timecop 0.5.2 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/README.markdown +48 -13
- data/Rakefile +10 -4
- data/lib/timecop/time_extensions.rb +128 -54
- data/lib/timecop/time_stack_item.rb +78 -83
- data/lib/timecop/timecop.rb +142 -49
- data/lib/timecop/version.rb +2 -2
- data/lib/timecop.rb +2 -2
- data/test/test_helper.rb +26 -17
- data/test/time_stack_item_test.rb +153 -73
- data/test/timecop_test.rb +247 -41
- data/test/timecop_without_date_but_with_time_test.rb +4 -8
- data/test/timecop_without_date_test.rb +22 -23
- metadata +16 -23
- data/History.rdoc +0 -137
- data/test/run_tests.sh +0 -6
data/test/timecop_test.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'timecop')
|
1
|
+
require_relative "test_helper"
|
2
|
+
require 'timecop'
|
4
3
|
|
5
|
-
class TestTimecop < Test
|
6
|
-
|
7
|
-
def setup
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
# just in case...let's really make sure that Timecop is disabled between tests...
|
4
|
+
class TestTimecop < Minitest::Test
|
12
5
|
def teardown
|
13
6
|
Timecop.return
|
14
7
|
end
|
15
8
|
|
16
9
|
def test_freeze_changes_and_resets_time
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
Timecop.freeze(
|
23
|
-
|
10
|
+
outer_freeze_time = Time.local(2001, 01, 01)
|
11
|
+
inner_freeze_block = Time.local(2002, 02, 02)
|
12
|
+
inner_freeze_one = Time.local(2003, 03, 03)
|
13
|
+
inner_freeze_two = Time.local(2004, 04, 04)
|
14
|
+
|
15
|
+
Timecop.freeze(outer_freeze_time) do
|
16
|
+
assert_times_effectively_equal outer_freeze_time, Time.now
|
17
|
+
Timecop.freeze(inner_freeze_block) do
|
18
|
+
assert_times_effectively_equal inner_freeze_block, Time.now
|
19
|
+
Timecop.freeze(inner_freeze_one)
|
20
|
+
assert_times_effectively_equal inner_freeze_one, Time.now
|
21
|
+
Timecop.freeze(inner_freeze_two)
|
22
|
+
assert_times_effectively_equal inner_freeze_two, Time.now
|
23
|
+
end
|
24
|
+
assert_times_effectively_equal outer_freeze_time, Time.now
|
24
25
|
end
|
25
|
-
assert_not_equal t, Time.now
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_freeze_yields_mocked_time
|
@@ -30,13 +30,19 @@ class TestTimecop < Test::Unit::TestCase
|
|
30
30
|
assert_equal frozen_time, Time.now
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def test_freeze_then_return_unsets_mock_time
|
35
35
|
Timecop.freeze(1)
|
36
36
|
Timecop.return
|
37
37
|
assert_nil Time.send(:mock_time)
|
38
38
|
end
|
39
39
|
|
40
|
+
def test_freeze_then_unfreeze_unsets_mock_time
|
41
|
+
Timecop.freeze(1)
|
42
|
+
Timecop.unfreeze
|
43
|
+
assert_nil Time.send(:mock_time)
|
44
|
+
end
|
45
|
+
|
40
46
|
def test_travel_then_return_unsets_mock_time
|
41
47
|
Timecop.travel(1)
|
42
48
|
Timecop.return
|
@@ -58,8 +64,11 @@ class TestTimecop < Test::Unit::TestCase
|
|
58
64
|
def test_travel_does_not_reduce_precision_of_datetime
|
59
65
|
# requires to_r on Float (>= 1.9)
|
60
66
|
if Float.method_defined?(:to_r)
|
61
|
-
Timecop.travel(1)
|
62
|
-
|
67
|
+
Timecop.travel(Time.new(2014, 1, 1, 0, 0, 0))
|
68
|
+
assert DateTime.now != DateTime.now
|
69
|
+
|
70
|
+
Timecop.travel(Time.new(2014, 1, 1, 0, 0, 59))
|
71
|
+
assert DateTime.now != DateTime.now
|
63
72
|
end
|
64
73
|
end
|
65
74
|
|
@@ -68,6 +77,7 @@ class TestTimecop < Test::Unit::TestCase
|
|
68
77
|
custom_timeklass = Class.new(Time) do
|
69
78
|
def custom_format_method() strftime('%F') end
|
70
79
|
end
|
80
|
+
|
71
81
|
Timecop.freeze(2008, 10, 10, 10, 10, 10) do
|
72
82
|
assert custom_timeklass.now.is_a? custom_timeklass
|
73
83
|
assert Time.now.eql? custom_timeklass.now
|
@@ -80,6 +90,7 @@ class TestTimecop < Test::Unit::TestCase
|
|
80
90
|
custom_dateklass = Class.new(Date) do
|
81
91
|
def custom_format_method() strftime('%F') end
|
82
92
|
end
|
93
|
+
|
83
94
|
Timecop.freeze(2008, 10, 10, 10, 10, 10) do
|
84
95
|
assert custom_dateklass.today.is_a? custom_dateklass
|
85
96
|
assert Date.today.eql? custom_dateklass.today
|
@@ -92,6 +103,7 @@ class TestTimecop < Test::Unit::TestCase
|
|
92
103
|
custom_datetimeklass = Class.new(DateTime) do
|
93
104
|
def custom_format_method() strftime('%F') end
|
94
105
|
end
|
106
|
+
|
95
107
|
Timecop.freeze(2008, 10, 10, 10, 10, 10) do
|
96
108
|
assert custom_datetimeklass.now.is_a? custom_datetimeklass
|
97
109
|
assert DateTime.now.eql? custom_datetimeklass.now
|
@@ -109,7 +121,7 @@ class TestTimecop < Test::Unit::TestCase
|
|
109
121
|
end
|
110
122
|
assert_equal t, Time.now
|
111
123
|
end
|
112
|
-
|
124
|
+
assert t != Time.now
|
113
125
|
end
|
114
126
|
|
115
127
|
def test_freeze_with_time_instance_works_as_expected
|
@@ -119,9 +131,10 @@ class TestTimecop < Test::Unit::TestCase
|
|
119
131
|
assert_date_times_equal DateTime.new(2008, 10, 10, 10, 10, 10, local_offset), DateTime.now
|
120
132
|
assert_equal Date.new(2008, 10, 10), Date.today
|
121
133
|
end
|
122
|
-
|
123
|
-
|
124
|
-
|
134
|
+
|
135
|
+
assert t != Time.now
|
136
|
+
assert DateTime.new(2008, 10, 10, 10, 10, 10, local_offset) != DateTime.now
|
137
|
+
assert Date.new(2008, 10, 10) != Date.today
|
125
138
|
end
|
126
139
|
|
127
140
|
def test_freeze_with_datetime_on_specific_timezone_during_dst
|
@@ -133,7 +146,6 @@ class TestTimecop < Test::Unit::TestCase
|
|
133
146
|
Timecop.freeze(t) do
|
134
147
|
assert_date_times_equal t, DateTime.now
|
135
148
|
end
|
136
|
-
# Undo the original freeze
|
137
149
|
Timecop.return
|
138
150
|
end
|
139
151
|
end
|
@@ -181,9 +193,9 @@ class TestTimecop < Test::Unit::TestCase
|
|
181
193
|
assert_equal Time.local(2008, 10, 10, 0, 0, 0), Time.now
|
182
194
|
assert_date_times_equal DateTime.new(2008, 10, 10, 0, 0, 0, local_offset), DateTime.now
|
183
195
|
end
|
184
|
-
|
185
|
-
|
186
|
-
|
196
|
+
assert d != Date.today
|
197
|
+
assert Time.local(2008, 10, 10, 0, 0, 0) != Time.now
|
198
|
+
assert DateTime.new(2008, 10, 10, 0, 0, 0, local_offset) != DateTime.now
|
187
199
|
end
|
188
200
|
|
189
201
|
def test_freeze_with_integer_instance_works_as_expected
|
@@ -198,9 +210,9 @@ class TestTimecop < Test::Unit::TestCase
|
|
198
210
|
assert_equal Date.new(2008, 10, 10), Date.today
|
199
211
|
end
|
200
212
|
end
|
201
|
-
|
202
|
-
|
203
|
-
|
213
|
+
assert t != Time.now
|
214
|
+
assert DateTime.new(2008, 10, 10, 10, 10, 10) != DateTime.now
|
215
|
+
assert Date.new(2008, 10, 10) != Date.today
|
204
216
|
end
|
205
217
|
|
206
218
|
def test_exception_thrown_in_freeze_block_properly_resets_time
|
@@ -211,11 +223,19 @@ class TestTimecop < Test::Unit::TestCase
|
|
211
223
|
raise "blah exception"
|
212
224
|
end
|
213
225
|
rescue
|
214
|
-
|
226
|
+
assert t != Time.now
|
215
227
|
assert_nil Time.send(:mock_time)
|
216
228
|
end
|
217
229
|
end
|
218
230
|
|
231
|
+
def test_exception_thrown_in_return_block_restores_previous_time
|
232
|
+
t = Time.local(2008, 10, 10, 10, 10, 10)
|
233
|
+
Timecop.freeze(t) do
|
234
|
+
Timecop.return { raise 'foobar' } rescue nil
|
235
|
+
assert_equal t, Time.now
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
219
239
|
def test_freeze_freezes_time
|
220
240
|
t = Time.local(2008, 10, 10, 10, 10, 10)
|
221
241
|
now = Time.now
|
@@ -237,7 +257,7 @@ class TestTimecop < Test::Unit::TestCase
|
|
237
257
|
new_now = Time.now
|
238
258
|
assert_times_effectively_equal(new_now, t, 1, "Looks like we failed to actually travel time")
|
239
259
|
sleep(0.25)
|
240
|
-
assert_times_effectively_not_equal new_now, Time.now, 0.
|
260
|
+
assert_times_effectively_not_equal new_now, Time.now, 0.24, "Looks like time is not moving"
|
241
261
|
end
|
242
262
|
end
|
243
263
|
|
@@ -245,12 +265,17 @@ class TestTimecop < Test::Unit::TestCase
|
|
245
265
|
each_timezone do
|
246
266
|
t = DateTime.parse("2009-10-11 00:38:00 +0200")
|
247
267
|
Timecop.freeze(t) do
|
268
|
+
if ENV['TZ'] == 'UTC'
|
269
|
+
assert_equal(local_offset, 0, "Local offset not be zero for #{ENV['TZ']}")
|
270
|
+
else
|
271
|
+
assert(local_offset, 0 != "Local offset should not be zero for #{ENV['TZ']}")
|
272
|
+
end
|
248
273
|
assert_equal local_offset, DateTime.now.offset, "Failed for timezone: #{ENV['TZ']}"
|
249
274
|
end
|
250
275
|
end
|
251
276
|
end
|
252
277
|
|
253
|
-
def
|
278
|
+
def test_scaling_keeps_time_moving_at_an_accelerated_rate
|
254
279
|
t = Time.local(2008, 10, 10, 10, 10, 10)
|
255
280
|
Timecop.scale(4, t) do
|
256
281
|
start = Time.now
|
@@ -260,6 +285,22 @@ class TestTimecop < Test::Unit::TestCase
|
|
260
285
|
end
|
261
286
|
end
|
262
287
|
|
288
|
+
def test_scaling_returns_now_if_no_block_given
|
289
|
+
t = Time.local(2008, 10, 10, 10, 10, 10)
|
290
|
+
assert_times_effectively_equal t, Timecop.scale(4, t)
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_scaling_returns_now_if_nil_supplied
|
294
|
+
assert_times_effectively_equal Time.now, Timecop.scale(nil)
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_scaling_raises_when_empty_string_supplied
|
298
|
+
err = assert_raises(TypeError) do
|
299
|
+
Timecop.scale("")
|
300
|
+
end
|
301
|
+
assert_match /String can't be coerced into Float/, err.message
|
302
|
+
end
|
303
|
+
|
263
304
|
def test_freeze_with_utc_time
|
264
305
|
each_timezone do
|
265
306
|
t = Time.utc(2008, 10, 10, 10, 10, 10)
|
@@ -270,6 +311,19 @@ class TestTimecop < Test::Unit::TestCase
|
|
270
311
|
end
|
271
312
|
end
|
272
313
|
|
314
|
+
def test_freeze_without_arguments_instance_works_as_expected
|
315
|
+
t = Time.local(2008, 10, 10, 10, 10, 10)
|
316
|
+
Timecop.freeze(t) do
|
317
|
+
assert_equal t, Time.now
|
318
|
+
Timecop.freeze do
|
319
|
+
assert_equal t, Time.now
|
320
|
+
assert_equal Time.local(2008, 10, 10, 10, 10, 10), Time.now
|
321
|
+
assert_equal Date.new(2008, 10, 10), Date.today
|
322
|
+
end
|
323
|
+
end
|
324
|
+
assert t != Time.now
|
325
|
+
end
|
326
|
+
|
273
327
|
def test_destructive_methods_on_frozen_time
|
274
328
|
# Use any time zone other than UTC.
|
275
329
|
ENV['TZ'] = 'EST'
|
@@ -300,13 +354,13 @@ class TestTimecop < Test::Unit::TestCase
|
|
300
354
|
end
|
301
355
|
|
302
356
|
def test_recursive_travel_yields_correct_time
|
303
|
-
Timecop.travel(2008, 10, 10, 10, 10, 10) do
|
357
|
+
Timecop.travel(2008, 10, 10, 10, 10, 10) do
|
304
358
|
Timecop.travel(2008, 9, 9, 9, 9, 9) do |inner_freeze|
|
305
359
|
assert_times_effectively_equal inner_freeze, Time.now, 1, "Failed to yield current time back to block"
|
306
360
|
end
|
307
361
|
end
|
308
362
|
end
|
309
|
-
|
363
|
+
|
310
364
|
def test_recursive_travel_then_freeze
|
311
365
|
t = Time.local(2008, 10, 10, 10, 10, 10)
|
312
366
|
Timecop.travel(2008, 10, 10, 10, 10, 10) do
|
@@ -334,9 +388,26 @@ class TestTimecop < Test::Unit::TestCase
|
|
334
388
|
assert_nil Time.send(:mock_time)
|
335
389
|
end
|
336
390
|
|
337
|
-
def
|
391
|
+
def test_travel_time_returns_now_if_no_block_given
|
338
392
|
t_future = Time.local(2030, 10, 10, 10, 10, 10)
|
339
|
-
|
393
|
+
assert_times_effectively_equal t_future, Timecop.travel(t_future)
|
394
|
+
end
|
395
|
+
|
396
|
+
def test_return_temporarily_returns_to_current_time_in_given_block
|
397
|
+
time_after_travel = Time.local(1990, 7, 16)
|
398
|
+
now = Time.now
|
399
|
+
|
400
|
+
Timecop.travel(time_after_travel)
|
401
|
+
|
402
|
+
assert_times_effectively_equal(time_after_travel, Time.now)
|
403
|
+
Timecop.return do
|
404
|
+
assert_times_effectively_equal(now, Time.now)
|
405
|
+
end
|
406
|
+
assert_times_effectively_equal(time_after_travel, Time.now)
|
407
|
+
end
|
408
|
+
|
409
|
+
def test_travel_returns_now_if_nil_supplied
|
410
|
+
assert_times_effectively_equal Time.now, Timecop.travel(nil)
|
340
411
|
end
|
341
412
|
|
342
413
|
def test_travel_time_with_block_returns_the_value_of_the_block
|
@@ -346,10 +417,17 @@ class TestTimecop < Test::Unit::TestCase
|
|
346
417
|
|
347
418
|
assert_equal expected, actual
|
348
419
|
end
|
420
|
+
|
421
|
+
def test_travel_raises_when_empty_string_supplied
|
422
|
+
err = assert_raises(ArgumentError) do
|
423
|
+
Timecop.travel("")
|
424
|
+
end
|
425
|
+
assert_match /no time information in \"\"/, err.message
|
426
|
+
end
|
349
427
|
|
350
|
-
def
|
428
|
+
def test_freeze_time_returns_now_if_no_block_given
|
351
429
|
t_future = Time.local(2030, 10, 10, 10, 10, 10)
|
352
|
-
|
430
|
+
assert_times_effectively_equal t_future, Timecop.freeze(t_future)
|
353
431
|
end
|
354
432
|
|
355
433
|
def test_freeze_time_with_block_returns_the_value_of_the_block
|
@@ -372,6 +450,17 @@ class TestTimecop < Test::Unit::TestCase
|
|
372
450
|
end
|
373
451
|
end
|
374
452
|
end
|
453
|
+
|
454
|
+
def test_freeze_returns_now_if_nil_supplied
|
455
|
+
assert_times_effectively_equal Time.now, Timecop.freeze(nil)
|
456
|
+
end
|
457
|
+
|
458
|
+
def test_freeze_raises_when_empty_string_supplied
|
459
|
+
err = assert_raises(ArgumentError) do
|
460
|
+
Timecop.freeze("")
|
461
|
+
end
|
462
|
+
assert_match /no time information in \"\"/, err.message
|
463
|
+
end
|
375
464
|
|
376
465
|
def test_freeze_with_new_date
|
377
466
|
date = Date.new(2012, 6, 9)
|
@@ -413,4 +502,121 @@ class TestTimecop < Test::Unit::TestCase
|
|
413
502
|
assert_equal date, Time.now
|
414
503
|
assert_equal date, Time.new
|
415
504
|
end
|
505
|
+
|
506
|
+
def test_not_callable_send_travel
|
507
|
+
assert_raises NoMethodError do
|
508
|
+
Timecop.send_travel(:travel, Time.now - 100)
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
512
|
+
def test_datetime_to_time_for_dst_to_non_dst
|
513
|
+
# Start at a time subject to DST
|
514
|
+
Timecop.travel(2009, 4, 1, 0, 0, 0, -4*60*60) do
|
515
|
+
|
516
|
+
# Then freeze, via DateTime, at a time not subject to DST
|
517
|
+
t = DateTime.new(2009,01,01,0,0,0, "-0500")
|
518
|
+
Timecop.freeze(t) do
|
519
|
+
|
520
|
+
# Check the current time via DateTime.now--should be what we asked for
|
521
|
+
assert_date_times_equal t, DateTime.now
|
522
|
+
|
523
|
+
# Then check the current time via Time.now (not DateTime.now)
|
524
|
+
assert_times_effectively_equal Time.new(2009, 1, 1, 0, 0, 0, -5*60*60), Time.now
|
525
|
+
end
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
529
|
+
def test_raises_when_safe_mode_and_no_block
|
530
|
+
with_safe_mode do
|
531
|
+
assert_raises Timecop::SafeModeException do
|
532
|
+
Timecop.freeze
|
533
|
+
end
|
534
|
+
end
|
535
|
+
end
|
536
|
+
|
537
|
+
def test_raises_when_safe_mode_and_no_block_though_previously_block_given
|
538
|
+
Timecop.freeze do
|
539
|
+
Timecop.freeze
|
540
|
+
end
|
541
|
+
|
542
|
+
with_safe_mode do
|
543
|
+
assert_raises Timecop::SafeModeException do
|
544
|
+
Timecop.freeze
|
545
|
+
end
|
546
|
+
end
|
547
|
+
end
|
548
|
+
|
549
|
+
def test_no_raise_when_safe_mode_and_block_used
|
550
|
+
with_safe_mode do
|
551
|
+
Timecop.freeze {}
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
def test_no_raise_when_not_safe_mode_and_no_block
|
556
|
+
with_safe_mode(false) do
|
557
|
+
Timecop.freeze
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
561
|
+
def test_no_raise_when_safe_mode_and_no_block_and_in_block_context
|
562
|
+
with_safe_mode do
|
563
|
+
Timecop.freeze do
|
564
|
+
Timecop.freeze
|
565
|
+
end
|
566
|
+
end
|
567
|
+
end
|
568
|
+
|
569
|
+
def test_frozen_after_freeze
|
570
|
+
Timecop.freeze
|
571
|
+
assert Timecop.frozen?
|
572
|
+
end
|
573
|
+
|
574
|
+
def test_frozen_inside_freeze
|
575
|
+
Timecop.freeze do
|
576
|
+
assert Timecop.frozen?
|
577
|
+
end
|
578
|
+
end
|
579
|
+
|
580
|
+
def test_not_frozen_after_return
|
581
|
+
Timecop.freeze
|
582
|
+
Timecop.return
|
583
|
+
assert !Timecop.frozen?
|
584
|
+
end
|
585
|
+
|
586
|
+
def test_thread_safe_timecop_in_parallel
|
587
|
+
Timecop.thread_safe = true
|
588
|
+
date = Time.local(2011, 01, 02)
|
589
|
+
thread = Thread.new do
|
590
|
+
Timecop.freeze(date) do
|
591
|
+
sleep 1 #give main thread time to run
|
592
|
+
assert_equal date, Time.now
|
593
|
+
end
|
594
|
+
end
|
595
|
+
|
596
|
+
sleep 0.25
|
597
|
+
assert Time.now != date
|
598
|
+
thread.join
|
599
|
+
ensure
|
600
|
+
Timecop.thread_safe = false
|
601
|
+
end
|
602
|
+
|
603
|
+
def test_thread_safe_timecop_returns_after_block
|
604
|
+
Timecop.thread_safe = true
|
605
|
+
date = Time.local(2017, 10, 8)
|
606
|
+
|
607
|
+
Timecop.freeze(date) { }
|
608
|
+
assert Time.now != date
|
609
|
+
ensure
|
610
|
+
Timecop.thread_safe = false
|
611
|
+
end
|
612
|
+
|
613
|
+
private
|
614
|
+
|
615
|
+
def with_safe_mode(enabled=true)
|
616
|
+
mode = Timecop.safe_mode?
|
617
|
+
Timecop.safe_mode = enabled
|
618
|
+
yield
|
619
|
+
ensure
|
620
|
+
Timecop.safe_mode = mode
|
621
|
+
end
|
416
622
|
end
|
@@ -1,12 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class TestTimecopWithoutDateButWithTime < Test::Unit::TestCase
|
4
|
-
TIMECOP_LIB = File.join(File.dirname(__FILE__), '..', 'lib', 'timecop')
|
1
|
+
require_relative "test_helper"
|
2
|
+
require "time"
|
5
3
|
|
4
|
+
class TestTimecopWithoutDateButWithTime < Minitest::Test
|
6
5
|
def test_loads_properly_when_time_is_required_instead_of_date
|
7
|
-
|
8
|
-
require "time"
|
9
|
-
require TIMECOP_LIB
|
10
|
-
end
|
6
|
+
require 'timecop'
|
11
7
|
end
|
12
8
|
end
|
@@ -1,34 +1,33 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
require 'timecop'
|
1
3
|
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'timecop')
|
4
|
+
class TestTimecopWithoutDate < Minitest::Test
|
4
5
|
|
5
|
-
class TestTimecopWithoutDate < Test::Unit::TestCase
|
6
|
-
|
7
6
|
def setup
|
8
7
|
Object.send(:remove_const, :Date) if Object.const_defined?(:Date)
|
9
8
|
Object.send(:remove_const, :DateTime) if Object.const_defined?(:DateTime)
|
10
9
|
end
|
11
|
-
|
10
|
+
|
12
11
|
# just in case...let's really make sure that Timecop is disabled between tests...
|
13
12
|
def teardown
|
14
13
|
Timecop.return
|
15
14
|
end
|
16
|
-
|
15
|
+
|
17
16
|
def test_freeze_changes_and_resets_time
|
18
17
|
# depending on how we're invoked (individually or via the rake test suite)
|
19
18
|
assert !Time.respond_to?(:zone) || Time.zone.nil?
|
20
|
-
|
19
|
+
|
21
20
|
t = Time.local(2008, 10, 10, 10, 10, 10)
|
22
|
-
|
21
|
+
assert t != Time.now
|
23
22
|
Timecop.freeze(2008, 10, 10, 10, 10, 10) do
|
24
23
|
assert_equal t, Time.now
|
25
24
|
end
|
26
|
-
|
25
|
+
assert t != Time.now
|
27
26
|
end
|
28
|
-
|
27
|
+
|
29
28
|
def test_recursive_freeze
|
30
29
|
t = Time.local(2008, 10, 10, 10, 10, 10)
|
31
|
-
Timecop.freeze(2008, 10, 10, 10, 10, 10) do
|
30
|
+
Timecop.freeze(2008, 10, 10, 10, 10, 10) do
|
32
31
|
assert_equal t, Time.now
|
33
32
|
t2 = Time.local(2008, 9, 9, 9, 9, 9)
|
34
33
|
Timecop.freeze(2008, 9, 9, 9, 9, 9) do
|
@@ -38,7 +37,7 @@ class TestTimecopWithoutDate < Test::Unit::TestCase
|
|
38
37
|
end
|
39
38
|
assert_nil Time.send(:mock_time)
|
40
39
|
end
|
41
|
-
|
40
|
+
|
42
41
|
def test_exception_thrown_in_freeze_block_properly_resets_time
|
43
42
|
t = Time.local(2008, 10, 10, 10, 10, 10)
|
44
43
|
begin
|
@@ -47,11 +46,11 @@ class TestTimecopWithoutDate < Test::Unit::TestCase
|
|
47
46
|
raise "blah exception"
|
48
47
|
end
|
49
48
|
rescue
|
50
|
-
|
49
|
+
assert t != Time.now
|
51
50
|
assert_nil Time.send(:mock_time)
|
52
51
|
end
|
53
52
|
end
|
54
|
-
|
53
|
+
|
55
54
|
def test_freeze_freezes_time
|
56
55
|
t = Time.local(2008, 10, 10, 10, 10, 10)
|
57
56
|
now = Time.now
|
@@ -63,7 +62,7 @@ class TestTimecopWithoutDate < Test::Unit::TestCase
|
|
63
62
|
assert_equal new_t, Time.now
|
64
63
|
end
|
65
64
|
end
|
66
|
-
|
65
|
+
|
67
66
|
def test_travel_keeps_time_moving
|
68
67
|
t = Time.local(2008, 10, 10, 10, 10, 10)
|
69
68
|
now = Time.now
|
@@ -71,13 +70,13 @@ class TestTimecopWithoutDate < Test::Unit::TestCase
|
|
71
70
|
new_now = Time.now
|
72
71
|
assert_times_effectively_equal new_now, t, 1, "Looks like we failed to actually travel time" # 0.1 seconds
|
73
72
|
sleep(0.25)
|
74
|
-
assert_times_effectively_not_equal new_now, Time.now, 0.
|
73
|
+
assert_times_effectively_not_equal new_now, Time.now, 0.24, "Looks like time is not moving"
|
75
74
|
end
|
76
75
|
end
|
77
|
-
|
76
|
+
|
78
77
|
def test_recursive_travel_maintains_each_context
|
79
78
|
t = Time.local(2008, 10, 10, 10, 10, 10)
|
80
|
-
Timecop.travel(2008, 10, 10, 10, 10, 10) do
|
79
|
+
Timecop.travel(2008, 10, 10, 10, 10, 10) do
|
81
80
|
assert((t - Time.now).abs < 50, "Failed to travel time.")
|
82
81
|
t2 = Time.local(2008, 9, 9, 9, 9, 9)
|
83
82
|
Timecop.travel(2008, 9, 9, 9, 9, 9) do
|
@@ -88,10 +87,10 @@ class TestTimecopWithoutDate < Test::Unit::TestCase
|
|
88
87
|
end
|
89
88
|
assert_nil Time.send(:mock_time)
|
90
89
|
end
|
91
|
-
|
90
|
+
|
92
91
|
def test_recursive_travel_then_freeze
|
93
92
|
t = Time.local(2008, 10, 10, 10, 10, 10)
|
94
|
-
Timecop.travel(2008, 10, 10, 10, 10, 10) do
|
93
|
+
Timecop.travel(2008, 10, 10, 10, 10, 10) do
|
95
94
|
assert((t - Time.now).abs < 50, "Failed to travel time.")
|
96
95
|
t2 = Time.local(2008, 9, 9, 9, 9, 9)
|
97
96
|
Timecop.freeze(2008, 9, 9, 9, 9, 9) do
|
@@ -101,10 +100,10 @@ class TestTimecopWithoutDate < Test::Unit::TestCase
|
|
101
100
|
end
|
102
101
|
assert_nil Time.send(:mock_time)
|
103
102
|
end
|
104
|
-
|
103
|
+
|
105
104
|
def test_recursive_freeze_then_travel
|
106
105
|
t = Time.local(2008, 10, 10, 10, 10, 10)
|
107
|
-
Timecop.freeze(t) do
|
106
|
+
Timecop.freeze(t) do
|
108
107
|
assert_equal t, Time.now
|
109
108
|
t2 = Time.local(2008, 9, 9, 9, 9, 9)
|
110
109
|
Timecop.travel(t2) do
|
@@ -113,7 +112,7 @@ class TestTimecopWithoutDate < Test::Unit::TestCase
|
|
113
112
|
end
|
114
113
|
assert_equal t, Time.now
|
115
114
|
end
|
116
|
-
assert_nil Time.send(:mock_time)
|
115
|
+
assert_nil Time.send(:mock_time)
|
117
116
|
end
|
118
117
|
|
119
118
|
end
|
metadata
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timecop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Travis Jeffery
|
9
8
|
- John Trupiano
|
10
|
-
autorequire:
|
9
|
+
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2022-03-07 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
|
@@ -22,47 +21,41 @@ extra_rdoc_files:
|
|
22
21
|
- LICENSE
|
23
22
|
- README.markdown
|
24
23
|
files:
|
25
|
-
- History.rdoc
|
26
24
|
- LICENSE
|
27
25
|
- README.markdown
|
28
26
|
- Rakefile
|
29
27
|
- lib/timecop.rb
|
30
28
|
- lib/timecop/time_extensions.rb
|
31
29
|
- lib/timecop/time_stack_item.rb
|
32
|
-
- lib/timecop/version.rb
|
33
30
|
- lib/timecop/timecop.rb
|
34
|
-
-
|
31
|
+
- lib/timecop/version.rb
|
35
32
|
- test/test_helper.rb
|
36
33
|
- test/time_stack_item_test.rb
|
37
34
|
- test/timecop_test.rb
|
38
|
-
- test/timecop_without_date_test.rb
|
39
35
|
- test/timecop_without_date_but_with_time_test.rb
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
- test/timecop_without_date_test.rb
|
37
|
+
homepage: https://github.com/travisjeffery/timecop
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
43
42
|
rdoc_options:
|
44
|
-
- --charset=UTF-8
|
43
|
+
- "--charset=UTF-8"
|
45
44
|
require_paths:
|
46
45
|
- lib
|
47
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
47
|
requirements:
|
50
|
-
- -
|
48
|
+
- - ">="
|
51
49
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
53
|
-
segments:
|
54
|
-
- 0
|
55
|
-
hash: -1525074573276164628
|
50
|
+
version: 1.9.2
|
56
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
52
|
requirements:
|
59
|
-
- -
|
53
|
+
- - ">="
|
60
54
|
- !ruby/object:Gem::Version
|
61
55
|
version: '0'
|
62
56
|
requirements: []
|
63
|
-
|
64
|
-
|
65
|
-
signing_key:
|
57
|
+
rubygems_version: 3.2.22
|
58
|
+
signing_key:
|
66
59
|
specification_version: 3
|
67
60
|
summary: A gem providing "time travel" and "time freezing" capabilities, making it
|
68
61
|
dead simple to test time-dependent code. It provides a unified method to mock Time.now,
|