timecop 0.9.6 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +9 -9
- data/lib/timecop/time_extensions.rb +80 -9
- data/lib/timecop/time_stack_item.rb +31 -0
- data/lib/timecop/timecop.rb +18 -2
- data/lib/timecop/version.rb +1 -1
- metadata +4 -14
- data/test/test_helper.rb +0 -59
- data/test/time_stack_item_test.rb +0 -299
- data/test/timecop_test.rb +0 -622
- data/test/timecop_without_date_but_with_time_test.rb +0 -8
- data/test/timecop_without_date_test.rb +0 -118
@@ -1,118 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
require 'timecop'
|
3
|
-
|
4
|
-
class TestTimecopWithoutDate < Minitest::Test
|
5
|
-
|
6
|
-
def setup
|
7
|
-
Object.send(:remove_const, :Date) if Object.const_defined?(:Date)
|
8
|
-
Object.send(:remove_const, :DateTime) if Object.const_defined?(:DateTime)
|
9
|
-
end
|
10
|
-
|
11
|
-
# just in case...let's really make sure that Timecop is disabled between tests...
|
12
|
-
def teardown
|
13
|
-
Timecop.return
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_freeze_changes_and_resets_time
|
17
|
-
# depending on how we're invoked (individually or via the rake test suite)
|
18
|
-
assert !Time.respond_to?(:zone) || Time.zone.nil?
|
19
|
-
|
20
|
-
t = Time.local(2008, 10, 10, 10, 10, 10)
|
21
|
-
assert t != Time.now
|
22
|
-
Timecop.freeze(2008, 10, 10, 10, 10, 10) do
|
23
|
-
assert_equal t, Time.now
|
24
|
-
end
|
25
|
-
assert t != Time.now
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_recursive_freeze
|
29
|
-
t = Time.local(2008, 10, 10, 10, 10, 10)
|
30
|
-
Timecop.freeze(2008, 10, 10, 10, 10, 10) do
|
31
|
-
assert_equal t, Time.now
|
32
|
-
t2 = Time.local(2008, 9, 9, 9, 9, 9)
|
33
|
-
Timecop.freeze(2008, 9, 9, 9, 9, 9) do
|
34
|
-
assert_equal t2, Time.now
|
35
|
-
end
|
36
|
-
assert_equal t, Time.now
|
37
|
-
end
|
38
|
-
assert_nil Time.send(:mock_time)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_exception_thrown_in_freeze_block_properly_resets_time
|
42
|
-
t = Time.local(2008, 10, 10, 10, 10, 10)
|
43
|
-
begin
|
44
|
-
Timecop.freeze(t) do
|
45
|
-
assert_equal t, Time.now
|
46
|
-
raise "blah exception"
|
47
|
-
end
|
48
|
-
rescue
|
49
|
-
assert t != Time.now
|
50
|
-
assert_nil Time.send(:mock_time)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_freeze_freezes_time
|
55
|
-
t = Time.local(2008, 10, 10, 10, 10, 10)
|
56
|
-
now = Time.now
|
57
|
-
Timecop.freeze(t) do
|
58
|
-
sleep(0.25)
|
59
|
-
assert Time.now < now, "If we had failed to freeze, time would have proceeded, which is what appears to have happened."
|
60
|
-
new_t = Time.now
|
61
|
-
assert_equal t, new_t, "Failed to change move time." # 2 seconds
|
62
|
-
assert_equal new_t, Time.now
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_travel_keeps_time_moving
|
67
|
-
t = Time.local(2008, 10, 10, 10, 10, 10)
|
68
|
-
now = Time.now
|
69
|
-
Timecop.travel(t) do
|
70
|
-
new_now = Time.now
|
71
|
-
assert_times_effectively_equal new_now, t, 1, "Looks like we failed to actually travel time" # 0.1 seconds
|
72
|
-
sleep(0.25)
|
73
|
-
assert_times_effectively_not_equal new_now, Time.now, 0.24, "Looks like time is not moving"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_recursive_travel_maintains_each_context
|
78
|
-
t = Time.local(2008, 10, 10, 10, 10, 10)
|
79
|
-
Timecop.travel(2008, 10, 10, 10, 10, 10) do
|
80
|
-
assert((t - Time.now).abs < 50, "Failed to travel time.")
|
81
|
-
t2 = Time.local(2008, 9, 9, 9, 9, 9)
|
82
|
-
Timecop.travel(2008, 9, 9, 9, 9, 9) do
|
83
|
-
assert_times_effectively_equal(t2, Time.now, 1, "Failed to travel time.")
|
84
|
-
assert_times_effectively_not_equal(t, Time.now, 1000, "Failed to travel time.")
|
85
|
-
end
|
86
|
-
assert_times_effectively_equal(t, Time.now, 2, "Failed to restore previously-traveled time.")
|
87
|
-
end
|
88
|
-
assert_nil Time.send(:mock_time)
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_recursive_travel_then_freeze
|
92
|
-
t = Time.local(2008, 10, 10, 10, 10, 10)
|
93
|
-
Timecop.travel(2008, 10, 10, 10, 10, 10) do
|
94
|
-
assert((t - Time.now).abs < 50, "Failed to travel time.")
|
95
|
-
t2 = Time.local(2008, 9, 9, 9, 9, 9)
|
96
|
-
Timecop.freeze(2008, 9, 9, 9, 9, 9) do
|
97
|
-
assert_equal t2, Time.now
|
98
|
-
end
|
99
|
-
assert_times_effectively_equal(t, Time.now, 2, "Failed to restore previously-traveled time.")
|
100
|
-
end
|
101
|
-
assert_nil Time.send(:mock_time)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_recursive_freeze_then_travel
|
105
|
-
t = Time.local(2008, 10, 10, 10, 10, 10)
|
106
|
-
Timecop.freeze(t) do
|
107
|
-
assert_equal t, Time.now
|
108
|
-
t2 = Time.local(2008, 9, 9, 9, 9, 9)
|
109
|
-
Timecop.travel(t2) do
|
110
|
-
assert_times_effectively_equal(t2, Time.now, 1, "Failed to travel time.")
|
111
|
-
assert_times_effectively_not_equal(t, Time.now, 1000, "Failed to travel time.")
|
112
|
-
end
|
113
|
-
assert_equal t, Time.now
|
114
|
-
end
|
115
|
-
assert_nil Time.send(:mock_time)
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|