timecop 0.8.1 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/README.markdown +8 -2
- data/lib/timecop/time_extensions.rb +62 -27
- data/lib/timecop/time_stack_item.rb +10 -7
- data/lib/timecop/timecop.rb +77 -19
- data/lib/timecop/version.rb +1 -1
- data/test/test_helper.rb +7 -2
- data/test/time_stack_item_test.rb +12 -2
- data/test/timecop_test.rb +51 -10
- data/test/timecop_without_date_test.rb +1 -1
- metadata +6 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9e107de03899173505259909d8ec9e008082d8fa4cf551a2326a6bc98890285e
|
4
|
+
data.tar.gz: e50a9c462cafa4feb5a1b47fc720f853c1a7ac62bd5d404ecad3f2b749be0ef4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 427b83dd2d0506193c3c4d947cb1281817a531a64f09f73f004d97c17339665311774e775bc7506e4447ed2c66636e0df2cd954447e079409aef347262ab3e30
|
7
|
+
data.tar.gz: 631df874968afa111e81b255d665972085ec64a6c315b424304148a75c3226eb7e0f259ed7d149c6829950394f340b4cd595fa21720149104b2c4c8e2448b586
|
data/LICENSE
CHANGED
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# timecop
|
2
2
|
|
3
|
-
[![Build Status](https://secure.travis-ci.org/travisjeffery/timecop.
|
3
|
+
[![Build Status](https://secure.travis-ci.org/travisjeffery/timecop.svg)](http://travis-ci.org/travisjeffery/timecop)
|
4
4
|
|
5
5
|
## DESCRIPTION
|
6
6
|
|
@@ -104,7 +104,7 @@ being able to simulate activity via subsequent calls to your application.
|
|
104
104
|
Timecop.scale(3600)
|
105
105
|
Time.now
|
106
106
|
# => 2012-09-20 21:23:25 -0500
|
107
|
-
# seconds later, hours have
|
107
|
+
# seconds later, hours have passed and it's gone from 9pm at night to 6am in the morning
|
108
108
|
Time.now
|
109
109
|
# => 2012-09-21 06:22:59 -0500
|
110
110
|
```
|
@@ -128,6 +128,12 @@ Timecop.freeze
|
|
128
128
|
# => Timecop::SafeModeException: Safe mode is enabled, only calls passing a block are allowed.
|
129
129
|
```
|
130
130
|
|
131
|
+
### Rails v Ruby Date/Time libraries
|
132
|
+
|
133
|
+
Sometimes [Rails Date/Time methods don't play nicely with Ruby Date/Time methods.](https://rails.lighthouseapp.com/projects/8994/tickets/6410-dateyesterday-datetoday)
|
134
|
+
|
135
|
+
Be careful mixing Ruby `Date.today` with Rails `Date.tomorrow` / `Date.yesterday` as things might break.
|
136
|
+
|
131
137
|
## Contribute
|
132
138
|
|
133
139
|
timecop is maintained by [travisjeffery](http://github.com/travisjeffery), and
|
@@ -22,24 +22,15 @@ class Time #:nodoc:
|
|
22
22
|
args.size <= 0 ? now : new_without_mock_time(*args)
|
23
23
|
end
|
24
24
|
|
25
|
+
ruby2_keywords :new_with_mock_time if Module.private_method_defined?(:ruby2_keywords)
|
26
|
+
|
25
27
|
alias_method :new, :new_with_mock_time
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
31
|
class Date #:nodoc:
|
30
|
-
WEEKDAYS = {
|
31
|
-
"sunday" => 0,
|
32
|
-
"monday" => 1,
|
33
|
-
"tuesday" => 2,
|
34
|
-
"wednesday" => 3,
|
35
|
-
"thursday" => 4,
|
36
|
-
"friday" => 5,
|
37
|
-
"saturday" => 6
|
38
|
-
}
|
39
|
-
|
40
32
|
class << self
|
41
33
|
def mock_date
|
42
|
-
mocked_time_stack_item = Timecop.top_stack_item
|
43
34
|
mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.date(self)
|
44
35
|
end
|
45
36
|
|
@@ -59,32 +50,67 @@ class Date #:nodoc:
|
|
59
50
|
"supports Date::ITALY for the start argument."
|
60
51
|
end
|
61
52
|
|
62
|
-
|
53
|
+
d = Date._strptime(str, fmt) || Date.strptime_without_mock_date(str, fmt)
|
54
|
+
now = Time.now.to_date
|
55
|
+
year = d[:year] || now.year
|
56
|
+
mon = d[:mon] || now.mon
|
57
|
+
if d[:mday]
|
58
|
+
Date.new(year, mon, d[:mday])
|
59
|
+
elsif d[:wday]
|
60
|
+
Date.new(year, mon, now.mday) + (d[:wday] - now.wday)
|
61
|
+
elsif d[:yday]
|
62
|
+
Date.new(year).next_day(d[:yday] - 1)
|
63
|
+
elsif d[:cwyear] && d[:cweek]
|
64
|
+
if d[:cwday]
|
65
|
+
Date.commercial(d[:cwyear], d[:cweek], d[:cwday])
|
66
|
+
else
|
67
|
+
Date.commercial(d[:cwyear], d[:cweek])
|
68
|
+
end
|
69
|
+
elsif d[:seconds]
|
70
|
+
Time.at(d[:seconds]).to_date
|
71
|
+
else
|
72
|
+
Date.new(year, mon)
|
73
|
+
end
|
63
74
|
end
|
64
75
|
|
65
76
|
alias_method :strptime, :strptime_with_mock_date
|
66
77
|
|
67
78
|
def parse_with_mock_date(*args)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
79
|
+
parsed_date = parse_without_mock_date(*args)
|
80
|
+
return parsed_date unless mocked_time_stack_item
|
81
|
+
date_hash = Date._parse(*args)
|
82
|
+
|
83
|
+
case
|
84
|
+
when date_hash[:year] && date_hash[:mon]
|
85
|
+
parsed_date
|
86
|
+
when date_hash[:mon] && date_hash[:mday]
|
87
|
+
Date.new(mocked_time_stack_item.year, date_hash[:mon], date_hash[:mday])
|
88
|
+
when date_hash[:wday]
|
89
|
+
closest_wday(date_hash[:wday])
|
73
90
|
else
|
74
|
-
|
91
|
+
parsed_date + mocked_time_stack_item.travel_offset_days
|
75
92
|
end
|
76
93
|
end
|
77
94
|
|
78
95
|
alias_method :parse_without_mock_date, :parse
|
79
96
|
alias_method :parse, :parse_with_mock_date
|
80
97
|
|
98
|
+
def mocked_time_stack_item
|
99
|
+
Timecop.top_stack_item
|
100
|
+
end
|
101
|
+
|
102
|
+
def closest_wday(wday)
|
103
|
+
today = Date.today
|
104
|
+
result = today - today.wday
|
105
|
+
result += 1 until wday == result.wday
|
106
|
+
result
|
107
|
+
end
|
81
108
|
end
|
82
109
|
end
|
83
110
|
|
84
111
|
class DateTime #:nodoc:
|
85
112
|
class << self
|
86
113
|
def mock_time
|
87
|
-
mocked_time_stack_item = Timecop.top_stack_item
|
88
114
|
mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.datetime(self)
|
89
115
|
end
|
90
116
|
|
@@ -97,19 +123,28 @@ class DateTime #:nodoc:
|
|
97
123
|
alias_method :now, :now_with_mock_time
|
98
124
|
|
99
125
|
def parse_with_mock_date(*args)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
126
|
+
date_hash = Date._parse(*args)
|
127
|
+
parsed_date = parse_without_mock_date(*args)
|
128
|
+
return parsed_date unless mocked_time_stack_item
|
129
|
+
date_hash = DateTime._parse(*args)
|
130
|
+
|
131
|
+
case
|
132
|
+
when date_hash[:year] && date_hash[:mon]
|
133
|
+
parsed_date
|
134
|
+
when date_hash[:mon] && date_hash[:mday]
|
135
|
+
DateTime.new(mocked_time_stack_item.year, date_hash[:mon], date_hash[:mday])
|
136
|
+
when date_hash[:wday]
|
137
|
+
Date.closest_wday(date_hash[:wday]).to_datetime
|
107
138
|
else
|
108
|
-
|
139
|
+
parsed_date + mocked_time_stack_item.travel_offset_days
|
109
140
|
end
|
110
141
|
end
|
111
142
|
|
112
143
|
alias_method :parse_without_mock_date, :parse
|
113
144
|
alias_method :parse, :parse_with_mock_date
|
145
|
+
|
146
|
+
def mocked_time_stack_item
|
147
|
+
Timecop.top_stack_item
|
148
|
+
end
|
114
149
|
end
|
115
150
|
end
|
@@ -43,7 +43,11 @@ class Timecop
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def travel_offset
|
46
|
-
@travel_offset
|
46
|
+
@travel_offset unless mock_type == :freeze
|
47
|
+
end
|
48
|
+
|
49
|
+
def travel_offset_days
|
50
|
+
(@travel_offset / 60 / 60 / 24).round
|
47
51
|
end
|
48
52
|
|
49
53
|
def scaling_factor
|
@@ -52,7 +56,7 @@ class Timecop
|
|
52
56
|
|
53
57
|
def time(time_klass = Time) #:nodoc:
|
54
58
|
if @time.respond_to?(:in_time_zone)
|
55
|
-
time = time_klass.at(@time.dup.
|
59
|
+
time = time_klass.at(@time.dup.localtime)
|
56
60
|
else
|
57
61
|
time = time_klass.at(@time)
|
58
62
|
end
|
@@ -60,7 +64,7 @@ class Timecop
|
|
60
64
|
if travel_offset.nil?
|
61
65
|
time
|
62
66
|
elsif scaling_factor.nil?
|
63
|
-
time_klass.at(
|
67
|
+
time_klass.at(Time.now_without_mock_time + travel_offset)
|
64
68
|
else
|
65
69
|
time_klass.at(scaled_time)
|
66
70
|
end
|
@@ -102,12 +106,12 @@ class Timecop
|
|
102
106
|
elsif Object.const_defined?(:Date) && arg.is_a?(Date)
|
103
107
|
time_klass.local(arg.year, arg.month, arg.day, 0, 0, 0)
|
104
108
|
elsif args.empty? && (arg.kind_of?(Integer) || arg.kind_of?(Float))
|
105
|
-
|
109
|
+
time_klass.now + arg
|
106
110
|
elsif arg.nil?
|
107
|
-
|
111
|
+
time_klass.now
|
108
112
|
else
|
109
113
|
if arg.is_a?(String) && Time.respond_to?(:parse)
|
110
|
-
|
114
|
+
time_klass.parse(arg)
|
111
115
|
else
|
112
116
|
# we'll just assume it's a list of y/m/d/h/m/s
|
113
117
|
year = arg || 2000
|
@@ -122,7 +126,6 @@ class Timecop
|
|
122
126
|
end
|
123
127
|
|
124
128
|
def compute_travel_offset
|
125
|
-
return nil if mock_type == :freeze
|
126
129
|
time - Time.now_without_mock_time
|
127
130
|
end
|
128
131
|
|
data/lib/timecop/timecop.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'singleton'
|
2
|
-
require File.join(File.dirname(__FILE__), "time_extensions")
|
3
2
|
require File.join(File.dirname(__FILE__), "time_stack_item")
|
4
3
|
|
5
4
|
# Timecop
|
@@ -93,6 +92,7 @@ class Timecop
|
|
93
92
|
nil
|
94
93
|
end
|
95
94
|
end
|
95
|
+
alias :unfreeze :return
|
96
96
|
|
97
97
|
def return_to_baseline
|
98
98
|
instance.send(:return_to_baseline)
|
@@ -100,7 +100,7 @@ class Timecop
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def top_stack_item #:nodoc:
|
103
|
-
instance.
|
103
|
+
instance.send(:stack).last
|
104
104
|
end
|
105
105
|
|
106
106
|
def safe_mode=(safe)
|
@@ -111,9 +111,17 @@ class Timecop
|
|
111
111
|
@safe_mode ||= false
|
112
112
|
end
|
113
113
|
|
114
|
+
def thread_safe=(t)
|
115
|
+
instance.send(:thread_safe=, t)
|
116
|
+
end
|
117
|
+
|
118
|
+
def thread_safe
|
119
|
+
instance.send(:thread_safe)
|
120
|
+
end
|
121
|
+
|
114
122
|
# Returns whether or not Timecop is currently frozen/travelled
|
115
123
|
def frozen?
|
116
|
-
!instance.
|
124
|
+
!instance.send(:stack).empty?
|
117
125
|
end
|
118
126
|
|
119
127
|
private
|
@@ -125,50 +133,97 @@ class Timecop
|
|
125
133
|
|
126
134
|
private
|
127
135
|
|
128
|
-
def baseline=(
|
129
|
-
|
130
|
-
|
136
|
+
def baseline=(b)
|
137
|
+
set_baseline(b)
|
138
|
+
stack << TimeStackItem.new(:travel, b)
|
139
|
+
end
|
140
|
+
|
141
|
+
def baseline
|
142
|
+
if @thread_safe
|
143
|
+
Thread.current[:timecop_baseline]
|
144
|
+
else
|
145
|
+
@baseline
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def set_baseline(b)
|
150
|
+
if @thread_safe
|
151
|
+
Thread.current[:timecop_baseline] = b
|
152
|
+
else
|
153
|
+
@baseline = b
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def stack
|
158
|
+
if @thread_safe
|
159
|
+
Thread.current[:timecop_stack] ||= []
|
160
|
+
Thread.current[:timecop_stack]
|
161
|
+
else
|
162
|
+
@stack
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def set_stack(s)
|
167
|
+
if @thread_safe
|
168
|
+
Thread.current[:timecop_stack] = s
|
169
|
+
else
|
170
|
+
@stack = s
|
171
|
+
end
|
131
172
|
end
|
132
173
|
|
133
174
|
def initialize #:nodoc:
|
134
|
-
@
|
175
|
+
@stack = []
|
176
|
+
@safe = nil
|
177
|
+
@thread_safe = false
|
178
|
+
end
|
179
|
+
|
180
|
+
def thread_safe=(t)
|
181
|
+
initialize
|
182
|
+
@thread_safe = t
|
183
|
+
end
|
184
|
+
|
185
|
+
def thread_safe
|
186
|
+
@thread_safe
|
135
187
|
end
|
136
188
|
|
137
189
|
def travel(mock_type, *args, &block) #:nodoc:
|
138
|
-
raise SafeModeException if Timecop.safe_mode? && !block_given?
|
190
|
+
raise SafeModeException if Timecop.safe_mode? && !block_given? && !@safe
|
139
191
|
|
140
192
|
stack_item = TimeStackItem.new(mock_type, *args)
|
141
193
|
|
142
|
-
stack_backup =
|
143
|
-
|
194
|
+
stack_backup = stack.dup
|
195
|
+
stack << stack_item
|
144
196
|
|
145
197
|
if block_given?
|
198
|
+
safe_backup = @safe
|
199
|
+
@safe = true
|
146
200
|
begin
|
147
201
|
yield stack_item.time
|
148
202
|
ensure
|
149
|
-
|
203
|
+
stack.replace stack_backup
|
204
|
+
@safe = safe_backup
|
150
205
|
end
|
151
206
|
end
|
152
207
|
end
|
153
208
|
|
154
209
|
def return(&block)
|
155
|
-
current_stack =
|
156
|
-
current_baseline =
|
210
|
+
current_stack = stack
|
211
|
+
current_baseline = baseline
|
157
212
|
unmock!
|
158
213
|
yield
|
159
214
|
ensure
|
160
|
-
|
161
|
-
|
215
|
+
set_stack current_stack
|
216
|
+
set_baseline current_baseline
|
162
217
|
end
|
163
218
|
|
164
219
|
def unmock! #:nodoc:
|
165
|
-
|
166
|
-
|
220
|
+
set_baseline nil
|
221
|
+
set_stack []
|
167
222
|
end
|
168
223
|
|
169
224
|
def return_to_baseline
|
170
|
-
if
|
171
|
-
|
225
|
+
if baseline
|
226
|
+
set_stack [stack.shift]
|
172
227
|
else
|
173
228
|
unmock!
|
174
229
|
end
|
@@ -180,3 +235,6 @@ class Timecop
|
|
180
235
|
end
|
181
236
|
end
|
182
237
|
end
|
238
|
+
|
239
|
+
# This must be done after TimeCop is available
|
240
|
+
require File.join(File.dirname(__FILE__), "time_extensions")
|
data/lib/timecop/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
require 'minitest/autorun'
|
3
3
|
require 'minitest/rg'
|
4
|
+
require 'pry'
|
4
5
|
|
5
6
|
$VERBOSE = true # enable ruby warnings
|
6
7
|
|
7
|
-
require 'mocha/
|
8
|
+
require 'mocha/minitest'
|
8
9
|
|
9
10
|
class Minitest::Test
|
10
11
|
private
|
@@ -28,7 +29,7 @@ class Minitest::Test
|
|
28
29
|
Time.at(time.to_i).to_datetime.offset
|
29
30
|
end
|
30
31
|
|
31
|
-
TIMEZONES = ["Europe/Paris", "UTC", "America/Chicago"]
|
32
|
+
TIMEZONES = ["Pacific/Midway", "Europe/Paris", "UTC", "America/Chicago"]
|
32
33
|
|
33
34
|
def each_timezone
|
34
35
|
old_tz = ENV["TZ"]
|
@@ -51,4 +52,8 @@ class Minitest::Test
|
|
51
52
|
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
53
|
end
|
53
54
|
|
55
|
+
def jruby?
|
56
|
+
RUBY_PLATFORM == "java"
|
57
|
+
end
|
58
|
+
|
54
59
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'date'
|
2
2
|
require_relative "test_helper"
|
3
3
|
require 'timecop'
|
4
|
+
|
4
5
|
require 'active_support/all'
|
5
6
|
|
6
7
|
class TestTimeStackItem < Minitest::Test
|
@@ -180,7 +181,7 @@ class TestTimeStackItem < Minitest::Test
|
|
180
181
|
t = Time.local(2009, 10, 1, 0, 0, 30)
|
181
182
|
tsi = Timecop::TimeStackItem.new(:freeze, t)
|
182
183
|
|
183
|
-
|
184
|
+
assert_nil tsi.send(:travel_offset)
|
184
185
|
end
|
185
186
|
|
186
187
|
def test_timezones
|
@@ -191,12 +192,21 @@ class TestTimeStackItem < Minitest::Test
|
|
191
192
|
end
|
192
193
|
end
|
193
194
|
|
195
|
+
def test_timezones_with_parsed_string
|
196
|
+
Time.zone = "Europe/Zurich"
|
197
|
+
time_string = "2012-12-27 12:12"
|
198
|
+
expected_time = Time.zone.parse(time_string)
|
199
|
+
Timecop.freeze(time_string) do |frozen_time|
|
200
|
+
assert_equal expected_time, frozen_time
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
194
204
|
def test_timezones_apply_dates
|
195
205
|
Time.zone = "Central Time (US & Canada)"
|
196
206
|
time = Time.zone.local(2013,1,3)
|
197
207
|
|
198
208
|
Timecop.freeze(time) do
|
199
|
-
assert_equal time.to_date, Time.now.to_date
|
209
|
+
assert_equal time.to_date, Time.zone.now.to_date
|
200
210
|
end
|
201
211
|
end
|
202
212
|
|
data/test/timecop_test.rb
CHANGED
@@ -37,6 +37,12 @@ class TestTimecop < Minitest::Test
|
|
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
|
@@ -251,7 +257,7 @@ class TestTimecop < Minitest::Test
|
|
251
257
|
new_now = Time.now
|
252
258
|
assert_times_effectively_equal(new_now, t, 1, "Looks like we failed to actually travel time")
|
253
259
|
sleep(0.25)
|
254
|
-
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"
|
255
261
|
end
|
256
262
|
end
|
257
263
|
|
@@ -495,6 +501,18 @@ class TestTimecop < Minitest::Test
|
|
495
501
|
end
|
496
502
|
end
|
497
503
|
|
504
|
+
def test_raises_when_safe_mode_and_no_block_though_previously_block_given
|
505
|
+
Timecop.freeze do
|
506
|
+
Timecop.freeze
|
507
|
+
end
|
508
|
+
|
509
|
+
with_safe_mode do
|
510
|
+
assert_raises Timecop::SafeModeException do
|
511
|
+
Timecop.freeze
|
512
|
+
end
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
498
516
|
def test_no_raise_when_safe_mode_and_block_used
|
499
517
|
with_safe_mode do
|
500
518
|
Timecop.freeze {}
|
@@ -507,15 +525,11 @@ class TestTimecop < Minitest::Test
|
|
507
525
|
end
|
508
526
|
end
|
509
527
|
|
510
|
-
def
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
def test_date_strptime_without_specifying_format
|
517
|
-
Timecop.freeze(Time.new(1984,2,28)) do
|
518
|
-
assert_equal Date.strptime('1999-04-14'), Date.new(1999, 4, 14)
|
528
|
+
def test_no_raise_when_safe_mode_and_no_block_and_in_block_context
|
529
|
+
with_safe_mode do
|
530
|
+
Timecop.freeze do
|
531
|
+
Timecop.freeze
|
532
|
+
end
|
519
533
|
end
|
520
534
|
end
|
521
535
|
|
@@ -536,6 +550,33 @@ class TestTimecop < Minitest::Test
|
|
536
550
|
assert !Timecop.frozen?
|
537
551
|
end
|
538
552
|
|
553
|
+
def test_thread_safe_timecop_in_parallel
|
554
|
+
Timecop.thread_safe = true
|
555
|
+
date = Time.local(2011, 01, 02)
|
556
|
+
thread = Thread.new do
|
557
|
+
Timecop.freeze(date) do
|
558
|
+
sleep 1 #give main thread time to run
|
559
|
+
assert_equal date, Time.now
|
560
|
+
end
|
561
|
+
end
|
562
|
+
|
563
|
+
sleep 0.25
|
564
|
+
assert Time.now != date
|
565
|
+
thread.join
|
566
|
+
ensure
|
567
|
+
Timecop.thread_safe = false
|
568
|
+
end
|
569
|
+
|
570
|
+
def test_thread_safe_timecop_returns_after_block
|
571
|
+
Timecop.thread_safe = true
|
572
|
+
date = Time.local(2017, 10, 8)
|
573
|
+
|
574
|
+
Timecop.freeze(date) { }
|
575
|
+
assert Time.now != date
|
576
|
+
ensure
|
577
|
+
Timecop.thread_safe = false
|
578
|
+
end
|
579
|
+
|
539
580
|
private
|
540
581
|
|
541
582
|
def with_safe_mode(enabled=true)
|
@@ -70,7 +70,7 @@ class TestTimecopWithoutDate < Minitest::Test
|
|
70
70
|
new_now = Time.now
|
71
71
|
assert_times_effectively_equal new_now, t, 1, "Looks like we failed to actually travel time" # 0.1 seconds
|
72
72
|
sleep(0.25)
|
73
|
-
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"
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timecop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Jeffery
|
8
8
|
- John Trupiano
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A gem providing "time travel" and "time freezing" capabilities, making
|
15
15
|
it dead simple to test time-dependent code. It provides a unified method to mock
|
@@ -38,7 +38,7 @@ homepage: https://github.com/travisjeffery/timecop
|
|
38
38
|
licenses:
|
39
39
|
- MIT
|
40
40
|
metadata: {}
|
41
|
-
post_install_message:
|
41
|
+
post_install_message:
|
42
42
|
rdoc_options:
|
43
43
|
- "--charset=UTF-8"
|
44
44
|
require_paths:
|
@@ -54,9 +54,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
|
-
|
58
|
-
|
59
|
-
signing_key:
|
57
|
+
rubygems_version: 3.0.8
|
58
|
+
signing_key:
|
60
59
|
specification_version: 3
|
61
60
|
summary: A gem providing "time travel" and "time freezing" capabilities, making it
|
62
61
|
dead simple to test time-dependent code. It provides a unified method to mock Time.now,
|
@@ -67,4 +66,3 @@ test_files:
|
|
67
66
|
- test/timecop_test.rb
|
68
67
|
- test/timecop_without_date_test.rb
|
69
68
|
- test/timecop_without_date_but_with_time_test.rb
|
70
|
-
has_rdoc:
|