69e373dc1da96e4e18448fa103982865fc9277b5
test-doubles.md
... | ... | @@ -179,6 +179,12 @@ describe Converter do |
179 | 179 | end |
180 | 180 | ``` |
181 | 181 | |
182 | +`let` and `subject` provide for dynamically creating methods that return what's defined in the blocks. |
|
183 | +With `let`, the name of the method comes from the symbol you pass in. For `subject`, the method |
|
184 | +is called `subject`. They are both lazy. So if you never use `specific_converter` the block `{ FToCConverter.new }` will |
|
185 | +never run. Also, because they are lazy, you can reverse the order. Maybe people like to have the |
|
186 | +subject of the test at the top of the spec. I'll do that below. |
|
187 | + |
|
182 | 188 | Stubbing in MiniTest requires the the stubbed method actually exist in the instance being stubbed. Other |
183 | 189 | testing frameworks are more lenient in this respect, which can result in more concise tests -- but at |
184 | 190 | the expense of having test doubles that are _too_ fake and don't match up to your real collaborators. For |
... | ... | @@ -274,9 +280,9 @@ I've annotated this with the four phases. |
274 | 280 | |
275 | 281 | ```ruby |
276 | 282 | describe Converter, "delegation to logger" do |
283 | + subject { Converter.new(logger: logger) } # setup |
|
277 | 284 | let(:logger) { Minitest::Mock.new } # setup |
278 | 285 | let(:converter) { subject.converter } # setup |
279 | - subject { Converter.new(logger: logger) } # setup |
|
280 | 286 | |
281 | 287 | it "logs the value and the converted value" do |
282 | 288 | converter.stub :convert, 400 do |