Last active
August 29, 2015 14:06
-
-
Save jcasimir/2d816e99c0a5932a6f63 to your computer and use it in GitHub Desktop.
Gets.chomp stubbing with Dependency Injection
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 InputFetcher | |
def fetch | |
gets.chomp | |
end | |
end | |
class Game | |
attr_reader :fetcher | |
def initialize(fetcher_type = InputFetcher) | |
@fetcher = fetcher_type.new | |
end | |
def play | |
unless fetcher.fetch == "quit" | |
puts "Still Going" | |
end | |
return "done" | |
end | |
end | |
class GameTest < Minitest::Test | |
class FakeFetcher | |
def fetch | |
"quit" | |
end | |
end | |
def test_it_exits | |
game = Game.new(FakeFetcher) | |
assert_equal "done", game.play | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment