Fail specs that inherit a leaked Timecop clock - #5511
Open
philippthun wants to merge 1 commit into
Open
philippthun wants to merge 1 commit into
philippthun wants to merge 1 commit into
Conversation
philippthun
force-pushed
the
add-timecop-leak-guard
branch
from
October 5, 2026 19:19
39e1f92 to
b717ba3
Compare
A spec that freezes or travels time without returning it corrupts every following example that derives a value from Time.now, such as the decorator specs that set created_at to Time.now.utc - 1.second to assert an ordering. The leaked clock reverses that ordering, producing flaky failures far from the spec that actually leaked. The global after(:each) that returns time silently absorbs such a leak. Add a prepend_before that detects an already-active Timecop clock at example entry and fails immediately, naming the example that inherited the leak so the real culprit can be bisected out.
philippthun
force-pushed
the
add-timecop-leak-guard
branch
from
October 6, 2026 11:04
b717ba3 to
a491da6
Compare
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A spec that freezes or travels time without returning it corrupts every following example that derives a value from
Time.now, such as the decorator specs that setcreated_attoTime.now.utc - 1.secondto assert an ordering. The leaked clock reverses that ordering, producing flaky failures far from the spec that actually leaked.The global
after(:each)that returns time silently absorbs such a leak. Add aprepend_beforethat detects an already-active Timecop clock at example entry and fails immediately, naming the example that inherited the leak so the real culprit can be bisected out.This change was developed with AI assistance; all code was reviewed and tested by me.
I have reviewed the contributing guide
I have viewed, signed, and submitted the Contributor License Agreement
I have made this pull request to the
mainbranchI have run all the unit tests using
bundle exec rakeI have run CF Acceptance Tests