summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2009-05-27 09:20:51 -0600
committermo khan <mo@mokhan.ca>2009-05-27 09:20:51 -0600
commit6af7a76a35f0507bf7138d4510c7210a9192fb6c (patch)
treea8dd02b2ff8d9490bb8da0d27dc7a9127a579fe8
parent0e61384f75e0aedfed0642ffbc7229d970707dc7 (diff)
refactored the step definitions
-rw-r--r--features/step_definitions/mastermind.rb35
1 files changed, 23 insertions, 12 deletions
diff --git a/features/step_definitions/mastermind.rb b/features/step_definitions/mastermind.rb
index f07c541..680a2b6 100644
--- a/features/step_definitions/mastermind.rb
+++ b/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