timecop 0.7.4 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 20cb6846c9eed771ecb4652d95a568e0fe53066a
4
- data.tar.gz: 887873c54cc4dc84fc1b01c0da708289d67e8c76
2
+ SHA256:
3
+ metadata.gz: 8e1bf57b28c2d86304d5ca7192fb44fab26457ea631ebe45d1361b4e8ad165e5
4
+ data.tar.gz: cbd98da4611a74dda4c377a89b25a9e66be575fde9278663a36386857f0b80db
5
5
  SHA512:
6
- metadata.gz: bde686bc5c574e8901c82ce9b66cd45649b03da6a55fedb6cab3dc71a730d0f42bcf23f1da70a410222f8fe2cfc39c23f4ce72bd8a535dce3f3b7bb3feb8a0b7
7
- data.tar.gz: 78fef5abf78c22bec175382563eb4fc3d92d87fbb107de4d1a24ece25c85b40bcb52d1dad7d174b59a15493abf128af0ac53e9cab820f4f4abfd26d540fa43bc
6
+ metadata.gz: 5f3d6796ee0f520b1bcc6dfc3cd7251f8a9ae32b6079e29b7564418f9250da70bd3d39042c311d17e7f1507ff2a6522ece4a4160d6bb8170db820b6b60c9493d
7
+ data.tar.gz: bc5600d477a487a23892ffed0a57511aa66dfb188b8b6600ff82194afe8b38921ed869fc184f15584be18f7b1f8a68bebe15b9f96ee0628bd2bde60302cb4fc5
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2012 — Travis Jeffery, John Trupiano
3
+ Copyright (c) 2019 — Travis Jeffery, John Trupiano
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -1,6 +1,6 @@
1
1
  # timecop
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/travisjeffery/timecop.png)](http://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 past it's gone from 9pm at night to 6am in the morning
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
- system "cd test && ./run_tests.sh" or fail
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
 
@@ -59,32 +48,57 @@ class Date #:nodoc:
59
48
  "supports Date::ITALY for the start argument."
60
49
  end
61
50
 
62
- Time.strptime(str, fmt).to_date
51
+ d = Date._strptime(str, fmt) || Date.strptime_without_mock_date(str, fmt)
52
+ now = Time.now.to_date
53
+ year = d[:year] || now.year
54
+ mon = d[:mon] || now.mon
55
+ if d[:mday]
56
+ Date.new(year, mon, d[:mday])
57
+ elsif d[:wday]
58
+ Date.new(year, mon, now.mday) + (d[:wday] - now.wday)
59
+ else
60
+ Date.new(year, mon, now.mday)
61
+ end
63
62
  end
64
63
 
65
64
  alias_method :strptime, :strptime_with_mock_date
66
65
 
67
66
  def parse_with_mock_date(*args)
68
- str = args.first
69
- if str && WEEKDAYS.keys.include?(str.downcase)
70
- offset = WEEKDAYS[str.downcase] - Date.today.wday
71
-
72
- Date.today + offset
67
+ parsed_date = parse_without_mock_date(*args)
68
+ return parsed_date unless mocked_time_stack_item
69
+ date_hash = Date._parse(*args)
70
+
71
+ case
72
+ when date_hash[:year] && date_hash[:mon]
73
+ parsed_date
74
+ when date_hash[:mon] && date_hash[:mday]
75
+ Date.new(mocked_time_stack_item.year, date_hash[:mon], date_hash[:mday])
76
+ when date_hash[:wday]
77
+ closest_wday(date_hash[:wday])
73
78
  else
74
- parse_without_mock_date(*args)
79
+ parsed_date + mocked_time_stack_item.travel_offset_days
75
80
  end
76
81
  end
77
82
 
78
83
  alias_method :parse_without_mock_date, :parse
79
84
  alias_method :parse, :parse_with_mock_date
80
85
 
86
+ def mocked_time_stack_item
87
+ Timecop.top_stack_item
88
+ end
89
+
90
+ def closest_wday(wday)
91
+ today = Date.today
92
+ result = today - today.wday
93
+ result += 1 until wday == result.wday
94
+ result
95
+ end
81
96
  end
82
97
  end
83
98
 
84
99
  class DateTime #:nodoc:
85
100
  class << self
86
101
  def mock_time
87
- mocked_time_stack_item = Timecop.top_stack_item
88
102
  mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.datetime(self)
89
103
  end
90
104
 
@@ -97,19 +111,28 @@ class DateTime #:nodoc:
97
111
  alias_method :now, :now_with_mock_time
98
112
 
99
113
  def parse_with_mock_date(*args)
100
- str = args.first
101
- if str && Date::WEEKDAYS.keys.include?(str.downcase)
102
- offset = Date::WEEKDAYS[str.downcase] - DateTime.now.wday
103
-
104
- parsed_weekday =(DateTime.now + offset)
105
-
106
- DateTime.new(parsed_weekday.year, parsed_weekday.month, parsed_weekday.day, 0, 0, 0, 0)
114
+ date_hash = Date._parse(*args)
115
+ parsed_date = parse_without_mock_date(*args)
116
+ return parsed_date unless mocked_time_stack_item
117
+ date_hash = DateTime._parse(*args)
118
+
119
+ case
120
+ when date_hash[:year] && date_hash[:mon]
121
+ parsed_date
122
+ when date_hash[:mon] && date_hash[:mday]
123
+ DateTime.new(mocked_time_stack_item.year, date_hash[:mon], date_hash[:mday])
124
+ when date_hash[:wday]
125
+ Date.closest_wday(date_hash[:wday]).to_datetime
107
126
  else
108
- parse_without_mock_date(*args)
127
+ parsed_date + mocked_time_stack_item.travel_offset_days
109
128
  end
110
129
  end
111
130
 
112
131
  alias_method :parse_without_mock_date, :parse
113
132
  alias_method :parse, :parse_with_mock_date
133
+
134
+ def mocked_time_stack_item
135
+ Timecop.top_stack_item
136
+ end
114
137
  end
115
138
  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.utc.to_r)
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((Time.now_without_mock_time + travel_offset).to_f)
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
- Time.now + arg
108
+ elsif args.empty? && (arg.kind_of?(Integer) || arg.kind_of?(Float))
109
+ time_klass.now + arg
106
110
  elsif arg.nil?
107
- Time.now
111
+ time_klass.now
108
112
  else
109
113
  if arg.is_a?(String) && Time.respond_to?(:parse)
110
- Time.parse(arg)
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
 
@@ -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.instance_variable_get(:@_stack).last
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=(baseline)
124
- @baseline = baseline
125
- @_stack << TimeStackItem.new(:travel, baseline)
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
- @_stack = []
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 = @_stack.dup
138
- @_stack << stack_item
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
- @_stack.replace stack_backup
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 = @_stack
151
- current_baseline = @baseline
210
+ current_stack = stack
211
+ current_baseline = baseline
152
212
  unmock!
153
213
  yield
154
214
  ensure
155
- @_stack = current_stack
156
- @baseline = current_baseline
215
+ set_stack current_stack
216
+ set_baseline current_baseline
157
217
  end
158
218
 
159
219
  def unmock! #:nodoc:
160
- @baseline = nil
161
- @_stack = []
220
+ set_baseline nil
221
+ set_stack []
162
222
  end
163
223
 
164
224
  def return_to_baseline
165
- if @baseline
166
- @_stack = [@_stack.shift]
225
+ if baseline
226
+ set_stack [stack.shift]
167
227
  else
168
228
  unmock!
169
229
  end
@@ -175,3 +235,6 @@ class Timecop
175
235
  end
176
236
  end
177
237
  end
238
+
239
+ # This must be done after TimeCop is available
240
+ require File.join(File.dirname(__FILE__), "time_extensions")
@@ -1,3 +1,3 @@
1
1
  class Timecop
2
- VERSION = "0.7.4"
2
+ VERSION = "0.9.2"
3
3
  end
@@ -1,16 +1,13 @@
1
- require 'rubygems'
2
1
  require 'bundler/setup'
3
2
  require 'minitest/autorun'
3
+ require 'minitest/rg'
4
+ require 'pry'
4
5
 
5
6
  $VERBOSE = true # enable ruby warnings
6
7
 
7
- begin
8
- require 'mocha/setup'
9
- rescue LoadError
10
- require 'mocha'
11
- end
8
+ require 'mocha/minitest'
12
9
 
13
- class Minitest::Unit::TestCase
10
+ class Minitest::Test
14
11
  private
15
12
  # Tests to see that two times are within the given distance,
16
13
  # in seconds, from each other.
@@ -55,4 +52,8 @@ class Minitest::Unit::TestCase
55
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}"
56
53
  end
57
54
 
55
+ def jruby?
56
+ RUBY_PLATFORM == "java"
57
+ end
58
+
58
59
  end
@@ -1,10 +1,10 @@
1
1
  require 'date'
2
- require File.join(File.dirname(__FILE__), "test_helper")
3
- require File.join(File.dirname(__FILE__), '..', 'lib', 'timecop')
2
+ require_relative "test_helper"
3
+ require 'timecop'
4
4
 
5
5
  require 'active_support/all'
6
6
 
7
- class TestTimeStackItem < Minitest::Unit::TestCase
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)
@@ -168,7 +181,7 @@ class TestTimeStackItem < Minitest::Unit::TestCase
168
181
  t = Time.local(2009, 10, 1, 0, 0, 30)
169
182
  tsi = Timecop::TimeStackItem.new(:freeze, t)
170
183
 
171
- assert_equal nil, tsi.send(:travel_offset)
184
+ assert_nil tsi.send(:travel_offset)
172
185
  end
173
186
 
174
187
  def test_timezones
@@ -179,12 +192,21 @@ 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)
185
207
 
186
208
  Timecop.freeze(time) do
187
- assert_equal time.to_date, Time.now.to_date
209
+ assert_equal time.to_date, Time.zone.now.to_date
188
210
  end
189
211
  end
190
212
 
@@ -1,7 +1,7 @@
1
- require File.join(File.dirname(__FILE__), "test_helper")
2
- require File.join(File.dirname(__FILE__), '..', 'lib', 'timecop')
1
+ require_relative "test_helper"
2
+ require 'timecop'
3
3
 
4
- class TestTimecop < Minitest::Unit::TestCase
4
+ class TestTimecop < Minitest::Test
5
5
  def teardown
6
6
  Timecop.return
7
7
  end
@@ -37,6 +37,12 @@ class TestTimecop < Minitest::Unit::TestCase
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::Unit::TestCase
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.25, "Looks like time is not moving"
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
 
@@ -293,7 +299,7 @@ class TestTimecop < Minitest::Unit::TestCase
293
299
  end
294
300
  end
295
301
  end
296
-
302
+
297
303
  def test_freeze_without_arguments_instance_works_as_expected
298
304
  t = Time.local(2008, 10, 10, 10, 10, 10)
299
305
  Timecop.freeze(t) do
@@ -495,6 +501,18 @@ class TestTimecop < Minitest::Unit::TestCase
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,6 +525,14 @@ class TestTimecop < Minitest::Unit::TestCase
507
525
  end
508
526
  end
509
527
 
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
533
+ end
534
+ end
535
+
510
536
  def test_date_strptime_without_year
511
537
  Timecop.freeze(Time.new(1984,2,28)) do
512
538
  assert_equal Date.strptime('04-14', '%m-%d'), Date.new(1984, 4, 14)
@@ -519,6 +545,60 @@ class TestTimecop < Minitest::Unit::TestCase
519
545
  end
520
546
  end
521
547
 
