7ab96be682a36dc2f9ef1a7db5ed1620c5a67eba
test-doubles.md
| ... | ... | @@ -13,6 +13,26 @@ When we receive a message from another object, we want to verify a state change |
| 13 | 13 | Example: Suppose we have an object that converts fahrenheit to celsius. When we pass in a measurement |
| 14 | 14 | in fahrenheit, we want to verify that the computation of the celsius value is correct. |
| 15 | 15 | |
| 16 | +```ruby |
|
| 17 | +require 'minitest/autorun' |
|
| 18 | + |
|
| 19 | +class TemperatureConverter |
|
| 20 | + def f_to_c(f) |
|
| 21 | + (f - 32.0) * 5.0 / 9.0 |
|
| 22 | + end |
|
| 23 | +end |
|
| 24 | + |
|
| 25 | +class TemperatureConverterTest < MiniTest::Test |
|
| 26 | + def setup |
|
| 27 | + @tc = TemperatureConverter.new |
|
| 28 | + end |
|
| 29 | + |
|
| 30 | + def test_f_to_c |
|
| 31 | + assert_in_delta 0.0, @tc.f_to_c(32), 0.01 |
|
| 32 | + end |
|
| 33 | +end |
|
| 34 | +``` |
|
| 35 | + |
|
| 16 | 36 | ### Testing messages sent to others |
| 17 | 37 | |
| 18 | 38 | When we send a message to another object that results in a side effect, we want to verify the side effect. |