Skip to content

Instantly share code, notes, and snippets.

@leoallen85
Created October 22, 2015 14:10
Show Gist options
  • Save leoallen85/574c69cc61dd850476bd to your computer and use it in GitHub Desktop.
Save leoallen85/574c69cc61dd850476bd to your computer and use it in GitHub Desktop.
Dependency Injection in the method
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