Created
October 22, 2015 14:10
-
-
Save leoallen85/574c69cc61dd850476bd to your computer and use it in GitHub Desktop.
Dependency Injection in the method
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
describe JourneyLog do | |
subject(:journey_log) { described_class.new } | |
let(:journey_klass) { double(:journey_klass) } | |
let(:journey) { double(:journey) } | |
describe "Starting a journey" do | |
it "adds a journey to the log" do | |
allow(journey_klass).to receive(:new).with(:station).and_return(journey) | |
journey_log.start_journey(:station, journey_klass: journey_klass) | |
expect(journey_log.journeys).to include(journey) | |
end | |
end | |
end | |
class JourneyLog | |
attr_reader :journeys | |
def initialize | |
@journeys = [] | |
end | |
def start_journey(station, journey_klass: Journey) | |
journeys << journey_klass.new(station) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment