Created
September 12, 2018 08:26
-
-
Save krisleech/f05b57a9b241c9c1aa82469cdefd7b84 to your computer and use it in GitHub Desktop.
Inject mutable state (time)
This file contains 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 '#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