【问题标题】:"rake" runs all my Cucumber tests fine but "cucumber" doesn't have the steps“rake”可以很好地运行我所有的 Cucumber 测试,但“cucumber”没有这些步骤
【发布时间】: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


【解决方案1】:

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/ 并使其正确加载所有内容。

【讨论】:

  • @Max,你应该接受这个答案。
  • 另外,如果你不想添加默认选项,你可以在运行黄瓜时添加-r features/
【解决方案2】:

无论出于何种原因,我都没有要更改的 cucumber.yml 文件。因此,只需创建一个空白的 /config/cucumber.yml 文件并将该行放入其中:

std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip --require features/"

没用。 (这并不奇怪,我认为它应该不仅仅是那一行。)

我在这里找到了一个完整的工作 cucumber.yml 示例文件的好例子:http://jdfrens.blogspot.com/2010/03/uh-yes-i-did-define-that-cucumber-step.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多