diff options
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/test_test.rb | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index 0c8cc1f883..5ed2da7e8b 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -1,4 +1,6 @@ require 'abstract_unit' +require 'active_support/core_ext/date' +require 'active_support/core_ext/numeric/time' class AssertDifferenceTest < ActiveSupport::TestCase def setup @@ -122,7 +124,6 @@ class SetupAndTeardownTest < ActiveSupport::TestCase end end - class SubclassSetupAndTeardownTest < SetupAndTeardownTest setup :bar teardown :bar @@ -143,7 +144,6 @@ class SubclassSetupAndTeardownTest < SetupAndTeardownTest end end - class TestCaseTaggedLoggingTest < ActiveSupport::TestCase def before_setup require 'stringio' @@ -156,3 +156,49 @@ class TestCaseTaggedLoggingTest < ActiveSupport::TestCase assert_match "#{self.class}: #{name}\n", @out.string end end + +class TimeHelperTest < ActiveSupport::TestCase + setup do + Time.stubs now: Time.now + end + + def test_time_helper_travel + expected_time = Time.now + 1.day + travel 1.day + + assert_equal expected_time, Time.now + assert_equal expected_time.to_date, Date.today + end + + def test_time_helper_travel_with_block + expected_time = Time.now + 1.day + + travel 1.day do + assert_equal expected_time, Time.now + assert_equal expected_time.to_date, Date.today + end + + assert_not_equal expected_time, Time.now + assert_not_equal expected_time.to_date, Date.today + end + + def test_time_helper_travel_to + 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 + end + + def test_time_helper_travel_to_with_block + expected_time = Time.new(2004, 11, 24, 01, 04, 44) + + travel_to expected_time do + assert_equal expected_time, Time.now + assert_equal Date.new(2004, 11, 24), Date.today + end + + assert_not_equal expected_time, Time.now + assert_not_equal Date.new(2004, 11, 24), Date.today + end +end |