我继承了一个 Rails (3) 应用程序,并试图掌握现有的 Cucumber 测试。我在应用程序的“功能”文件夹中有以下设置(我遗漏了任何不相关的文件,例如额外的功能和步骤)
/features
/people
new-person.feature
/step_definitions
people_steps.rb
web_steps.rb
/support
env.rb
paths.rb
selectors.rb
如果我运行“rake”,那么它会正确使用 step_definitions 中列出的步骤运行 features/people/new-person.feature 中的所有功能。
但是,我不想每次都运行 rake 因为它需要太长时间,我只想在 Cucumber 中运行一个特定的测试,例如
cucumber features/people/new-person.feature -l 8
当我这样做时,它运行该功能但尚未加载步骤。我得到这个:
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.
为什么 Cucumber 没有加载步骤?我猜我需要在某个地方要求这些步骤,但我不知道在哪里。
谢谢,马克斯
最佳答案
Max Williams 找到了他问题的答案:
编辑 - 在这里找到答案:https://rspec.lighthouseapp.com/projects/16211/tickets/401-envrb-not-loaded-when-running-individual-features-in-sub-directories
在 config/cucumber.yml 中有一行看起来像这样:std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
将其更改为std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip --require features/"
这就像添加 --require features/
到您的 cucumber 测试运行结束,并使其正确加载所有内容。
关于ruby-on-rails - "rake"可以正常运行我所有的 Cucumber 测试,但是 "cucumber"没有这些步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6264030/