548
+ def test_date_strptime_with_day_of_week
549
+ Timecop.freeze(Time.new(1984,2,28)) do
550
+ assert_equal Date.strptime('Thursday', '%A'), Date.new(1984, 3, 1)
551
+ assert_equal Date.strptime('Monday', '%A'), Date.new(1984, 2, 27)
552
+ end
553
+ end
554
+
555
+ def test_date_strptime_with_invalid_date
556
+ begin
557
+ Date.strptime('', '%Y-%m-%d')
558
+ rescue ArgumentError => e
559
+ assert_equal 'invalid date', e.message
560
+ end
561
+ end
562
+
563
+ def test_ancient_strptime
564
+ ancient = Date.strptime('11-01-08', '%Y-%m-%d').strftime
565
+ assert_equal '0011-01-08', ancient # Failed before fix to strptime_with_mock_date
566
+ end
567
+
568
+ def test_frozen_after_freeze
569
+ Timecop.freeze
570
+ assert Timecop.frozen?
571
+ end
572
+
573
+ def test_frozen_inside_freeze
574
+ Timecop.freeze do
575
+ assert Timecop.frozen?
576
+ end
577
+ end
578
+
579
+ def test_not_frozen_after_return
580
+ Timecop.freeze
581
+ Timecop.return
582
+ assert !Timecop.frozen?
583
+ end
584
+
585
+ def test_thread_safe_timecop
586
+ Timecop.thread_safe = true
587
+ date = Time.local(2011, 01, 02)
588
+ thread = Thread.new do
589
+ Timecop.freeze(date) do
590
+ sleep 1 #give main thread time to run
591
+ assert_equal date, Time.now
592
+ end
593
+ end
594
+
595
+ sleep 0.25
596
+ assert Time.now != date
597
+ thread.join
598
+ ensure
599
+ Timecop.thread_safe = false
600
+ end
601
+
522
602
  private
523
603
 
524
604
  def with_safe_mode(enabled=true)
@@ -1,10 +1,8 @@
1
- require File.join(File.dirname(__FILE__), "test_helper")
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 "time"
8
- require TIMECOP_LIB
6
+ require 'timecop'
9
7
  end
10
8
  end
@@ -1,7 +1,7 @@
1
- require File.join(File.dirname(__FILE__), "test_helper")
2
- require File.join(File.dirname(__FILE__), '..', 'lib', 'timecop')
1
+ require_relative "test_helper"
2
+ require 'timecop'
3
3
 
4
- class TestTimecopWithoutDate < Minitest::Unit::TestCase
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.25, "Looks like time is not moving"
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.7.4
4
+ version: 0.9.2
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: 2015-05-31 00:00:00.000000000 Z
12
+ date: 2020-10-14 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
@@ -39,7 +38,7 @@ homepage: https://github.com/travisjeffery/timecop
39
38
  licenses:
40
39
  - MIT
41
40
  metadata: {}
42
- post_install_message:
41
+ post_install_message:
43
42
  rdoc_options:
44
43
  - "--charset=UTF-8"
45
44
  require_paths:
@@ -55,9 +54,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
54
  - !ruby/object:Gem::Version
56
55
  version: '0'
57
56
  requirements: []
58
- rubyforge_project: timecop
59
- rubygems_version: 2.2.2
60
- signing_key:
57
+ rubygems_version: 3.1.4
58
+ signing_key:
61
59
  specification_version: 3
62
60
  summary: A gem providing "time travel" and "time freezing" capabilities, making it
63
61
  dead simple to test time-dependent code. It provides a unified method to mock Time.now,
@@ -1,10 +0,0 @@
1
- #!/bin/sh
2
-
3
- FAILEDCASES=0
4
- for f in *_test.rb; do
5
- if ! ${RUBY:-ruby} -I../lib:. $f; then
6
- FAILEDCASES=`expr "$FAILEDCASES" + 1`
7
- fi
8
- done
9
- echo "$FAILEDCASES test cases had failures"
10
- exit $FAILEDCASES