我正在关注 '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
步骤定义文件:
注意:我尝试打印 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/