Class: RuboCop::Cop::DevDoc::Test::AvoidGlibTravelFreeze
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::DevDoc::Test::AvoidGlibTravelFreeze
- Defined in:
- lib/rubocop/cop/dev_doc/test/avoid_glib_travel_freeze.rb
Overview
Flag glib_travel_freeze calls in test files — use glib_travel instead.
Rationale
glib_travel_freeze stops the clock completely, which is not representative
of real-world behavior: in production, time ticks as code executes.
We have had bugs that went undetected in tests because glib_travel_freeze
masked timing issues, only to surface in production.
glib_travel advances time normally inside the block — use it instead.
Reserve glib_travel_freeze only as a last resort when glib_travel
truly cannot work for a specific test, and document why.
Escape hatch
Disable per-line with a comment explaining why glib_travel doesn't work:
glib_travel_freeze(time) do # rubocop:disable DevDoc/Test/AvoidGlibTravelFreeze
# Reason: <explanation>
end
Constant Summary collapse
- MSG =
'Avoid `glib_travel_freeze` — use `glib_travel` instead. ' \ 'Frozen time masks timing bugs that surface in production. ' \ 'Use `# rubocop:disable DevDoc/Test/AvoidGlibTravelFreeze` ' \ 'with a comment explaining why `glib_travel` cannot work for this test.'
- RESTRICT_ON_SEND =
%i[glib_travel_freeze].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
46 47 48 |
# File 'lib/rubocop/cop/dev_doc/test/avoid_glib_travel_freeze.rb', line 46 def on_send(node) add_offense(node.loc.selector) end |