21ffeab04ee4d16786e5317fda04f5ddd2b9abcc
test-doubles.md
| ... | ... | @@ -262,20 +262,22 @@ the message `log` with the right values. At this point, we don't even have a log |
| 262 | 262 | know that it is going to expose a method `log` and expect that the method call will pass the |
| 263 | 263 | value and its conversion. |
| 264 | 264 | |
| 265 | -To make this happen, we want to create a `Mock`. |
|
| 265 | +To make this happen, we want to create a `Mock`. Notice that we are still using the stubbed converter. |
|
| 266 | +But now we write `logger.expect` to set up our expectations for what will happen on the collaborating |
|
| 267 | +object; and then we verify it afterward. I've annotated this with the four phases. |
|
| 266 | 268 | |
| 267 | 269 | ```ruby |
| 268 | 270 | describe Converter, "delegation to logger" do |
| 269 | - let(:logger) { Minitest::Mock.new } |
|
| 270 | - let(:converter) { subject.converter } |
|
| 271 | - subject { Converter.new(logger: logger) } |
|
| 271 | + let(:logger) { Minitest::Mock.new } # setup |
|
| 272 | + let(:converter) { subject.converter } # setup |
|
| 273 | + subject { Converter.new(logger: logger) } # setup |
|
| 272 | 274 | |
| 273 | 275 | it "logs the value and the converted value" do |
| 274 | 276 | converter.stub :convert, 400 do |
| 275 | - logger.expect(:log, nil, [32, 400]) |
|
| 276 | - subject.convert(32) |
|
| 277 | + logger.expect(:log, nil, [32, 400]) # verify |
|
| 278 | + subject.convert(32) # exercise |
|
| 277 | 279 | end |
| 278 | - logger.verify |
|
| 280 | + logger.verify # verify |
|
| 279 | 281 | end |
| 280 | 282 | end |
| 281 | 283 | ``` |