06 Mar 2014, 12:14
Generic-user-small

Bruno Amaral (1 post)

I’m with the following problem:

➜ codebreaker: cucumber features/codebreaker_starts_game.feature 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 # features/codebreaker_starts_game.feature:5 Given I am not yet playing # features/step_definitions/codebreaker_steps.rb:15 When I start a new game # features/step_definitions/codebreaker_steps.rb:18 Then I should see “Welcome to Codebreaker!” # features/step_definitions/codebreaker_steps.rb:23 undefined method messages' for #<RSpec::Matchers::BuiltIn::Output:0x0000000209cb60> (NoMethodError) ./features/step_definitions/codebreaker_steps.rb:24:in /^I should see “([^”]*)”$/’ features/codebreaker_starts_game.feature:8:in `Then I should see “Welcome to Codebreaker!”’ And I should see “Enter guess:” # features/step_definitions/codebreaker_steps.rb:23

Failing Scenarios: cucumber features/codebreaker_starts_game.feature:5 # Scenario: start game

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


The file (features/step_definitions/codebreaker_steps.rb) is like this: class Output def messages @messages ||= [] end

def puts(message) messages « message end end

def output @output ||= Output.new end

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

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

Then /^I should see “([^”]*)”$/ do |message| output.messages.should include(message) end


what can be?

17 Jul 2014, 13:35
Generic-user-small

Rollo Tom (2 posts)

The output method causes a name clash with RSpec’s built-in Output matcher. Just rename the output method:

def terminal_output
  @output ||= Output.new
end

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

Then /^I should see “([^”]*)”$/ do |message|
  terminal_output.messages.should include(message)
end

If you are using a recent RSpec you might want to write it as:

Then /^I should see “([^”]*)”$/ do |message|
  expect(terminal_output.messages).to include(message)
end
  You must be logged in to comment