timecop 0.5.9.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,21 +50,21 @@ class Timecop
50
50
  @scaling_factor
51
51
  end
52
52
 
53
- def time(time_klass = Time) #:nodoc:
53
+ def time(klass = time_klass) #:nodoc:
54
54
  begin
55
- actual_time = time_klass.at(@time)
56
- calculated_time = time_klass.at(@time.to_f)
55
+ actual_time = klass.at(@time)
56
+ calculated_time = klass.at(@time.to_f)
57
57
  time = times_are_equal_within_epsilon(actual_time, calculated_time, 1) ? actual_time : calculated_time
58
58
  rescue
59
- time = time_klass.at(@time.to_f)
59
+ time = klass.at(@time.to_f)
60
60
  end
61
61
 
62
62
  if travel_offset.nil?
63
63
  time
64
64
  elsif scaling_factor.nil?
65
- time_klass.at(Time.now_without_mock_time + travel_offset)
65
+ klass.at(Time.now_without_mock_time + travel_offset)
66
66
  else
67
- time_klass.at(scaled_time)
67
+ klass.at(scaled_time)
68
68
  end
69
69
  end
70
70
 
@@ -103,7 +103,6 @@ class Timecop
103
103
  end
104
104
 
105
105
  def parse_time(*args)
106
- time_klass = Time.respond_to?(:zone) && Time.zone ? Time.zone : Time
107
106
  arg = args.shift
108
107
  if arg.is_a?(Time)
109
108
  if Timecop.active_support != false && arg.respond_to?(:in_time_zone)
@@ -151,5 +150,9 @@ class Timecop
151
150
  def times_are_equal_within_epsilon t1, t2, epsilon_in_seconds
152
151
  (t1 - t2).abs < epsilon_in_seconds
153
152
  end
153
+
154
+ def time_klass
155
+ Time.respond_to?(:zone) ? Time.zone : Time
156
+ end
154
157
  end
155
- end
158
+ end
@@ -107,7 +107,7 @@ class Timecop
107
107
  private
108
108
  def send_travel(mock_type, *args, &block)
109
109
  val = instance.send(:travel, mock_type, *args, &block)
110
- block_given? ? val : Time.now
110
+ block_given? ? val : Time.now
111
111
  end
112
112
  end
113
113
 
@@ -1,3 +1,3 @@
1
1
  class Timecop
2
- VERSION = "0.5.9.2"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -192,6 +192,16 @@ class TestTimeStackItem < Test::Unit::TestCase
192
192
  end
193
193
  end
194
194
 
195
+ def test_timezones_apply_dates
196
+ require 'active_support/all'
197
+ Time.zone = "Marshall Is."
198
+ time = Time.zone.local(2013,1,3)
199
+
200
+ Timecop.freeze(time) do
201
+ assert_equal time.to_date, Date.today
202
+ end
203
+ end
204
+
195
205
  def test_set_scaling_factor_for_scale
196
206
  t_now = Time.now
197
207
  t = Time.local(2009, 10, 1, 0, 0, 30)
@@ -247,7 +257,7 @@ class TestTimeStackItem < Test::Unit::TestCase
247
257
 
248
258
  def test_time_with_different_timezone
249
259
  require 'active_support/all'
250
-
260
+
251
261
  Time.zone = "Tokyo"
252
262
  t = Time.now
253
263
  Timecop.freeze(t) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timecop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9.2
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-11 00:00:00.000000000 Z
13
+ date: 2013-03-08 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: A gem providing "time travel" and "time freezing" capabilities, making
16
16
  it dead simple to test time-dependent code. It provides a unified method to mock