Last active
March 14, 2018 08:13
-
-
Save samgooi4189/176ba649d8100adc6ca184e4ba252dbe to your computer and use it in GitHub Desktop.
Mocking Time.now in rspec
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
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