"rake" runs all my Cucumber tests fine but "cucumber" doesn't have the steps
I've inherited a Rails (3) app and am trying to get to grips with the existing Cucumber tests. I've got the following setup in the app's 'features' folder (I've missed out any files which aren't relevant, eg extra feature开发者_如何学JAVAs and steps)
/features
/people
new-person.feature
/step_definitions
people_steps.rb
web_steps.rb
/support
env.rb
paths.rb
selectors.rb
If I run 'rake' then it runs all the features in features/people/new-person.feature, correctly using the steps listed in step_definitions.
However, I don't want to run rake every time as it takes too long, I just want to run a specific test in Cucumber, e.g. cucumber features/people/new-person.feature -l 8
When I do this, it runs the feature but hasn't loaded the steps. I get this back:
Using the default profile...
Feature: Add a new person
In order to allocate tasks to people
As a community manager
I want to add a new person
Scenario: Secondary navigation should contain "Add new person" # features/people/new-person.feature:8
Given I am on the new person page # features/people/new-person.feature:9
Undefined step: "I am on the new person page" (Cucumber::Undefined)
features/people/new-person.feature:9:in `Given I am on the new person page'
Then I should not see "Add new person" # features/people/new-person.feature:10
Undefined step: "I should not see "Add new person"" (Cucumber::Undefined)
features/people/new-person.feature:10:in `Then I should not see "Add new person"'
1 scenario (1 undefined)
2 steps (2 undefined)
0m0.005s
You can implement step definitions for undefined steps with these snippets:
Given /^I am on the new person page$/ do
pending # express the regexp above with the code you wish you had
end
Then /^I should not see "([^"]*)"$/ do |arg1|
pending # express the regexp above with the code you wish you had
end
If you want snippets in a different programming language, just make sure a file
with the appropriate file extension exists where cucumber looks for step definitions.
Why isn't Cucumber loading the steps in? I'm guessing that I need to require the steps somewhere but I can't work out where.
Thanks, Max
Max Williams found the answer to his question:
EDIT - found the answer, here: https://rspec.lighthouseapp.com/projects/16211/tickets/401-envrb-not-loaded-when-running-individual-features-in-sub-directories
In config/cucumber.yml there's a line that looks like this:
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
change it to
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip --require features/"
This is like adding --require features/
to the end of your cucumber test run and makes it load everything up properly.
I did not already have a cucumber.yml file to change, for whatever reason. So, simply creating a blank /config/cucumber.yml file and putting the line in it:
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip --require features/"
did not work. (That is not surprising, I figured there was supposed to be more to it than just that one line.)
I found a good example of a FULL, working, cucumber.yml example file here: http://jdfrens.blogspot.com/2010/03/uh-yes-i-did-define-that-cucumber-step.html
精彩评论