small medium large xlarge

Back to: All Forums  The RSpec Book
06 Mar 2014, 12:14
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 ||= end

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

When /^I start a new game$/ do game = game.start end

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

what can be?

17 Jul 2014, 13:35
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 ||=

When /^I start a new game$/ do
  game =

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

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)
  You must be logged in to comment