timecop 0.6.1 → 0.6.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50d8a097f64ecc69c2fd97409fd484d4ae24ea32
4
+ data.tar.gz: 2331d9650b9cbcc142d4dbddf9a93c615bf18e1d
5
+ SHA512:
6
+ metadata.gz: fe7d7dc16fa00728272702b53e7fb8dc9bc1736e43085696a20f3bd381941704d9112639e1c3623278bdf0709986361664777d1efb97a9e34961ff9f14d33dc1
7
+ data.tar.gz: e03aec0f8836e109a6d399e3a983757b35a31c701944396ac0a4154d2ba08be333c032af7af42836b6c3746cb3af09cfde30b0899ca0b39d8d3bea04c3b18989
@@ -11,7 +11,7 @@ A gem providing "time travel" and "time freezing" capabilities, making it dead s
11
11
 
12
12
  ## INSTALL
13
13
 
14
- gem install timecop
14
+ `gem install timecop`
15
15
 
16
16
  ## FEATURES
17
17
 
@@ -49,7 +49,7 @@ describe "some set of tests to mock" do
49
49
  before do
50
50
  Timecop.freeze(Time.local(1990))
51
51
  end
52
-
52
+
53
53
  after do
54
54
  Timecop.return
55
55
  end
@@ -62,7 +62,7 @@ Set the time for the test environment of a rails app -- this is particularly
62
62
  helpful if your whole application is time-sensitive. It allows you to build
63
63
  your test data at a single point in time, and to move in/out of that time as
64
64
  appropriate (within your tests)
65
-
65
+
66
66
  in config/environments/test.rb
67
67
 
