aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/test_test.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2013-11-20 01:21:43 -0800
committerXavier Noria <fxn@hashref.com>2013-11-20 01:21:43 -0800
commitb43b6d5c82f1086715278e75f6659b9a1db0c758 (patch)
tree4249462334353ee711378c335f95df3655d82f42 /activesupport/test/test_test.rb
parent1ffa4abcd595b98ad83bc6b80cdf3b5a30fa25c9 (diff)
parent225cd915cf5ab3b6662d3eecf3fe0715bf73e4de (diff)
downloadrails-b43b6d5c82f1086715278e75f6659b9a1db0c758.tar.gz
rails-b43b6d5c82f1086715278e75f6659b9a1db0c758.tar.bz2
rails-b43b6d5c82f1086715278e75f6659b9a1db0c758.zip
Merge pull request #12824 from sikachu/ps-testing-time-helper
Add `#travel` and `#travel_to` to `ActiveSupport::TestCase`
Diffstat (limited to 'activesupport/test/test_test.rb')
-rw-r--r--activesupport/test/test_test.rb50
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