timecop 0.7.4 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +10 -3
- data/Rakefile +9 -3
- data/lib/timecop/time_extensions.rb +39 -26
- data/lib/timecop/time_stack_item.rb +11 -8
- data/lib/timecop/timecop.rb +77 -17
- data/lib/timecop/version.rb +1 -1
- data/test/test_helper.rb +7 -7
- data/test/time_stack_item_test.rb +25 -3
- data/test/timecop_test.rb +59 -5
- data/test/timecop_without_date_but_with_time_test.rb +4 -6
- data/test/timecop_without_date_test.rb +4 -4
- metadata +4 -4
- data/test/run_tests.sh +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 580525a47a6026f3d83689807d96949dd5269fa5
|
4
|
+
data.tar.gz: ffb9cc8cf58489f231f3348656f99597b3c79989
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc3c024856bf2bbaab09a0734aa1d87712e26c8b1e47774edf2d65153ceb22ae6bbe3b04499a4f12c68acf5f9352fb26e614c8c4996c80e14353f75049899598
|
7
|
+
data.tar.gz: c759c9cc704c61d2bd1cf13b4d44a6ad8a1b36a03fc398b4796f1dd1bc0d055a6ddda86aa0a31addc753eb6accc57049648d3fd5334477ccb0cc8cbc594076b7
|
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
|
|
@@ -51,7 +51,8 @@ describe "some set of tests to mock" do
|
|
51
51
|
Timecop.return
|
52
52
|
end
|
53
53
|
|
54
|
-
it "should do blah blah blah"
|
54
|
+
it "should do blah blah blah" do
|
55
|
+
end
|
55
56
|
end
|
56
57
|
```
|
57
58
|
|
@@ -103,7 +104,7 @@ being able to simulate activity via subsequent calls to your application.
|
|
103
104
|
Timecop.scale(3600)
|
104
105
|
Time.now
|
105
106
|
# => 2012-09-20 21:23:25 -0500
|
106
|
-
# seconds later, hours have
|
107
|
+
# seconds later, hours have passed and it's gone from 9pm at night to 6am in the morning
|
107
108
|
Time.now
|
108
109
|
# => 2012-09-21 06:22:59 -0500
|
109
110
|
```
|
@@ -127,6 +128,12 @@ Timecop.freeze
|
|
127
128
|
# => Timecop::SafeModeException: Safe mode is enabled, only calls passing a block are allowed.
|
128
129
|
```
|
129
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
|
+
|
130
137
|
## Contribute
|
131
138
|
|
132
139
|
timecop is maintained by [travisjeffery](http://github.com/travisjeffery), and
|
data/Rakefile
CHANGED
@@ -3,8 +3,6 @@ require 'bundler/gem_tasks'
|
|
3
3
|
require 'rake/testtask'
|
4
4
|
require 'rdoc/task'
|
5
5
|
|
6
|
-
$LOAD_PATH.unshift("lib")
|
7
|
-
|
8
6
|
Rake::RDocTask.new do |rdoc|
|
9
7
|
if File.exist?('VERSION')
|
10
8
|
version = File.read('VERSION')
|
@@ -21,7 +19,15 @@ Rake::RDocTask.new do |rdoc|
|
|
21
19
|
end
|
22
20
|
|
23
21
|
task :test do
|
24
|
-
|
22
|
+
failed = Dir["test/*_test.rb"].map do |test|
|
23
|
+
command = "ruby #{test}"
|
24
|
+
puts
|
25
|
+
puts command
|
26
|
+
command unless system(command)
|
27
|
+
end.compact
|
28
|
+
if failed.any?
|
29
|
+
abort "#{failed.count} Tests failed\n#{failed.join("\n")}"
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
desc 'Default: run tests'
|
@@ -27,19 +27,8 @@ class Time #:nodoc:
|
|
27
27
|
end
|
28
28
|
|
29
29
|
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
30
|
class << self
|
41
31
|
def mock_date
|
42
|
-
mocked_time_stack_item = Timecop.top_stack_item
|
43
32
|
mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.date(self)
|
44
33
|
end
|
45
34
|
|
@@ -65,26 +54,41 @@ class Date #:nodoc:
|
|
65
54
|
alias_method :strptime, :strptime_with_mock_date
|
66
55
|
|
67
56
|
def parse_with_mock_date(*args)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
57
|
+
parsed_date = parse_without_mock_date(*args)
|
58
|
+
return parsed_date unless mocked_time_stack_item
|
59
|
+
date_hash = Date._parse(*args)
|
60
|
+
|
61
|
+
case
|
62
|
+
when date_hash[:year] && date_hash[:mon] && date_hash[:mday]
|
63
|
+
parsed_date
|
64
|
+
when date_hash[:mon] && date_hash[:mday]
|
65
|
+
Date.new(mocked_time_stack_item.year, date_hash[:mon], date_hash[:mday])
|
66
|
+
when date_hash[:wday]
|
67
|
+
closest_wday(date_hash[:wday])
|
73
68
|
else
|
74
|
-
|
69
|
+
parsed_date + mocked_time_stack_item.travel_offset_days
|
75
70
|
end
|
76
71
|
end
|
77
72
|
|
78
73
|
alias_method :parse_without_mock_date, :parse
|
79
74
|
alias_method :parse, :parse_with_mock_date
|
80
75
|
|
76
|
+
def mocked_time_stack_item
|
77
|
+
Timecop.top_stack_item
|
78
|
+
end
|
79
|
+
|
80
|
+
def closest_wday(wday)
|
81
|
+
today = Date.today
|
82
|
+
result = today - today.wday
|
83
|
+
result += 1 until wday == result.wday
|
84
|
+
result
|
85
|
+
end
|
81
86
|
end
|
82
87
|
end
|
83
88
|
|
84
89
|
class DateTime #:nodoc:
|
85
90
|
class << self
|
86
91
|
def mock_time
|
87
|
-
mocked_time_stack_item = Timecop.top_stack_item
|
88
92
|
mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.datetime(self)
|
89
93
|
end
|
90
94
|
|
@@ -97,19 +101,28 @@ class DateTime #:nodoc:
|
|
97
101
|
alias_method :now, :now_with_mock_time
|
98
102
|
|
99
103
|
def parse_with_mock_date(*args)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
date_hash = Date._parse(*args)
|
105
|
+
parsed_date = parse_without_mock_date(*args)
|
106
|
+
return parsed_date unless mocked_time_stack_item
|
107
|
+
date_hash = DateTime._parse(*args)
|
108
|
+
|
109
|
+
case
|
110
|
+
when date_hash[:year] && date_hash[:mon] && date_hash[:mday]
|
111
|
+
parsed_date
|
112
|
+
when date_hash[:mon] && date_hash[:mday]
|
113
|
+
DateTime.new(mocked_time_stack_item.year, date_hash[:mon], date_hash[:mday])
|
114
|
+
when date_hash[:wday]
|
115
|
+
Date.closest_wday(date_hash[:wday]).to_datetime
|
107
116
|
else
|
108
|
-
|
117
|
+
parsed_date + mocked_time_stack_item.travel_offset_days
|
109
118
|
end
|
110
119
|
end
|
111
120
|
|
112
121
|
alias_method :parse_without_mock_date, :parse
|
113
122
|
alias_method :parse, :parse_with_mock_date
|
123
|
+
|
124
|
+
def mocked_time_stack_item
|
125
|
+
Timecop.top_stack_item
|
126
|
+
end
|
114
127
|
end
|
115
128
|
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
|
@@ -101,13 +105,13 @@ class Timecop
|
|
101
105
|
time_klass.at(arg.to_time.to_f).getlocal
|
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
|
-
elsif args.empty? && arg.kind_of?(Integer)
|
105
|
-
|
108
|
+
elsif args.empty? && (arg.kind_of?(Integer) || arg.kind_of?(Float))
|
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
@@ -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,6 +111,19 @@ 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
|
+
|
122
|
+
# Returns whether or not Timecop is currently frozen/travelled
|
123
|
+
def frozen?
|
124
|
+
!instance.send(:stack).empty?
|
125
|
+
end
|
126
|
+
|
114
127
|
private
|
115
128
|
def send_travel(mock_type, *args, &block)
|
116
129
|
val = instance.send(:travel, mock_type, *args, &block)
|
@@ -120,50 +133,97 @@ class Timecop
|
|
120
133
|
|
121
134
|
private
|
122
135
|
|
123
|
-
def baseline=(
|
124
|
-
|
125
|
-
|
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
|
126
172
|
end
|
127
173
|
|
128
174
|
def initialize #:nodoc:
|
129
|
-
@
|
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
|
130
187
|
end
|
131
188
|
|
132
189
|
def travel(mock_type, *args, &block) #:nodoc:
|
133
|
-
raise SafeModeException if Timecop.safe_mode? && !block_given?
|
190
|
+
raise SafeModeException if Timecop.safe_mode? && !block_given? && !@safe
|
134
191
|
|
135
192
|
stack_item = TimeStackItem.new(mock_type, *args)
|
136
193
|
|
137
|
-
stack_backup =
|
138
|
-
|
194
|
+
stack_backup = stack.dup
|
195
|
+
stack << stack_item
|
139
196
|
|
140
197
|
if block_given?
|
198
|
+
safe_backup = @safe
|
199
|
+
@safe = true
|
141
200
|
begin
|
142
201
|
yield stack_item.time
|
143
202
|
ensure
|
144
|
-
@
|
203
|
+
@stack.replace stack_backup
|
204
|
+
@safe = safe_backup
|
145
205
|
end
|
146
206
|
end
|
147
207
|
end
|
148
208
|
|
149
209
|
def return(&block)
|
150
|
-
current_stack =
|
151
|
-
current_baseline =
|
210
|
+
current_stack = stack
|
211
|
+
current_baseline = baseline
|
152
212
|
unmock!
|
153
213
|
yield
|
154
214
|
ensure
|
155
|
-
|
156
|
-
|
215
|
+
set_stack current_stack
|
216
|
+
set_baseline current_baseline
|
157
217
|
end
|
158
218
|
|
159
219
|
def unmock! #:nodoc:
|
160
|
-
|
161
|
-
|
220
|
+
set_baseline nil
|
221
|
+
set_stack []
|
162
222
|
end
|
163
223
|
|
164
224
|
def return_to_baseline
|
165
|
-
if
|
166
|
-
|
225
|
+
if baseline
|
226
|
+
set_stack [stack.shift]
|
167
227
|
else
|
168
228
|
unmock!
|
169
229
|
end
|
data/lib/timecop/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'bundler/setup'
|
3
2
|
require 'minitest/autorun'
|
3
|
+
require 'minitest/rg'
|
4
4
|
|
5
5
|
$VERBOSE = true # enable ruby warnings
|
6
6
|
|
7
|
-
|
8
|
-
require 'mocha/setup'
|
9
|
-
rescue LoadError
|
10
|
-
require 'mocha'
|
11
|
-
end
|
7
|
+
require 'mocha/setup'
|
12
8
|
|
13
|
-
class Minitest::
|
9
|
+
class Minitest::Test
|
14
10
|
private
|
15
11
|
# Tests to see that two times are within the given distance,
|
16
12
|
# in seconds, from each other.
|
@@ -55,4 +51,8 @@ class Minitest::Unit::TestCase
|
|
55
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}"
|
56
52
|
end
|
57
53
|
|
54
|
+
def jruby?
|
55
|
+
RUBY_PLATFORM == "java"
|
56
|
+
end
|
57
|
+
|
58
58
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'date'
|
2
|
-
|
3
|
-
require
|
2
|
+
require_relative "test_helper"
|
3
|
+
require 'timecop'
|
4
4
|
|
5
5
|
require 'active_support/all'
|
6
6
|
|
7
|
-
class TestTimeStackItem < Minitest::
|
7
|
+
class TestTimeStackItem < Minitest::Test
|
8
8
|
def teardown
|
9
9
|
Timecop.return
|
10
10
|
Time.zone = nil
|
@@ -87,6 +87,19 @@ class TestTimeStackItem < Minitest::Unit::TestCase
|
|
87
87
|
assert_equal s, stack_item.sec
|
88
88
|
end
|
89
89
|
|
90
|
+
def test_new_with_float
|
91
|
+
t = Time.now
|
92
|
+
y, m, d, h, min, s = t.year, t.month, t.day, t.hour, t.min, t.sec
|
93
|
+
stack_item = Timecop::TimeStackItem.new(:freeze, 0.0)
|
94
|
+
|
95
|
+
assert_equal y, stack_item.year
|
96
|
+
assert_equal m, stack_item.month
|
97
|
+
assert_equal d, stack_item.day
|
98
|
+
assert_equal h, stack_item.hour
|
99
|
+
assert_equal min, stack_item.min
|
100
|
+
assert_equal s, stack_item.sec
|
101
|
+
end
|
102
|
+
|
90
103
|
def test_new_with_individual_arguments
|
91
104
|
y, m, d, h, min, s = 2008, 10, 10, 10, 10, 10
|
92
105
|
stack_item = Timecop::TimeStackItem.new(:freeze, y, m, d, h, min, s)
|
@@ -179,6 +192,15 @@ class TestTimeStackItem < Minitest::Unit::TestCase
|
|
179
192
|
end
|
180
193
|
end
|
181
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
|
+
|
182
204
|
def test_timezones_apply_dates
|
183
205
|
Time.zone = "Central Time (US & Canada)"
|
184
206
|
time = Time.zone.local(2013,1,3)
|
data/test/timecop_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
require_relative "test_helper"
|
2
|
+
require 'timecop'
|
3
3
|
|
4
|
-
class TestTimecop < Minitest::
|
4
|
+
class TestTimecop < Minitest::Test
|
5
5
|
def teardown
|
6
6
|
Timecop.return
|
7
7
|
end
|
@@ -251,7 +251,7 @@ class TestTimecop < Minitest::Unit::TestCase
|
|
251
251
|
new_now = Time.now
|
252
252
|
assert_times_effectively_equal(new_now, t, 1, "Looks like we failed to actually travel time")
|
253
253
|
sleep(0.25)
|
254
|
-
assert_times_effectively_not_equal new_now, Time.now, 0.
|
254
|
+
assert_times_effectively_not_equal new_now, Time.now, 0.24, "Looks like time is not moving"
|
255
255
|
end
|
256
256
|
end
|
257
257
|
|
@@ -293,7 +293,7 @@ class TestTimecop < Minitest::Unit::TestCase
|
|
293
293
|
end
|
294
294
|
end
|
295
295
|
end
|
296
|
-
|
296
|
+
|
297
297
|
def test_freeze_without_arguments_instance_works_as_expected
|
298
298
|
t = Time.local(2008, 10, 10, 10, 10, 10)
|
299
299
|
Timecop.freeze(t) do
|
@@ -495,6 +495,18 @@ class TestTimecop < Minitest::Unit::TestCase
|
|
495
495
|
end
|
496
496
|
end
|
497
497
|
|
498
|
+
def test_raises_when_safe_mode_and_no_block_though_previously_block_given
|
499
|
+
Timecop.freeze do
|
500
|
+
Timecop.freeze
|
501
|
+
end
|
502
|
+
|
503
|
+
with_safe_mode do
|
504
|
+
assert_raises Timecop::SafeModeException do
|
505
|
+
Timecop.freeze
|
506
|
+
end
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
498
510
|
def test_no_raise_when_safe_mode_and_block_used
|
499
511
|
with_safe_mode do
|
500
512
|
Timecop.freeze {}
|
@@ -507,6 +519,14 @@ class TestTimecop < Minitest::Unit::TestCase
|
|
507
519
|
end
|
508
520
|
end
|
509
521
|
|
522
|
+
def test_no_raise_when_safe_mode_and_no_block_and_in_block_context
|
523
|
+
with_safe_mode do
|
524
|
+
Timecop.freeze do
|
525
|
+
Timecop.freeze
|
526
|
+
end
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
510
530
|
def test_date_strptime_without_year
|
511
531
|
Timecop.freeze(Time.new(1984,2,28)) do
|
512
532
|
assert_equal Date.strptime('04-14', '%m-%d'), Date.new(1984, 4, 14)
|
@@ -519,6 +539,40 @@ class TestTimecop < Minitest::Unit::TestCase
|
|
519
539
|
end
|
520
540
|
end
|
521
541
|
|
542
|
+
def test_frozen_after_freeze
|
543
|
+
Timecop.freeze
|
544
|
+
assert Timecop.frozen?
|
545
|
+
end
|
546
|
+
|
547
|
+
def test_frozen_inside_freeze
|
548
|
+
Timecop.freeze do
|
549
|
+
assert Timecop.frozen?
|
550
|
+
end
|
551
|
+
end
|
552
|
+
|
553
|
+
def test_not_frozen_after_return
|
554
|
+
Timecop.freeze
|
555
|
+
Timecop.return
|
556
|
+
assert !Timecop.frozen?
|
557
|
+
end
|
558
|
+
|
559
|
+
def test_thread_safe_timecop
|
560
|
+
Timecop.thread_safe = true
|
561
|
+
date = Time.local(2011, 01, 02)
|
562
|
+
thread = Thread.new do
|
563
|
+
Timecop.freeze(date) do
|
564
|
+
sleep 1 #give main thread time to run
|
565
|
+
assert_equal date, Time.now
|
566
|
+
end
|
567
|
+
end
|
568
|
+
|
569
|
+
sleep 0.25
|
570
|
+
assert Time.now != date
|
571
|
+
thread.join
|
572
|
+
ensure
|
573
|
+
Timecop.thread_safe = false
|
574
|
+
end
|
575
|
+
|
522
576
|
private
|
523
577
|
|
524
578
|
def with_safe_mode(enabled=true)
|
@@ -1,10 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class TestTimecopWithoutDateButWithTime < Minitest::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
|
-
require
|
8
|
-
require TIMECOP_LIB
|
6
|
+
require 'timecop'
|
9
7
|
end
|
10
8
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
require_relative "test_helper"
|
2
|
+
require 'timecop'
|
3
3
|
|
4
|
-
class TestTimecopWithoutDate < Minitest::
|
4
|
+
class TestTimecopWithoutDate < Minitest::Test
|
5
5
|
|
6
6
|
def setup
|
7
7
|
Object.send(:remove_const, :Date) if Object.const_defined?(:Date)
|
@@ -70,7 +70,7 @@ class TestTimecopWithoutDate < Minitest::Unit::TestCase
|
|
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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timecop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Jeffery
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-06-22 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
|
@@ -29,7 +29,6 @@ files:
|
|
29
29
|
- lib/timecop/time_stack_item.rb
|
30
30
|
- lib/timecop/timecop.rb
|
31
31
|
- lib/timecop/version.rb
|
32
|
-
- test/run_tests.sh
|
33
32
|
- test/test_helper.rb
|
34
33
|
- test/time_stack_item_test.rb
|
35
34
|
- test/timecop_test.rb
|
@@ -56,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
55
|
version: '0'
|
57
56
|
requirements: []
|
58
57
|
rubyforge_project: timecop
|
59
|
-
rubygems_version: 2.
|
58
|
+
rubygems_version: 2.4.5
|
60
59
|
signing_key:
|
61
60
|
specification_version: 3
|
62
61
|
summary: A gem providing "time travel" and "time freezing" capabilities, making it
|
@@ -68,3 +67,4 @@ test_files:
|
|
68
67
|
- test/timecop_test.rb
|
69
68
|
- test/timecop_without_date_test.rb
|
70
69
|
- test/timecop_without_date_but_with_time_test.rb
|
70
|
+
has_rdoc:
|