Last active
October 22, 2015 14:11
-
-
Save leoallen85/771259e77e5853c994ac to your computer and use it in GitHub Desktop.
Dependency Injection in the constructor
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(journey_klass: journey_klass) } | |
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) | |
expect(journey_log.journeys).to include(journey) | |
end | |
end | |
end | |
class JourneyLog | |
attr_reader :journeys | |
def initialize(journey_klass: Journey) | |
@journeys = [] | |
@journey_klass = journey_klass | |
end | |
def start_journey(station) | |
journeys << journey_klass.new(station) | |
end | |
private | |
attr_reader :journey_klass | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment