-
Notifications
You must be signed in to change notification settings - Fork 21.8k
Add travel_back
to remove stubs from travel
and travel_to
and remove auto-rollback after each test case
#13884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -68,8 +62,7 @@ def travel(duration, &block) | |||
end | |||
|
|||
# Change current time to the given time by stubbing +Time.now+ and +Date.today+ to return the | |||
# time or date passed into this method. Note that the stubs are automatically removed | |||
# at the end of each test. | |||
# time or date passed into this method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll want to keep the doc on this method intact, as we really travelling back on the block form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is documented below:
# This method also accepts a block, which will return the current time back to its original
# state at the end of the block:
What I removed is the automatically removal of the stubs in the non-block version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, ha. I read it wrong. This is good to go 👍
@@ -607,6 +607,9 @@ for detailed changes. | |||
`Time.now` and | |||
`Date.today`. ([Pull Request](https://github.com/rails/rails/pull/12824)) | |||
|
|||
* Added `ActiveSupport::Testing::TimeHelpers#travel_back`. This method return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"returns" here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@rafaelfranca looking good 👍 |
This behavior is only work out-of-box with minitest and also add a downside to run after each test case, even if we don't used the travel or travel_to methods
Add `travel_back` to remove stubs from `travel` and `travel_to` and remove auto-rollback after each test case
This is a alternative implementation of #12966.
The reason is the same plus, I'm removing the auto-rollback after each test case. The reason is this auto-rollback will only work with minitest out of the box and it may confuse the users.
Closes #12966