timecop 0.7.2 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f776ac9891fa370f63fc78ad33aa01866e84a298
4
- data.tar.gz: 5ebcc9bd5855f97e79d4dd62b7694d99b7449783
3
+ metadata.gz: 6e96be7760b99a2b26e5d68800d2980190fe22c2
4
+ data.tar.gz: 9c55cc8abe218ff8dd6035452ffe5e1056d592a4
5
5
  SHA512:
6
- metadata.gz: 5ca661e7b650a72e902e429c473fb338d3756866d453126f4330a541ca2ba3965566e8ed4a30888948eab9b6d58cd2ddda3640ec4284ef58548ed877013882ee
7
- data.tar.gz: 1c678be19de2c126f053908349fb17c1a57ce48f305a0dc079b34257e76f2a9f4d73b83142c0ceecda03288b938f40808095688566058289faa33d1e34d4210e
6
+ metadata.gz: 6f5b765cd3bc5ead77b8947e18d8230f164a1b4655f26ccc73bc7715a70666bf6e623a8567274fda5b375955f30a7bbeb825921fa24c2bb046de9cd8b26df429
7
+ data.tar.gz: 2170ebdcf36371775b6b2abd27faf6ed435ba3d7469c405d8dbda47328622a9375b847de7663e25ff23a6dd8fbddc64012246f4127752a21a143d87458ee0f94
data/README.markdown CHANGED
@@ -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
 
@@ -64,13 +64,14 @@ class Date #:nodoc:
64
64
 
65
65
  alias_method :strptime, :strptime_with_mock_date
66
66
 
67
- def parse_with_mock_date(str)
68
- if WEEKDAYS.keys.include?(str.downcase)
67
+ def parse_with_mock_date(*args)
68
+ str = args.first
69
+ if str && WEEKDAYS.keys.include?(str.downcase)
69
70
  offset = WEEKDAYS[str.downcase] - Date.today.wday
70
71
 
71
72
  Date.today + offset
72
73
  else
73
- parse_without_mock_date(str)
74
+ parse_without_mock_date(*args)
74
75
  end
75
76
  end
76
77
 
@@ -95,15 +96,16 @@ class DateTime #:nodoc:
95
96
 
96
97
  alias_method :now, :now_with_mock_time
97
98
 
98
- def parse_with_mock_date(str)
99
- if Date::WEEKDAYS.keys.include?(str.downcase)
99
+ def parse_with_mock_date(*args)
100
+ str = args.first
101
+ if str && Date::WEEKDAYS.keys.include?(str.downcase)
100
102
  offset = Date::WEEKDAYS[str.downcase] - DateTime.now.wday
101
103
 
102
104
  parsed_weekday =(DateTime.now + offset)
103
105
 
104
106
  DateTime.new(parsed_weekday.year, parsed_weekday.month, parsed_weekday.day, 0, 0, 0, 0)
105
107
  else
106
- parse_without_mock_date(str)
108
+ parse_without_mock_date(*args)
107
109
  end
108
110
  end
109
111
 
@@ -111,6 +111,11 @@ class Timecop
111
111
  @safe_mode ||= false
112
112
  end
113
113
 
114
+ # Returns whether or not Timecop is currently frozen/travelled
115
+ def frozen?
116
+ !instance.instance_variable_get(:@_stack).empty?
117
+ end
118
+
114
119
  private
115
120
  def send_travel(mock_type, *args, &block)
116
121
  val = instance.send(:travel, mock_type, *args, &block)
@@ -1,3 +1,3 @@
1
1
  class Timecop
2
- VERSION = "0.7.2"
2
+ VERSION = "0.8.0"
3
3
  end
data/test/timecop_test.rb CHANGED
@@ -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
@@ -519,6 +519,23 @@ class TestTimecop < Minitest::Unit::TestCase
519
519
  end
520
520
  end
521
521
 
522
+ def test_frozen_after_freeze
523
+ Timecop.freeze
524
+ assert Timecop.frozen?
525
+ end
526
+
527
+ def test_frozen_inside_freeze
528
+ Timecop.freeze do
529
+ assert Timecop.frozen?
530
+ end
531
+ end
532
+
533
+ def test_not_frozen_after_return
534
+ Timecop.freeze
535
+ Timecop.return
536
+ assert !Timecop.frozen?
537
+ end
538
+
522
539
  private
523
540
 
524
541
  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.7.2
4
+ version: 0.8.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: 2015-02-19 00:00:00.000000000 Z
12
+ date: 2015-07-28 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
@@ -27,36 +27,36 @@ files:
27
27
  - lib/timecop.rb
28
28
  - lib/timecop/time_extensions.rb
29
29
  - lib/timecop/time_stack_item.rb
30
- - lib/timecop/timecop.rb
31
30
  - lib/timecop/version.rb
31
+ - lib/timecop/timecop.rb
32
32
  - test/run_tests.sh
33
33
  - test/test_helper.rb
34
34
  - test/time_stack_item_test.rb
35
35
  - test/timecop_test.rb
36
- - test/timecop_without_date_but_with_time_test.rb
37
36
  - test/timecop_without_date_test.rb
37
+ - test/timecop_without_date_but_with_time_test.rb
38
38
  homepage: https://github.com/travisjeffery/timecop
39
39
  licenses:
40
40
  - MIT
41
41
  metadata: {}
42
42
  post_install_message:
43
43
  rdoc_options:
44
- - "--charset=UTF-8"
44
+ - --charset=UTF-8
45
45
  require_paths:
46
46
  - lib
47
47
  required_ruby_version: !ruby/object:Gem::Requirement
48
48
  requirements:
49
- - - ">="
49
+ - - '>='
50
50
  - !ruby/object:Gem::Version
51
51
  version: 1.9.2
52
52
  required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ">="
54
+ - - '>='
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  requirements: []
58
58
  rubyforge_project: timecop
59
- rubygems_version: 2.2.2
59
+ rubygems_version: 2.0.14
60
60
  signing_key:
61
61
  specification_version: 3
62
62
  summary: A gem providing "time travel" and "time freezing" capabilities, making it