Permalink
Browse files

Add Timecop to mock time dependent tests

  • Loading branch information...
1 parent 3248f10 commit 90e0ac9ddb02865e8f51b4b9a128660d1bb9583d Denis Odorcic committed Jun 18, 2012
Showing with 4 additions and 1 deletion.
  1. +1 −0 active_shipping.gemspec
  2. +1 −0 test/test_helper.rb
  3. +2 −1 test/unit/carriers/ups_test.rb
View
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('rake')
s.add_development_dependency('mocha')
+ s.add_development_dependency('timecop')
s.files = Dir.glob("lib/**/*") + %w(MIT-LICENSE README.markdown CHANGELOG)
s.require_path = 'lib'
View
@@ -8,6 +8,7 @@
require 'test/unit'
require 'active_shipping'
require 'mocha'
+require 'timecop'
XmlNode # trigger autorequire
@@ -140,10 +140,11 @@ def test_delivery_range_takes_weekend_into_consideration
@locations[:real_home_as_residential],
@packages.values_at(:chocolate_stuff))
- DateTime.stubs(:now => DateTime.new(2012, 6, 15))
+ Timecop.freeze(DateTime.new(2012, 6, 15))
date_test = [nil, 3, 2, 1, 1, 1].map do |days|
DateTime.now + days + 3 if days
end
+ Timecop.return
assert_equal date_test, response.rates.map(&:delivery_date)
end

0 comments on commit 90e0ac9

Please sign in to comment.