“rake” runs all my Cucumber tests fine but “cucumber” doesn't have the steps

时光总嘲笑我的痴心妄想 提交于 2019-12-18 07:33:43

问题


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 features 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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6264030/rake-runs-all-my-cucumber-tests-fine-but-cucumber-doesnt-have-the-steps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!