Last active
August 29, 2015 13:57
-
-
Save jgn/9380500 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 Logger | |
attr_reader :log_output | |
def info(s) | |
@log_output ||= "" | |
@log_output << s << "\n" | |
end | |
end | |
examples.each do |example| | |
a, b, c, s = example | |
# Getting a fresh Logger because it has state now | |
logger = Logger.new # setup | |
half_adder = HalfAdder.new(a, b, logger) # setup | |
half_adder.compute # exercise | |
assert_equality(example, half_adder.carry, c) # verify | |
assert_equality(example, half_adder.sum, s) # verify | |
adder = nil # teardown | |
end | |
# And now I'm going to verify the DOC with the spy | |
a, b, c, s = examples[0] | |
expected_logging = <<LOG | |
augend: 0 | |
addend: 0 | |
carry: 0 | |
sum: 0 | |
LOG | |
logger = Logger.new # setup | |
half_adder = HalfAdder.new(a, b, logger) # setup | |
half_adder.compute # exercise | |
assert_equality("verifying logging", | |
logger.log_output, | |
expected_logging) # verify | |
adder = nil # teardown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment