Skip to content

Instantly share code, notes, and snippets.

@samgooi4189
Last active March 14, 2018 08:13
Show Gist options
  • Save samgooi4189/176ba649d8100adc6ca184e4ba252dbe to your computer and use it in GitHub Desktop.
Save samgooi4189/176ba649d8100adc6ca184e4ba252dbe to your computer and use it in GitHub Desktop.
Mocking Time.now in rspec
put in 'before' block inside rspec scenario:
@time_now = Time.parse("2018-03-08T00:00:00.000Z")
allow(Time).to receive(:now).and_return(@time_now)
You should see that the Time.now is being used in rspec scenario, but this won't be used in factory_bot.
You can selectively use it in certain test cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment