Step reported as Cucumber::Undefined but can be jumped to
jondkinney opened this issue · comments
I'm seeing vim report Cucumber::Undefined
for steps that work fine with cucumber, and that cucumber-vim will let me jump to with ctrl-w d
. So it seems like cucumber-vim knows how to find the steps.
Is it a directory structure thing? This project uses steps
instead of step_definitions
, though I tried switching the name of the directory and it didn't matter. I also tried un-nesting the .feature file I'm working on and putting it at the top level features directory like (features/my_file.feature) to see if it could find the step defs that way but that didn't matter either.
I'm stumped. Any ideas? Thanks much!
Perhaps this is a syntastic thing and not a vim-cucumber thing? Does vim-cucumber plug into syntastic at all?
I see this item out on the syntastic issue tracker vim-syntastic/syntastic#415
Sorry if this isn't even something in vim-cucumber at all, I'm just trying to figure out how to fix it. It was working wonderfully a few months back and was handy to let me know which steps I needed to go implement yet! I'm not certain what broke it.
Yeah sounds like syntastic.
Well, for posterity, I actually did figure it out. I think it's because of either the page objects we're using through site prism or the directory structure (or both), but a few weeks ago another team member that re-organized that code mentioned that we now needed to use -r features
when running cucumber. Looking up -r
for cucumber with cucumber --help
it specified that the -r
flag required a specific folder, in our case, features.
Some additional googling lead me to this: http://old.thoughtsincomputation.com/posts/cucumber-step-definitions-and-autorequire-hell
Which pointed out that you can add -r features
to your config/cucumber.yml
profile. Doing this fixed the issue with syntastic. Presumably because syntastic can now find the step defs thanks to -r
.
In case that blog post goes away, here's the config/cucumber.yml
file as specified in the post. I didn't use this exact cucumber.yml
, but prepending -r features
to my existing one for each different profile: default, wip, rerun, etc. did work.
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format progress features" :
"--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "#{rerun_opts} --format rerun --out rerun.txt --strict --tags ~@wip"
%>
default: -r features <%= std_opts %>
wip: -r features --tags @wip:3 --wip features
One final update to this issue... just using -r features isn't enough, you need to add a new profile for syntastic to specifically require the folder that contains the step definitions.
Here is my working cucumber.yml
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --tags ~@wip --snippet-type percent"
%>
syntastic: -r features/steps <%= std_opts %>
default: -r features <%= std_opts %>
wip: -r features --tags @wip:3 --wip
rerun: -r features <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip --snippet-type percent
Then in your ~/.vimrc
you need to add this syntastic configuration flag:
let g:syntastic_cucumber_cucumber_args="--profile syntastic"
Sorry for all the posts on what ended up not being a vim-cucumber issue, but I wanted to at least solve the problem fully in one place. BTW, this assumes your step definitions are in a folder called steps
. If they're in the standard step_definitions
folder then update the above cucumber.yml file appropriately to reference syntastic: -r features/step_definitions <%= std_opts %>