summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2009-05-27 09:25:00 -0600
committermo khan <mo@mokhan.ca>2009-05-27 09:25:00 -0600
commit1b3e97664a6fe0af00cb0aef406ebba8de69f7c9 (patch)
tree3cecdbe3732b8346a9d8ffe51cf028347968b128
parent6af7a76a35f0507bf7138d4510c7210a9192fb6c (diff)
refactored the game_spec to remove duplication
-rw-r--r--spec/mastermind/game_spec.rb36
1 files changed, 15 insertions, 21 deletions
diff --git a/spec/mastermind/game_spec.rb b/spec/mastermind/game_spec.rb
index 34e232c..4788aa9 100644
--- a/spec/mastermind/game_spec.rb
+++ b/spec/mastermind/game_spec.rb
@@ -3,46 +3,40 @@ require File.join(File.dirname(__FILE__), "/../spec_helper")
module Mastermind
describe Game do
+ before(:each) do
+ @messenger = mock("messenger").as_null_object
+ @game = Game.new(@messenger)
+ end
context "starting up" do
- before(:each) do
- @messenger = mock("messenger").as_null_object
- @game = Game.new(@messenger)
- end
it "should send a welcome message" do
@messenger.should_receive(:puts).with("Welcome to Mastermind!")
- @game.start(%w[r c g y])
+ @game.start(%w[r g y c])
end
it "should prompt for the first guess" do
@messenger.should_receive(:puts).with("Enter guess:")
- @game.start(%w[r c g y])
+ @game.start(%w[r g y c])
end
end
context "marking a guess" do
context "with all 4 colors correct in the correct places" do
it "should mark the guess with bbbb" do
- messenger = mock("messenger").as_null_object
- game = Game.new(messenger)
- game.start(%w[r g y c])
- messenger.should_receive(:puts).with("bbbb")
- game.guess(%w[r g y c])
+ @game.start(%w[r g y c])
+ @messenger.should_receive(:puts).with("bbbb")
+ @game.guess(%w[r g y c])
end
end
context "with all 4 colors correct and 2 in the correct places" do
it "should mark the guess with bbww" do
- messenger = mock("messenger").as_null_object
- game = Game.new(messenger)
- game.start(%w[r g y c])
- messenger.should_receive(:puts).with("bbww")
- game.guess(%w[r g c y])
+ @game.start(%w[r g y c])
+ @messenger.should_receive(:puts).with("bbww")
+ @game.guess(%w[r g c y])
end
end
context "with all 4 colors correct and 1 in the correct place" do
it "should mark the guess with bwww" do
- messenger = mock("messenger").as_null_object
- game = Game.new(messenger)
- game.start(%w[r g y c])
- messenger.should_receive(:puts).with("bwww")
- game.guess(%w[y r g c])
+ @game.start(%w[r g y c])
+ @messenger.should_receive(:puts).with("bwww")
+ @game.guess(%w[y r g c])
end
end
end