Commit f340eb14 authored by Alishan Ladhani's avatar Alishan Ladhani

Update guideline for time-sensitive tests

Recommend using ActiveSupport::Testing::TimeHelpers
parent 8d7c7f17
...@@ -497,10 +497,9 @@ let_it_be(:project, refind: true) { create(:project) } ...@@ -497,10 +497,9 @@ let_it_be(:project, refind: true) { create(:project) }
### Time-sensitive tests ### Time-sensitive tests
[Timecop](https://github.com/travisjeffery/timecop) is available in our [`ActiveSupport::Testing::TimeHelpers`](https://api.rubyonrails.org/v6.0.3.1/classes/ActiveSupport/Testing/TimeHelpers.html)
Ruby-based tests for verifying things that are time-sensitive. Any test that can be used to verify things that are time-sensitive. Any test that exercises or verifies something time-sensitive
exercises or verifies something time-sensitive should make use of Timecop to should make use of these helpers to prevent transient test failures.
prevent transient test failures.
Example: Example:
...@@ -508,7 +507,7 @@ Example: ...@@ -508,7 +507,7 @@ Example:
it 'is overdue' do it 'is overdue' do
issue = build(:issue, due_date: Date.tomorrow) issue = build(:issue, due_date: Date.tomorrow)
Timecop.freeze(3.days.from_now) do travel_to(3.days.from_now) do
expect(issue).to be_overdue expect(issue).to be_overdue
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment