[rspec-users] Rspec book issue (mastermind example)

Chris Sund chris at silhouettesolutions.net
Mon Jul 6 13:51:33 EDT 2009


Hey Everyone,

Just a simple question. I have read and re-read the examples and I'm
not getting the proper output.  I'm on page 73/74 of the Rspec book
and it says I should have "4 steps passed". I think the problem is
within my /step_definition/mastermind.rb" file. It's definitely not
beyond me to make a mistake, but I have checked and double checked my
code and it all looks fine via the book examples. Here's the output
I'm getting...

______________________________________________________

cucumber features
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:7
    Given I am not yet playing                        # features/
step_definitions/mastermind.rb:3
    When I start a new game                           # features/
step_definitions/mastermind.rb:7
    Then the game should say "Welcome to Mastermind!" # features/
codebreaker_starts_game.feature:10
    And the game should say "Enter guess:"            # features/
codebreaker_starts_game.feature:11

1 scenario (1 undefined)
4 steps (2 undefined, 2 passed)
0m0.003s

You can implement step definitions for undefined steps with these
snippets:

Then /^the game should say "([^\"]*)"$/ do |arg1|
  pending
end

_______________________________________________

It seems it doesn't think my "Then" statement is defined, but it is.
My /step_definitions/mastermind.rb file looks like this...

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


When /^I start a new game$/ do
@messenger = StringIO.new
game = Mastermind::Game.new(@messenger)
game.start
end

Then /^the game should say "(.*)" $/ do |message|
@messenger.string.split("\n" ).should include(message)
end

__________________________________________

It's either a problem with the syntax in the "Then" statement, or my
"message" variable isn't getting defined right. Any help would be
appreciated, and I can provide my other files, but I'm a newbie and
I'm not sure what files would be worth looking at. Let me know and
I'll post them.

Thanks!

Chris


More information about the rspec-users mailing list