ruby - Rspec cucumber : NoMethodError

标签 ruby rspec cucumber

我正在关注 'The Rspec Book'我无法理解为什么在运行 cucumber 时会出现以下错误。

Feature: code-breaker starts game

  As a code-breaker
  I want to start a game
  So that I can break the code

  Scenario: start game                          # /Users/PC/ruby/practice/rspec/codebreaker/features/codebreaker_starts_game.feature:7
    Given I am not yet playing                  # ruby/practice/rspec/codebreaker/features/step_definitions/codebreaker_steps.rb:17
    When I start a new game                     # ruby/practice/rspec/codebreaker/features/step_definitions/codebreaker_steps.rb:20
    Then I should see "Welcome to Codebreaker!" # ruby/practice/rspec/codebreaker/features/step_definitions/codebreaker_steps.rb:25
      undefined method `messages' for #<RSpec::Matchers::BuiltIn::Output:0x007fd6611fcb30> (NoMethodError)
      ./ruby/practice/rspec/codebreaker/features/step_definitions/codebreaker_steps.rb:26:in `/^I should see "(.*?)"$/'
      ./ruby/practice/rspec/codebreaker/features/codebreaker_starts_game.feature:10:in `Then I should see "Welcome to Codebreaker!"'
    And I should see "Enter guess:"             # ruby/practice/rspec/codebreaker/features/step_definitions/codebreaker_steps.rb:25

Failing Scenarios:
cucumber /Users/PC/ruby/practice/rspec/codebreaker/features/codebreaker_starts_game.feature:7 # Scenario: start game

1 scenario (1 failed)
4 steps (1 failed, 1 skipped, 2 passed)
0m0.050s

shell returned 1

步骤定义文件:

http://pastebin.com/BZZKL0wa

注意:我尝试打印 output.messages,它工作正常。

最佳答案

我相信您遇到了内置的 output 匹配器,它是 RSpec 的一部分(参见 https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/output-matcher )。您是否在尝试检查输出的同时尝试在步骤定义中打印 output.messages ?你应该得到同样的失败。

无论如何,如果您使用不同的方法名称,您应该没问题。

关于ruby - Rspec cucumber : NoMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28142579/

相关文章:

ruby - ruby on rails 中的 Facebook 重定向 url 打开 ssl 错误

ruby-on-rails - 如何在 Rails/Capybara/Cucumber 或 Rspec 中测试帖子

ruby - Cucumber - 如何从此 Gherkin 场景中删除数据重复?

ruby - Capybara - 查找位于表行中的禁用按钮

ruby - 在 Rails 中使用 autofocus 和 text_field 表单助手

mysql - Rails/mysql SUM 不同记录 - 优化

ruby-on-rails - 找不到指定的模块(MySQL)

ruby-on-rails - 有什么方法可以使用公共(public) URL 在 Rspec 中测试文件上传吗?

ruby-on-rails - 单元测试 : How to test if rails migrations being called?

ruby-on-rails - 如何使用 Tim Pope 的 cucumber.vim 插件?