我继承了一个Rails(3)应用程序,正在努力掌握现有的Cucumber测试。我在应用程序的"功能"文件夹中有以下设置(我错过了任何不相关的文件,例如额外的功能和步骤)
/features
/people
new-person.feature
/step_definitions
people_steps.rb
web_steps.rb
/support
env.rb
paths.rb
selectors.rb
如果我运行"rake",那么它会运行features/people/new-person.feature中的所有功能,正确地使用step_definitions中列出的步骤。
然而,我不想每次都运行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
Max Williams找到了问题的答案:
编辑-找到答案,在这里:https://rspec.lighthouseapp.com/projects/16211/tickets/401-envrb-not-loaded-when-running-individual-features-in-sub-directories
在config/ccumber.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.yml文件要更改。因此,只需创建一个空白的/config/ccunumber.yml文件并在其中放入行:
std_opts="--format#{ENV['CUCUMBER_format']||'pretty'}--strict--tags~@wip--required features/"
不起作用。(这并不奇怪,我认为它应该不仅仅是一行。)
我在这里找到了一个完整的、可工作的、cucumber.yml示例文件的好例子:http://jdfrens.blogspot.com/2010/03/uh-yes-i-did-define-that-cucumber-step.html