【问题标题】:Cucumber not finding step definitions黄瓜找不到步骤定义
【发布时间】:2013-09-12 19:37:20
【问题描述】:

我的 Cucumber 只是找不到步骤定义。文件结构(仅 Rails 根目录中的 specs 文件夹)如下所示:

-> specs
   -> features
      -> main_structure.feature
      -> step_definitions
         -> main_structure_steps.rb

这是 main_structure.feature:

Feature: Main structure
  Scenario: Viewing the Structure page
    When I am on the structure page

这是 main_structure_steps.rb:

When(/^I am on the structure page$/) do
  visit '/'
end

现在我像这样运行黄瓜命令:

→ cucumber spec/features -r features 

我得到这个输出:

Using the default profile...
Feature: Main structure

  Scenario: Viewing the Structure page # spec/features/main_structure.feature:2
    When I am on the structure page    # spec/features/main_structure.feature:3
      Undefined step: "I am on the structure page" (Cucumber::Undefined)
      spec/features/main_structure.feature:3:in `When I am on the structure page'

1 scenario (1 undefined)
1 step (1 undefined)
0m0.229s

You can implement step definitions for undefined steps with these snippets:

When(/^I am on the structure page$/) do
  pending # express the regexp above with the code you wish you had
end

/Users/rudolf/.rvm/gems/ruby-2.0.0-p247@global/gems/minitest-4.7.5/lib/minitest/unit.rb:1037:in `block in process_args': invalid option: -r (OptionParser::InvalidOption)
    from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247@global/gems/minitest-4.7.5/lib/minitest/unit.rb:1016:in `new'
    from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247@global/gems/minitest-4.7.5/lib/minitest/unit.rb:1016:in `process_args'
    from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247@global/gems/minitest-4.7.5/lib/minitest/unit.rb:1066:in `_run'
    from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247@global/gems/minitest-4.7.5/lib/minitest/unit.rb:1059:in `run'
    from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247@global/gems/minitest-4.7.5/lib/minitest/unit.rb:795:in `block in autorun'

底部还有一条错误消息,当我在 RubyMine 中运行测试时没有出现。但在这两种情况下,都找不到步骤定义。这是 Rubymine 的输出:

Testing started at 21:29 ...


You can implement step definitions for undefined steps with these snippets:

When(/^I am on the structure page$/) do
  pending # express the regexp above with the code you wish you had
end
1 scenario (1 undefined)
1 step (1 undefined)
0m0.001s

Process finished with exit code 0

如果您需要任何其他信息,请告诉我。

【问题讨论】:

  • 当您明确运行该单一功能时,它是否找到步骤定义?例如cucumber spec/features/main_structure.feature
  • 刚刚运行cucumber spec/features/main_structure.feature -r features,结果相同。
  • 我相信 spec 文件夹是您运行黄瓜的子文件夹?
  • 就是这样。将其发布为答案,您将得到我的确认和支持;)cucumber spec/features/main_structure.feature -r spec/features 完成了这项工作(请参阅最后的-r spec/features)。

标签: ruby-on-rails ruby rspec cucumber


【解决方案1】:

试试

cucumber spec/features/main_structure.feature -r spec/features

【讨论】:

  • 截至 2016 年,Cucumber 开发人员删除了 -r 命令。你知道如何在 Cucumber 1.2.4 中做同样的事情吗? --help 不显示等效于 -r。
【解决方案2】:

与我的问题类似:Cucumber Test acting in a strange way

您可以使用这些 sn-ps 为未定义的步骤实现步骤定义:

When(/^I am on the structure page$/) do
  pending # express the regexp above with the code you wish you had
end

正如错误所说。把上面的代码放到web_steps.rb中,然后把pending # express the regexp above with the code you wish you had换成你想要的代码

【讨论】:

  • 对不起,我忘了提。这已包含在 main_structure_steps.rb 中。
  • 我的 cucumber-rails 版本是 1.0.6,也许这可能是个问题,因为正如我所关注的书所说,黄瓜在较新版本中删除了 web 步骤,所以我被允许使用的版本使用具有 web_steps.rb 的 1.0.6
【解决方案3】:

我在使用 Java 时也遇到了类似的问题,对我来说,原因是我在 NetBeans IDE 中安装了 2 个 Cucumber 插件。我离开 Cetriolo 并删除了 Cucumber 功能和测试开始工作

【讨论】:

    【解决方案4】:

    确保胶合语法如下:

    glue={"packageName"}

    这里的packageName是你步骤定义java文件所在的包

    【讨论】:

    • 我认为你的答案与java版本的黄瓜有关,但你可以从帖子下面的标签中看到问题是关于红宝石的黄瓜。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-10
    • 1970-01-01
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    相关资源
    最近更新 更多