instance method travel_back

Ruby on Rails 8.1.2

Since v4.1.16

Available in: v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

travel_back()

Returns the current time back to its original state, by removing the stubs added by travel, travel_to, and freeze_time.

Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00

travel_to Time.zone.local(2004, 11, 24, 1, 4, 44)
Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00

travel_back
Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00

This method also accepts a block, which brings the stubs back at the end of the block:

Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00

travel_to Time.zone.local(2004, 11, 24, 1, 4, 44)
Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00

travel_back do
  Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
end

Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00
Source
# File activesupport/lib/active_support/testing/time_helpers.rb, line 231
      def travel_back
        stubbed_time = Time.current if block_given? && simple_stubs.stubbed?

        simple_stubs.unstub_all!
        yield if block_given?
      ensure
        travel_to stubbed_time if stubbed_time
      end

Defined in activesupport/lib/active_support/testing/time_helpers.rb line 231 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::Testing::TimeHelpers

Type at least 2 characters to search.

↑↓ navigate · open · esc close