Created
October 11, 2013 19:46
-
-
Save dadarek/6940891 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Game | |
def initialize( printer, logicMachine ) | |
end | |
def go | |
while logicMachine.continue? | |
printer.puts( "We are still playing the game." ) | |
end | |
end | |
end | |
# -- THIS IS THE TEST | |
class RealPrinter | |
def puts( message ) | |
puts message | |
end | |
end | |
class MockPrinter | |
attr_reader :timesMessageWasPrinted, :message | |
def initialize | |
@timesMessageWasPrinted = 0 | |
end | |
def puts(message) | |
@timesMessageWasPrinted += 1 | |
@message = message | |
end | |
end | |
fakePrinter = MockPrinter.new | |
game = Game.new( fakePrinter, fakeLogicMachine ) | |
game.go | |
fakePrinter.message.should == 'We are still playing the game.' | |
fakePrinter.timesMessageWasPrinted.should == 2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment