Commit 6af7a76
Changed files (1)
features
step_definitions
features/step_definitions/mastermind.rb
@@ -1,24 +1,35 @@
# mastermind.rb
+def messenger
+ @messenger ||= StringIO.new
+end
-Given /^I am not yet playing$/ do
+def game
+ @game = ||= Mastermind::Game.new(messenger)
end
-When /^I start a new game$/ do
- @messenger = StringIO.new
- game =Mastermind::Game.new(@messenger)
- game.start
+
+def messages_should_include(message)
+ messenger.string.split("\n").should include(message)
end
-Then /^the game should say "(.$)"$/ do |message|
- @messenger.string.split("\n").should include(message)
+
+Given /^I am not yet playing$/ do
end
Given /^the secret code is (. . . .)$/ do |code|
- @messenger = StringIO.new
- @game = Mastermind::Game.new(@messenger)
- @game.start(code.split)
+ game.start(code.split)
end
+
When /^I guess (. . . .)$/ do |code|
- @game.guess(code.split)
+ game.guess(code.split)
end
+
+When /^I start a new game$/ do
+ game.start
+end
+
+Then /^the game should say "(.$)"$/ do |message|
+ messages_should_include(message)
+end
+
Then /^the mark should be (.*)$/ do |mark|
- @messenger.string.split("\n").should include(mark)
+ messages_should_include(mark)
end