aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/time_helpers.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-01-29 21:10:10 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-01-29 21:23:14 -0200
commit6dce4367c2bba894bb94e27cdfe4c56fdcc2c3df (patch)
tree3d1f4f664bcd78c9b09297a1e1b12bb6969a118c /activesupport/lib/active_support/testing/time_helpers.rb
parent049a10d4051a48136199fcdfd77bf35df9e9ad11 (diff)
downloadrails-6dce4367c2bba894bb94e27cdfe4c56fdcc2c3df.tar.gz
rails-6dce4367c2bba894bb94e27cdfe4c56fdcc2c3df.tar.bz2
rails-6dce4367c2bba894bb94e27cdfe4c56fdcc2c3df.zip
Use instance method instead of before hook
Diffstat (limited to 'activesupport/lib/active_support/testing/time_helpers.rb')
-rw-r--r--activesupport/lib/active_support/testing/time_helpers.rb17
1 files changed, 8 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb
index cd56ae1883..77b8ba261e 100644
--- a/activesupport/lib/active_support/testing/time_helpers.rb
+++ b/activesupport/lib/active_support/testing/time_helpers.rb
@@ -38,13 +38,8 @@ module ActiveSupport
# Containing helpers that helps you test passage of time.
module TimeHelpers
- def before_setup
- super
- @simple_stubs = SimpleStubs.new
- end
-
def after_teardown #:nodoc:
- @simple_stubs.unstub_all!
+ simple_stubs.unstub_all!
super
end
@@ -87,14 +82,18 @@ module ActiveSupport
# end
# Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
def travel_to(date_or_time, &block)
- @simple_stubs.stub_object(Time, :now, date_or_time.to_time)
- @simple_stubs.stub_object(Date, :today, date_or_time.to_date)
+ simple_stubs.stub_object(Time, :now, date_or_time.to_time)
+ simple_stubs.stub_object(Date, :today, date_or_time.to_date)
if block_given?
block.call
- @simple_stubs.unstub_all!
+ simple_stubs.unstub_all!
end
end
+
+ def simple_stubs
+ @simple_stubs ||= SimpleStubs.new
+ end
end
end
end