黄瓜没有找到步骤定义

时间:2013-09-12 19:37:20

标签: ruby-on-rails ruby rspec 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

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

4 个答案:

答案 0 :(得分:11)

尝试

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

答案 1 :(得分:1)

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

您可以使用以下代码段实现未定义步骤的步骤定义:

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替换为您想要的代码

答案 2 :(得分:0)

我也遇到过与Java类似的问题,对我而言,原因是我在NetBeans IDE中安装了2个Cucumber插件。我离开了Cetriolo并删除了Cucumber Features并且测试开始工作

答案 3 :(得分:0)

确保胶水语法如下所示:

胶= {"的packageName"}

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