Last active
June 14, 2020 06:48
-
-
Save usutani/72db9dcf90d496e6c4f57a46f5bc2fad to your computer and use it in GitHub Desktop.
オブジェクト指向設計実践ガイド 9章 ダックタイプをテストする
This file contains hidden or 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
| # frozen_string_literal: true | |
| class Trip | |
| def prepare(preparers) | |
| # ... | |
| preparers.each do |preparer| | |
| preparer.prepare_trip(foo: self) | |
| end | |
| # ... | |
| end | |
| end | |
| # Chapter 9: Designing Cost-Effective Tests | |
| # Testing Duck Type | |
| require 'minitest/autorun' | |
| class TripTest < Minitest::Test | |
| def test_requests_trip_preparation | |
| @preparer = Minitest::Mock.new | |
| @trip = Trip.new | |
| @preparer.expect(:prepare_trip, nil, [foo: @trip]) | |
| @trip.prepare([@preparer]) | |
| @preparer.verify | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment