1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make sure the time method is unstubed

The minitest stubs were conflicting with the time travel stubs so the
travel_back method call in the teardown block was actually keeping the
time stubbed.
This commit is contained in:
Rafael Mendonça França 2016-07-12 02:54:57 -03:00
parent 6bdec0f4c2
commit bbbabc22c1
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948

View file

@ -3,18 +3,18 @@ require 'active_support/core_ext/date_time'
require 'active_support/core_ext/numeric/time'
class TimeTravelTest < ActiveSupport::TestCase
teardown do
travel_back
end
def test_time_helper_travel
Time.stub(:now, Time.now) do
begin
expected_time = Time.now + 1.day
travel 1.day
assert_equal expected_time.to_s(:db), Time.now.to_s(:db)
assert_equal expected_time.to_date, Date.today
assert_equal expected_time.to_datetime.to_s(:db), DateTime.now.to_s(:db)
ensure
travel_back
end
end
end
@ -36,12 +36,16 @@ class TimeTravelTest < ActiveSupport::TestCase
def test_time_helper_travel_to
Time.stub(:now, Time.now) do
begin
expected_time = Time.new(2004, 11, 24, 01, 04, 44)
travel_to expected_time
assert_equal expected_time, Time.now
assert_equal Date.new(2004, 11, 24), Date.today
assert_equal expected_time.to_datetime, DateTime.now
ensure
travel_back
end
end
end
@ -63,6 +67,7 @@ class TimeTravelTest < ActiveSupport::TestCase
def test_time_helper_travel_back
Time.stub(:now, Time.now) do
begin
expected_time = Time.new(2004, 11, 24, 01, 04, 44)
travel_to expected_time
@ -74,6 +79,9 @@ class TimeTravelTest < ActiveSupport::TestCase
assert_not_equal expected_time, Time.now
assert_not_equal Date.new(2004, 11, 24), Date.today
assert_not_equal expected_time.to_datetime, DateTime.now
ensure
travel_back
end
end
end
@ -107,6 +115,7 @@ class TimeTravelTest < ActiveSupport::TestCase
def test_time_helper_travel_to_with_subsequent_calls
Time.stub(:now, Time.now) do
begin
initial_expected_time = Time.new(2004, 11, 24, 01, 04, 44)
subsequent_expected_time = Time.new(2004, 10, 24, 01, 04, 44)
assert_nothing_raised do
@ -115,6 +124,9 @@ class TimeTravelTest < ActiveSupport::TestCase
assert_equal subsequent_expected_time, Time.now
travel_back
end
ensure
travel_back
end
end