Skip to content
Browse files

Use instance method instead of before hook

  • Loading branch information...
1 parent 049a10d commit 6dce4367c2bba894bb94e27cdfe4c56fdcc2c3df @rafaelfranca rafaelfranca committed Jan 29, 2014
Showing with 8 additions and 9 deletions.
  1. +8 −9 activesupport/lib/active_support/testing/time_helpers.rb
View
17 activesupport/lib/active_support/testing/time_helpers.rb
@@ -38,13 +38,8 @@ def unstub_object(stub)
# 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 @@ def travel(duration, &block)
# 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

0 comments on commit 6dce436

Please sign in to comment.
Something went wrong with that request. Please try again.