【发布时间】:2011-06-07 10:40:39
【问题描述】:
我继承了 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 不加载步骤?我猜我需要在某处要求这些步骤,但我不知道在哪里。
谢谢,马克斯
【问题讨论】:
-
为了论证,将特征文件上移一个目录。我的各种 .feature 文件中的任何地方都没有要求,而且我在 features/support/ 文件中没有看到任何似乎指向这一点的配置 goop。你确定你的 people_steps.rb 代码是有效的吗?你牺牲了一只鸡吗?
-
@jaydel - 当我使用
rake运行它时,一切正常,即所有步骤都加载正常。我想继续细分我的功能,只是为了将它们组织成合理的组。 -
@jaydel - 但是,将功能文件移动到主要功能文件夹确实解决了问题......我认为我需要在某个地方添加额外的“../”。
-
啊,完美。好东西。谢谢你把它还给我们:)
-
请将您的解决方案作为答案发布并在两天内接受。这样,它就会在问题列表和搜索结果中正确显示。
标签: ruby-on-rails ruby-on-rails-3 cucumber