68
68
  ```ruby
@@ -113,17 +113,10 @@ Time.now
113
113
 
114
114
  See #42 for more information, thanks to Ken Mayer, David Holcomb, and Pivotal Labs.
115
115
 
116
- ## REFERENCES
117
-
118
- * {0.3.4 release}[http://blog.smartlogicsolutions.com/2009/12/07/timecop-0-3-4-released/]
119
- * {0.3.0 release}[http://blog.smartlogicsolutions.com/2009/09/20/timecop-0-3-0-released/]
120
- * {0.2.0 release}[http://blog.smartlogicsolutions.com/2008/12/24/timecop-2-released-freeze-and-rebase-time-ruby/]
121
- * {0.1.0 release}[http://blog.smartlogicsolutions.com/2008/11/19/timecop-freeze-time-in-ruby-for-better-testing/]
122
-
123
116
  ## Contribute
124
117
 
125
118
  timecop is maintained by [travisjeffery](http://github.com/travisjeffery), and
126
- was created by [jtrupiano](https://github.com/jtrupiano).
119
+ was created by [jtrupiano](https://github.com/jtrupiano).
127
120
 
128
121
  Here's the most direct way to get your work merged into the project.
129
122
 
@@ -136,3 +129,4 @@ Here's the most direct way to get your work merged into the project.
136
129
  - Push the branch up to your fork
137
130
  - Send a pull request for your branch
138
131
 
132
+
data/Rakefile CHANGED
@@ -20,8 +20,8 @@ Rake::RDocTask.new do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
- task :test do
24
- system "cd test && ./run_tests.sh"
23
+ task :test do
24
+ system "cd test && ./run_tests.sh" or fail
25
25
  end
26
26
 
27
27
  desc 'Default: run tests'
@@ -1,3 +1,4 @@
1
+ require 'date'
1
2
 
2
3
  class Time #:nodoc:
3
4
  class << self
@@ -5,77 +6,57 @@ class Time #:nodoc:
5
6
  mocked_time_stack_item = Timecop.top_stack_item
6
7
  mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.time(self)
7
8
  end
8
-
9
+
9
10
  alias_method :now_without_mock_time, :now
10
11
 
11
12
  def now_with_mock_time
12
13
  mock_time || now_without_mock_time
13
14
  end
14
-
15
+
15
16
  alias_method :now, :now_with_mock_time
16
17
 
17
18
  alias_method :new_without_mock_time, :new
18
19
 
19
20
  def new_with_mock_time(*args)
20
- begin
21
- raise ArgumentError.new if args.size <= 0
22
- new_without_mock_time(*args)
23
- rescue ArgumentError
24
- now
25
- end
21
+ args.size <= 0 ? now : new_without_mock_time(*args)
26
22
  end
27
23
 
28
24
  alias_method :new, :new_with_mock_time
29
25
  end
30
- end
26
+ end
31
27
 
32
- if Object.const_defined?(:Date) && Date.respond_to?(:today)
33
- class Date #:nodoc:
34
- class << self
35
- def mock_date
36
- mocked_time_stack_item = Timecop.top_stack_item
37
- mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.date(self)
38
- end
39
-
40
- alias_method :today_without_mock_date, :today
41
-
42
- def today_with_mock_date
43
- mock_date || today_without_mock_date
44
- end
45
-
46
- alias_method :today, :today_with_mock_date
28
+ class Date #:nodoc:
29
+ class << self
30
+ def mock_date
31
+ mocked_time_stack_item = Timecop.top_stack_item
32
+ mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.date(self)
47
33
  end
34
+
35
+ alias_method :today_without_mock_date, :today
36
+
37
+ def today_with_mock_date
38
+ mock_date || today_without_mock_date
39
+ end
40
+
41
+ alias_method :today, :today_with_mock_date
48
42
  end
49
43
  end
50
44
 
51
- if Object.const_defined?(:DateTime) && DateTime.respond_to?(:now)
52
- class DateTime #:nodoc:
53
- class << self
54
- def mock_time
55
- mocked_time_stack_item = Timecop.top_stack_item
56
- mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.datetime(self)
57
- end
58
-
59
- def now_without_mock_time
60
- Time.now_without_mock_time.to_datetime
61
- end
62
-
63
- def now_with_mock_time
64
- mock_time || now_without_mock_time
65
- end
45
+ class DateTime #:nodoc:
46
+ class << self
47
+ def mock_time
48
+ mocked_time_stack_item = Timecop.top_stack_item
49
+ mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.datetime(self)
50
+ end
66
51
 
67
- alias_method :now, :now_with_mock_time
52
+ def now_without_mock_time
53
+ Time.now_without_mock_time.to_datetime
68
54
  end
69
- end
70
55
 
71
- # for ruby1.8
72
- unless Time::public_instance_methods.include? :to_datetime
73
- class DateTime
74
- class << self
75
- def now_without_mock_time
76
- Time.now_without_mock_time.send(:to_datetime)
77
- end
78
- end
56
+ def now_with_mock_time
57
+ mock_time || now_without_mock_time
79
58
  end
59
+
60
+ alias_method :now, :now_with_mock_time
80
61
  end
81
62
  end
@@ -11,7 +11,6 @@ class Timecop
11
11
  @time = parse_time(*args)
12
12
  @time_was = Time.now_without_mock_time
13
13
  @travel_offset = compute_travel_offset
14
- @dst_adjustment = compute_dst_adjustment(@time)
15
14
  end
16
15
 
17
16
  def year
@@ -50,21 +49,19 @@ class Timecop
50
49
  @scaling_factor
51
50
  end
52
51
 
53
- def time(klass = time_klass) #:nodoc:
54
- begin
55
- actual_time = klass.at(@time)
56
- calculated_time = klass.at(@time.to_f)
57
- time = times_are_equal_within_epsilon(actual_time, calculated_time, 1) ? actual_time : calculated_time
58
- rescue
59
- time = klass.at(@time.to_f)
52
+ def time(time_klass = Time) #:nodoc:
53
+ if @time.respond_to?(:in_time_zone)
54
+ time = time_klass.at(@time.utc.to_r)
55
+ else
56
+ time = time_klass.at(@time)
60
57
  end
61
58
 
62
59
  if travel_offset.nil?
63
60
  time
64
61
  elsif scaling_factor.nil?
65
- klass.at(Time.now_without_mock_time + travel_offset)
62
+ time_klass.at((Time.now_without_mock_time + travel_offset).to_f)
66
63
  else
67
- klass.at(scaled_time)
64
+ time_klass.at(scaled_time)
68
65
  end
69
66
  end
70
67
 
@@ -77,21 +74,18 @@ class Timecop
77
74
  end
78
75
 
79
76
  def datetime(datetime_klass = DateTime)
80
- our_offset = utc_offset + dst_adjustment
81
-
82
77
  if Float.method_defined?(:to_r)
83
- fractions_of_a_second = time.to_f % 1
84
- datetime_klass.new(year, month, day, hour, min, sec + fractions_of_a_second, utc_offset_to_rational(our_offset))
78
+ if !sec.zero?
79
+ fractions_of_a_second = time.to_f % 1
80
+ datetime_klass.new(year, month, day, hour, min, (fractions_of_a_second + sec), utc_offset_to_rational(utc_offset))
81
+ else
82
+ datetime_klass.new(year, month, day, hour, min, sec, utc_offset_to_rational(utc_offset))
83
+ end
85
84
  else
86
- our_offset = utc_offset + dst_adjustment
87
- datetime_klass.new(year, month, day, hour, min, sec, utc_offset_to_rational(our_offset))
85
+ datetime_klass.new(year, month, day, hour, min, sec, utc_offset_to_rational(utc_offset))
88
86
  end
89
87
  end
90
88
 
91
- def dst_adjustment
92
- @dst_adjustment
93
- end
94
-
95
89
  private
96
90
 
97
91
  def rational_to_utc_offset(rational)
@@ -105,15 +99,9 @@ class Timecop
105
99
  def parse_time(*args)
106
100
  arg = args.shift
107
101
  if arg.is_a?(Time)
108
- if Timecop.active_support != false && arg.respond_to?(:in_time_zone)
109
- arg.in_time_zone
110
- else
111
- arg.getlocal
112
- end
102
+ arg
113
103
  elsif Object.const_defined?(:DateTime) && arg.is_a?(DateTime)
114
- expected_time = time_klass.local(arg.year, arg.month, arg.day, arg.hour, arg.min, arg.sec)
115
- expected_time += expected_time.utc_offset - rational_to_utc_offset(arg.offset)
116
- expected_time + compute_dst_adjustment(expected_time)
104
+ time_klass.at(arg.to_time.to_f).getlocal
117
105
  elsif Object.const_defined?(:Date) && arg.is_a?(Date)
118
106
  time_klass.local(arg.year, arg.month, arg.day, 0, 0, 0)
119
107
  elsif args.empty? && arg.kind_of?(Integer)
@@ -121,7 +109,7 @@ class Timecop
121
109
  elsif arg.nil?
122
110
  Time.now
123
111
  else
124
- if arg.is_a?(String) && Timecop.active_support != false && Time.respond_to?(:parse)
112
+ if arg.is_a?(String) && Time.respond_to?(:parse)
125
113
  Time.parse(arg)
126
114
  else
127
115
  # we'll just assume it's a list of y/m/d/h/m/s
@@ -136,12 +124,6 @@ class Timecop
136
124
  end
137
125
  end
138
126
 
139
- def compute_dst_adjustment(time)
140
- return 0 if !(time.dst? ^ Time.now.dst?)
141
- return -1 * 60 * 60 if time.dst?
142
- return 60 * 60
143
- end
144
-
145
127
  def compute_travel_offset
146
128
  return nil if mock_type == :freeze
147
129
  time - Time.now_without_mock_time
@@ -14,8 +14,6 @@ class Timecop
14
14
  include Singleton
15
15
 
16
16
  class << self
17
- attr_accessor :active_support
18
-
19
17
  # Allows you to run a block of code and "fake" a time throughout the execution of that block.
20
18
  # This is particularly useful for writing test methods where the passage of time is critical to the business
21
19
  # logic being tested. For example:
@@ -125,13 +123,14 @@ class Timecop
125
123
  def travel(mock_type, *args, &block) #:nodoc:
126
124
  stack_item = TimeStackItem.new(mock_type, *args)
127
125
 
126
+ stack_backup = @_stack.dup
128
127
  @_stack << stack_item
129
128
 
130
129
  if block_given?
131
130
  begin
132
131
  yield stack_item.time
133
132
  ensure
134
- @_stack.pop
133
+ @_stack.replace stack_backup
135
134
  end
136
135
  end
137
136
  end
@@ -1,3 +1,3 @@
1
1
  class Timecop
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2.2"
3
3
  end
@@ -1,6 +1,10 @@
1
1
  #!/bin/sh
2
2
 
3
+ FAILEDCASES=0
3
4
  for f in *_test.rb; do
4
- ${RUBY:-ruby} -I../lib:. $f
5
+ if ! ${RUBY:-ruby} -I../lib:. $f; then
6
+ FAILEDCASES=`expr "$FAILEDCASES" + 1`
7
+ fi
5
8
  done
6
-
9
+ echo "$FAILEDCASES test cases had failures"
10
+ exit $FAILEDCASES
@@ -48,7 +48,7 @@ class Test::Unit::TestCase
48
48
  end
49
49
 
50
50
  def assert_date_times_equal(dt1, dt2)
51
- assert_equal dt1, dt2, "Failed for timezone: #{ENV['TZ']}: #{dt1.to_s} not equal to #{dt2.to_s}"
51
+ assert_in_delta dt1.to_time.to_f, dt2.to_time.to_f, 0.01, "Failed for timezone: #{ENV['TZ']}: #{dt1.to_s} not equal to #{dt2.to_s}"
52
52
  end
53
53
 
54
54
  end
@@ -2,10 +2,12 @@ require 'date'
2
2
  require File.join(File.dirname(__FILE__), "test_helper")
3
3
  require File.join(File.dirname(__FILE__), '..', 'lib', 'timecop')
4
4
 
5
+ require 'active_support/all'
6
+
5
7
  class TestTimeStackItem < Test::Unit::TestCase
6
8
  def teardown
7
- Timecop.active_support = nil
8
9
  Timecop.return
10
+ Time.zone = nil
9
11
  end
10
12
 
11
13
  def test_new_with_time
@@ -111,49 +113,35 @@ class TestTimeStackItem < Test::Unit::TestCase
111
113
  assert_equal Rational(1, 24), a_time_stack_item.send(:utc_offset_to_rational, 3600)
112
114
  end
113
115
 
114
- def test_compute_dst_adjustment_for_dst_to_dst
115
- Timecop.freeze(DateTime.parse("2009-10-1 00:38:00 -0400"))
116
- t = DateTime.parse("2009-10-11 00:00:00 -0400")
117
- tsi = Timecop::TimeStackItem.new(:freeze, t)
118
- return if !(Time.now.dst? && tsi.time.dst?)
119
-
120
- assert_equal 0, tsi.send(:dst_adjustment)
121
- end
122
-
123
- def test_compute_dst_adjustment_for_non_dst_to_non_dst
124
- Timecop.freeze(DateTime.parse("2009-12-1 00:38:00 -0400"))
125
- t = DateTime.parse("2009-12-11 00:00:00 -0400")
126
- tsi = Timecop::TimeStackItem.new(:freeze, t)
127
- return if Time.now.dst? || tsi.time.dst?
128
-
129
- assert_equal 0, tsi.send(:dst_adjustment)
130
- end
116
+ def test_datetime_in_presence_of_activesupport_timezone
117
+ skip('requires ActiveSupport') unless Time.respond_to? :zone
118
+ backed_up_zone, backed_up_tzvar = Time.zone, ENV['TZ']
131
119
 
132
- def test_compute_dst_adjustment_for_dst_to_non_dst
133
- Timecop.freeze(DateTime.parse("2009-10-1 00:38:00 -0400"))
134
- t = DateTime.parse("2009-12-11 00:00:00 -0400")
120
+ Time.zone = ENV['TZ'] = 'America/Los_Angeles'
121
+ t = DateTime.new(2001, 2, 28, 23, 59, 59.5)
135
122
  tsi = Timecop::TimeStackItem.new(:freeze, t)
136
- return if !Time.now.dst? || tsi.time.dst?
137
123
 
138
- assert_equal 60 * 60, tsi.send(:dst_adjustment)
124
+ assert_date_times_equal t, tsi.datetime
125
+ ensure
126
+ Time.zone, ENV['TZ'] = backed_up_zone, backed_up_tzvar
139
127
  end
140
128
 
141
- def test_compute_dst_adjustment_for_non_dst_to_dst
142
- Timecop.freeze(DateTime.parse("2009-12-1 00:38:00 -0400"))
129
+ # Ensure DateTimes handle changing DST properly
130
+ def test_datetime_for_dst_to_non_dst
131
+ Timecop.freeze(DateTime.parse("2009-12-1 00:38:00 -0500"))
143
132
  t = DateTime.parse("2009-10-11 00:00:00 -0400")
144
133
  tsi = Timecop::TimeStackItem.new(:freeze, t)
145
- return if Time.now.dst? || !tsi.time.dst?
146
134
 
147
- assert_equal -1 * 60 * 60, tsi.send(:dst_adjustment)
135
+ assert_date_times_equal t, tsi.datetime
148
136
  end
149
137
 
150
- # Ensure DateTimes handle changing DST properly
151
- def test_datetime_for_dst_to_non_dst
138
+ # Ensure DateTimes handle changing DST properly when changing from DateTime to Time
139
+ def test_datetime_for_dst_to_time_for_non_dst
152
140
  Timecop.freeze(DateTime.parse("2009-12-1 00:38:00 -0500"))
153
141
  t = DateTime.parse("2009-10-11 00:00:00 -0400")
154
142
  tsi = Timecop::TimeStackItem.new(:freeze, t)
155
143
 
156
- assert_date_times_equal t, tsi.datetime
144
+ assert_date_times_equal t.to_time, tsi.time
157
145
  end
158
146
 
159
147
  def test_datetime_for_non_dst_to_dst
@@ -184,7 +172,6 @@ class TestTimeStackItem < Test::Unit::TestCase
184
172
  end
185
173
 
186
174
  def test_timezones
187
- require 'active_support/all'
188
175
  Time.zone = "Europe/Zurich"
189
176
  time = Time.zone.parse("2012-12-27T12:12:12+08:00")
190
177
  Timecop.freeze(time) do |frozen_time|
@@ -193,12 +180,11 @@ class TestTimeStackItem < Test::Unit::TestCase
193
180
  end
194
181
 
195
182
  def test_timezones_apply_dates
196
- require 'active_support/all'
197
- Time.zone = "Marshall Is."
183
+ Time.zone = "Central Time (US & Canada)"
198
184
  time = Time.zone.local(2013,1,3)
199
185
 
200
186
  Timecop.freeze(time) do
201
- assert_equal time.to_date, Date.today
187
+ assert_equal time.to_date, Time.now.to_date
202
188
  end
203
189
  end
204
190
 
@@ -212,36 +198,11 @@ class TestTimeStackItem < Test::Unit::TestCase
212
198
  assert_equal tsi.send(:scaling_factor), 4, "Scaling factor not set"
213
199
  end
214
200
 
215
- def test_parse_string_date_with_active_support
216
- date = '2012-01-02'
217
- Time.expects(:parse).with(date).returns(Time.local(2012, 01, 02))
218
- Timecop.freeze(date)
219
- end
220
-
221
201
  def test_parse_only_string_with_active_support
222
202
  Time.expects(:parse).never
223
203
  Timecop.freeze(2011, 01, 02, hour=0, minute=0, second=0)
224
204
  end
225
205
 
226
- def test_parse_with_active_support_off
227
- date = '2012-01-02'
228
- Timecop.active_support = false
229
- Time.expects(:parse).never
230
- Timecop.freeze(date)
231
- end
232
-
233
- def test_uses_active_supports_in_time_zone
234
- time = Time.now
235
- Time.any_instance.expects(:in_time_zone).returns(time)
236
- Timecop::TimeStackItem.new(:freeze, time)
237
- end
238
-
239
- def test_configured_off_active_support_in_time_zone_xxx
240
- Timecop.active_support = false
241
- Time.any_instance.expects(:in_time_zone).never
242
- Timecop::TimeStackItem.new(:freeze, Time.now)
243
- end
244
-
245
206
  def test_parse_date
246
207
  assert_nothing_raised do
247
208
  Timecop.freeze(Date.new(2012, 6, 9))
@@ -249,8 +210,7 @@ class TestTimeStackItem < Test::Unit::TestCase
249
210
  end
250
211
 
251
212
  def test_time_zone_returns_nil
252
- c = class << Time; self end
253
- c.send(:define_method, :zone) { nil }
213
+ Time.zone = nil
254
214
  assert_nothing_raised do
255
215
  Timecop.freeze
256
216
  end
@@ -263,13 +223,51 @@ class TestTimeStackItem < Test::Unit::TestCase
263
223
  assert_equal time.nsec, Time.now.nsec if (Time.now.respond_to?(:nsec))
264
224
  end
265
225
 
266
- def test_time_with_different_timezone
267
- require 'active_support/all'
268
-
226
+ def test_time_with_different_timezone_keeps_nsec
269
227
  Time.zone = "Tokyo"
270
228
  t = Time.now
271
229
  Timecop.freeze(t) do
272
- assert_times_effectively_equal t, Time.now
230
+ assert_equal t, Time.now
231
+ assert_equal t.nsec, Time.now.nsec if (Time.now.respond_to?(:nsec))
232
+ end
233
+ end
234
+
235
+ def test_time_now_always_returns_local_time
236
+ Time.zone = "Tokyo"
237
+ t = Time.utc(2000, 1, 1)
238
+ Timecop.freeze(t) do
239
+ assert_equal t.getlocal.zone, Time.now.zone
240
+ end
241
+ end
242
+
243
+ def test_time_zone_now_returns_time_in_that_zone
244
+ Time.zone = "Hawaii"
245
+ t = Time.utc(2000, 1, 1)
246
+ Timecop.freeze(t) do
247
+ assert_equal t, Time.zone.now
248
+ assert_equal 'HST', Time.zone.now.zone
249
+ end
250
+ end
251
+
252
+ def test_freezing_a_time_with_zone_returns_proper_zones
253
+ Time.zone = "Hawaii"
254
+ t = ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1), ActiveSupport::TimeZone['Tokyo'])
255
+ Timecop.freeze(t) do
256
+ local_now = Time.now
257
+ assert_equal t, local_now
258
+ assert_equal t.getlocal.zone, local_now.zone
259
+
260
+ zoned_now = Time.zone.now
261
+ assert_equal t, zoned_now
262
+ assert_equal 'HST', zoned_now.zone
263
+ end
264
+ end
265
+
266
+ def test_datetime_timezones
267
+ dt = DateTime.new(2011,1,3,15,25,0,"-6")
268
+ Timecop.travel(dt) do
269
+ now = DateTime.now
270
+ assert_equal dt, now, "#{dt.to_f}, #{now.to_f}"
273
271
  end
274
272
  end
275
273
  end
@@ -8,16 +8,22 @@ class TestTimecop < Test::Unit::TestCase
8
8
  end
9
9
 
10
10
  def test_freeze_changes_and_resets_time
11
- assert !Time.respond_to?(:zone) || Time.zone.nil?
12
-
13
- t = Time.local(2008, 10, 10, 10, 10, 10)
14
- assert_not_equal t, Time.now
15
-
16
- Timecop.freeze(2008, 10, 10, 10, 10, 10) do
17
- assert_equal t, Time.now
11
+ outer_freeze_time = Time.local(2001, 01, 01)
12
+ inner_freeze_block = Time.local(2002, 02, 02)
13
+ inner_freeze_one = Time.local(2003, 03, 03)
14
+ inner_freeze_two = Time.local(2004, 04, 04)
15
+
16
+ Timecop.freeze(outer_freeze_time) do
17
+ assert_times_effectively_equal outer_freeze_time, Time.now
18
+ Timecop.freeze(inner_freeze_block) do
19
+ assert_times_effectively_equal inner_freeze_block, Time.now
20
+ Timecop.freeze(inner_freeze_one)
21
+ assert_times_effectively_equal inner_freeze_one, Time.now
22
+ Timecop.freeze(inner_freeze_two)
23
+ assert_times_effectively_equal inner_freeze_two, Time.now
24
+ end
25
+ assert_times_effectively_equal outer_freeze_time, Time.now
18
26
  end
19
-
20
- assert_not_equal t, Time.now
21
27
  end
22
28
 
23
29
  def test_freeze_yields_mocked_time
@@ -435,4 +441,22 @@ class TestTimecop < Test::Unit::TestCase
435
441
  Timecop.send_travel(:travel, Time.now - 100)
436
442
  end
437
443
  end
444
+
445
+ def test_datetime_to_time_for_dst_to_non_dst
446
+ # Start at a time subject to DST
447
+ Timecop.travel(2009, 4, 1, 0, 0, 0, -4*60*60) do
448
+
449
+ # Then freeze, via DateTime, at a time not subject to DST
450
+ t = DateTime.new(2009,01,01,0,0,0, "-0500")
451
+ Timecop.freeze(t) do
452
+
453
+ # Check the current time via DateTime.now--should be what we asked for
454
+ assert_date_times_equal t, DateTime.now
455
+
456
+ # Then check the current time via Time.now (not DateTime.now)
457
+ assert_times_effectively_equal Time.new(2009, 1, 1, 0, 0, 0, -5*60*60), Time.now
458
+ end
459
+ end
460
+ end
461
+
438
462
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timecop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
5
- prerelease:
4
+ version: 0.6.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Travis Jeffery
@@ -10,7 +9,7 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-03-11 00:00:00.000000000 Z
12
+ date: 2013-07-20 00:00:00.000000000 Z
14
13
  dependencies: []
15
14
  description: A gem providing "time travel" and "time freezing" capabilities, making
16
15
  it dead simple to test time-dependent code. It provides a unified method to mock
@@ -39,26 +38,25 @@ files:
39
38
  homepage: https://github.com/travisjeffery/timecop
40
39
  licenses:
41
40
  - MIT
41
+ metadata: {}
42
42
  post_install_message:
43
43
  rdoc_options:
44
44
  - --charset=UTF-8
45
45
  require_paths:
46
46
  - lib
47
47
  required_ruby_version: !ruby/object:Gem::Requirement
48
- none: false
49
48
  requirements:
50
- - - ! '>='
49
+ - - '>='
51
50
  - !ruby/object:Gem::Version
52
- version: '0'
51
+ version: 1.9.2
53
52
  required_rubygems_version: !ruby/object:Gem::Requirement
54
- none: false
55
53
  requirements:
56
- - - ! '>='
54
+ - - '>='
57
55
  - !ruby/object:Gem::Version
58
56
  version: '0'
59
57
  requirements: []
60
58
  rubyforge_project: timecop
61
- rubygems_version: 1.8.23
59
+ rubygems_version: 2.0.3
62
60
  signing_key:
63
61
  specification_version: 3
64
62
  summary: A gem providing "time travel" and "time freezing" capabilities, making it