timecop 0.9.1 → 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: 73784bb387b1ff9addf9f0ea04a14e28d679a577
4
- data.tar.gz: 18fbfbd85ceae5b1a23111267b7b39287911b080
2
+ SHA256:
3
+ metadata.gz: 8e1bf57b28c2d86304d5ca7192fb44fab26457ea631ebe45d1361b4e8ad165e5
4
+ data.tar.gz: cbd98da4611a74dda4c377a89b25a9e66be575fde9278663a36386857f0b80db
5
5
  SHA512:
6
- metadata.gz: 39552bdc1d0278558f91802906da230656323690b3a4663c6c054e2f8ad379df9f593e65265faa6d0ee6769423b0d73d3ab3a1e16c8ac0ee80896cd88e5661ba
7
- data.tar.gz: 669823d9cd754f2fa5ec195012aa43f43a070e61e3be41dda3ada13eceaffa06733cb6302bbdf88b0764da28d6a3860d74d4505ba3fa4a75be88ef96c03d0ad1
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
@@ -48,7 +48,17 @@ class Date #:nodoc:
48
48
  "supports Date::ITALY for the start argument."
49
49
  end
50
50
 
51
- 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
52
62
  end
53
63
 
54
64
  alias_method :strptime, :strptime_with_mock_date
@@ -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)
@@ -235,3 +235,6 @@ class Timecop
235
235
  end
236
236
  end
237
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.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
@@ -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/setup'
8
+ require 'mocha/minitest'
8
9
 
9
10
  class Minitest::Test
10
11
  private
@@ -181,7 +181,7 @@ class TestTimeStackItem < Minitest::Test
181
181
  t = Time.local(2009, 10, 1, 0, 0, 30)
182
182
  tsi = Timecop::TimeStackItem.new(:freeze, t)
183
183
 
184
- assert_equal nil, tsi.send(:travel_offset)
184
+ assert_nil tsi.send(:travel_offset)
185
185
  end
186
186
 
187
187
  def test_timezones
@@ -206,7 +206,7 @@ class TestTimeStackItem < Minitest::Test
206
206
  time = Time.zone.local(2013,1,3)
207
207
 
208
208
  Timecop.freeze(time) do
209
- assert_equal time.to_date, Time.now.to_date
209
+ assert_equal time.to_date, Time.zone.now.to_date
210
210
  end
211
211
  end
212
212
 
@@ -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
@@ -539,6 +545,26 @@ class TestTimecop < Minitest::Test
539
545
  end
540
546
  end
541
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
+
542
568
  def test_frozen_after_freeze
543
569
  Timecop.freeze
544
570
  assert Timecop.frozen?
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.9.1
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: 2017-07-05 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
@@ -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
- rubyforge_project: timecop
58
- rubygems_version: 2.4.5
59
- signing_key:
57
+ rubygems_version: 3.1.4
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: