Commit 0e61384

mo khan <mo@mokhan.ca>
2009-05-27 15:09:18
got some more specs running. pg. 71
1 parent 4b8f713
Changed files (2)
lib
mastermind
spec
mastermind
lib/mastermind/game.rb
@@ -10,7 +10,7 @@ module Mastermind
 			@messenger.puts "Enter guess:"
 		end
 		def guess(guess)
-			result = ""
+			result = []
 			guess.each_with_index do |peg, index|
 				if @code[index] == peg
 					result << "b"
@@ -18,7 +18,7 @@ module Mastermind
 					result << "w"
 				end
 			end
-			@messenger.puts result
+			@messenger.puts result.sort.join
 		end
 	end
 end
spec/mastermind/game_spec.rb
@@ -36,6 +36,15 @@ module Mastermind
 					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])
+				end
+			end
 		end
 	end
 end