timecop 0.9.2 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/timecop/time_extensions.rb +13 -1
- data/lib/timecop/timecop.rb +1 -1
- data/lib/timecop/version.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/timecop_test.rb +11 -33
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
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
|
@@ -22,6 +22,8 @@ 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
|
@@ -56,8 +58,18 @@ class Date #:nodoc:
|
|
56
58
|
Date.new(year, mon, d[:mday])
|
57
59
|
elsif d[:wday]
|
58
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
|
59
71
|
else
|
60
|
-
Date.new(year, mon
|
72
|
+
Date.new(year, mon)
|
61
73
|
end
|
62
74
|
end
|
63
75
|
|
data/lib/timecop/timecop.rb
CHANGED
data/lib/timecop/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
data/test/timecop_test.rb
CHANGED
@@ -533,38 +533,6 @@ class TestTimecop < Minitest::Test
|
|
533
533
|
end
|
534
534
|
end
|
535
535
|
|
536
|
-
def test_date_strptime_without_year
|
537
|
-
Timecop.freeze(Time.new(1984,2,28)) do
|
538
|
-
assert_equal Date.strptime('04-14', '%m-%d'), Date.new(1984, 4, 14)
|
539
|
-
end
|
540
|
-
end
|
541
|
-
|
542
|
-
def test_date_strptime_without_specifying_format
|
543
|
-
Timecop.freeze(Time.new(1984,2,28)) do
|
544
|
-
assert_equal Date.strptime('1999-04-14'), Date.new(1999, 4, 14)
|
545
|
-
end
|
546
|
-
end
|
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
536
|
def test_frozen_after_freeze
|
569
537
|
Timecop.freeze
|
570
538
|
assert Timecop.frozen?
|
@@ -582,7 +550,7 @@ class TestTimecop < Minitest::Test
|
|
582
550
|
assert !Timecop.frozen?
|
583
551
|
end
|
584
552
|
|
585
|
-
def
|
553
|
+
def test_thread_safe_timecop_in_parallel
|
586
554
|
Timecop.thread_safe = true
|
587
555
|
date = Time.local(2011, 01, 02)
|
588
556
|
thread = Thread.new do
|
@@ -599,6 +567,16 @@ class TestTimecop < Minitest::Test
|
|
599
567
|
Timecop.thread_safe = false
|
600
568
|
end
|
601
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
|
+
|
602
580
|
private
|
603
581
|
|
604
582
|
def with_safe_mode(enabled=true)
|
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.9.
|
4
|
+
version: 0.9.4
|
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: 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
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
|
-
rubygems_version: 3.
|
57
|
+
rubygems_version: 3.0.8
|
58
58
|
signing_key:
|
59
59
|
specification_version: 3
|
60
60
|
summary: A gem providing "time travel" and "time freezing" capabilities, making it
|