I've just installed cucumber into a new rails project (first time setting it up from scratch) and it works wonderfully when running all tests (bundle exec cucumber
) but can't find any of my steps when I run a single feature file. How might I start to debug this?
rails (3.2.13)
cucumber-rails (1.3.1)
cucumber (>= 1.2.0)
# file listing
features/
├── campaigns
│ ├── donating_campaigns.feature
│ └── viewing_campaigns.feature
├── step_definitions
│ └── campaign_steps.rb
└── support
└── env.rb
I think you may be misunderstanding what step definitions are. In
features/step_definitions
is where you define your steps. So it looks like you have two features that contain scenarios you will or have written. Run the scenarios and you will see the step definitions you need to define. one for each line of your scenario. Now you need to define the steps in yourcampaign_steps.rb
file using Capybara. For a fictitious example,Cucumber used to come with
web_steps.rb
that defined many steps for you. However, that was changed and left out in recent versions. Hope this gets you started in the right direction. Stick with itI had this problem in one of my projects. When I compared the cucumber.yml file of a functional project with the problematic one, I found that the functional file set
-r features
on thestd_opts
andrerun
assignments. When I added that to the broken project, Cucumber could find my step definitions.Here's my successful cucumber.yml file:
Kudos to this coder for pointing me in the right direction: http://web.archive.org/web/20121026012412/http://old.thoughtsincomputation.com/posts/cucumber-step-definitions-and-autorequire-hell
It will only find files at the same level or lower in the features directory tree. So if you try to run just the scenarios in features/campaigns/donating_campaigns.feature it cannot find the step_definitions directory.
You can use the --require flag to explicitly tell cucumber what to include before it runs your feature. For example: