2015-01-25 4 views
1

나는 'The Rspec Book'을 팔로우하고 있는데 오이를 실행할 때 왜 다음 오류가 발생하는지 이해할 수 없습니다.Rspec 오이 : NoMethodError

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을 시도하고 괜찮 았는데.

+0

이것은 http://stackoverflow.com/questions/26850871/newbie-cant-define-a-method-in-ruby-for-cucumber-test-pass의 속일 수 있습니다. – orde

답변

2

Peter Alfvin이 맞습니다. 출력 방법의 이름을 변경하십시오. 다음은 저에게 효과적이었습니다.

class OutputDouble 
    def messages 
    @messages ||= [] 
    end 
    def puts(message) 
    messages << message 
    end 
end 

def output_double 
    @output ||= OutputDouble.new 
end 

Given /^I am not yet playing$/ do 
end 

When /^I start a new game$/ do 
    game = Codebreaker::Game.new(output_double) 
    game.start 
end 

Then /^I should see "([^"]*)"$/ do |message| 
    output_double.messages.should include(message) 
end 

생성 방법 (출력)의 이름이 output_double로 변경되었습니다.

관련 문제