Skip to content

Instantly share code, notes, and snippets.

@krisleech
Created September 12, 2018 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisleech/f05b57a9b241c9c1aa82469cdefd7b84 to your computer and use it in GitHub Desktop.
Save krisleech/f05b57a9b241c9c1aa82469cdefd7b84 to your computer and use it in GitHub Desktop.
Inject mutable state (time)
describe '#call' do
let(:today) { Date.parse('20/08/2018') }
let(:clock) { double('Clock', today: today) }
it 'generates report up to last month' do
subject = described_class.new(clock: clock)
# ...
end
end
class SendReport
def initialize(dependencies = {})
@clock = dependencies.fetch(:clock) { Date }
end
def call
# ...
end
private
def today
@clock.today
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment