timecop 0.6.2.2 → 0.6.3

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
2
  SHA1:
3
- metadata.gz: 50d8a097f64ecc69c2fd97409fd484d4ae24ea32
4
- data.tar.gz: 2331d9650b9cbcc142d4dbddf9a93c615bf18e1d
3
+ metadata.gz: 28306a2c78d6588f97b394b65bba1163a9a1cf4a
4
+ data.tar.gz: c2323a791bb954e70a70b9595cb56135e54ff64d
5
5
  SHA512:
6
- metadata.gz: fe7d7dc16fa00728272702b53e7fb8dc9bc1736e43085696a20f3bd381941704d9112639e1c3623278bdf0709986361664777d1efb97a9e34961ff9f14d33dc1
7
- data.tar.gz: e03aec0f8836e109a6d399e3a983757b35a31c701944396ac0a4154d2ba08be333c032af7af42836b6c3746cb3af09cfde30b0899ca0b39d8d3bea04c3b18989
6
+ metadata.gz: 5e445072106712764a97139527912b59ec29cb0e4a97b4a1203dd8c5d72aebea0788935ca56fec863285cb2d764f3312ad604f1d311fa51fcd4ea07a9bd4c8d8
7
+ data.tar.gz: 6f690a4c4d944c7f3df343616bb4e78c707e0efaf8b9c102d71da2a72029bffb0d26dcd64dea856e59183c04cc98d5c0c5d5c7549892338dc823ba3d963968cc
@@ -111,7 +111,25 @@ Time.now
111
111
  # => 2012-09-21 06:22:59 -0500
112
112
  ```
113
113
 
114
- See #42 for more information, thanks to Ken Mayer, David Holcomb, and Pivotal Labs.
114
+ <<<<<<< HEAD
115
+ ### Timecop.safe_mode
116
+
117
+ Safe mode forces you to use Timecop with the block syntax since it always puts time back the way it was. If you are running in safe mode and use Timecop without the block syntax `Timecop::SafeModeException` will be raised to tell the user they are not being safe.
118
+
119
+ ``` ruby
120
+ # turn on safe mode
121
+ Timecop.safe_mode = true
122
+
123
+ # check if you are in safe mode
124
+ Timecop.safe_mode?
125
+ # => true
126
+
127
+ # using method without block
128
+ Timecop.freeze
129
+ # => Timecop::SafeModeException: Safe mode is enabled, only calls passing a block are allowed.
130
+ ```
131
+
132
+ See [#42](https://github.com/travisjeffery/timecop/pull/42) for more information, thanks to Ken Mayer, David Holcomb, and Pivotal Labs.
115
133
 
116
134
  ## Contribute
117
135
 
@@ -129,4 +147,3 @@ Here's the most direct way to get your work merged into the project.
129
147
  - Push the branch up to your fork
130
148
  - Send a pull request for your branch
131
149
 
132
-
@@ -102,6 +102,14 @@ class Timecop
102
102
  instance.instance_variable_get(:@_stack).last
103
103
  end
104
104
 
105
+ def safe_mode=(safe)
106
+ @safe_mode = safe
107
+ end
108
+
109
+ def safe_mode?
110
+ false || @safe_mode
111
+ end
112
+
105
113
  private
106
114
  def send_travel(mock_type, *args, &block)
107
115
  val = instance.send(:travel, mock_type, *args, &block)
@@ -121,6 +129,8 @@ class Timecop
121
129
  end
122
130
 
123
131
  def travel(mock_type, *args, &block) #:nodoc:
132
+ raise SafeModeException if Timecop.safe_mode? && !block_given?
133
+
124
134
  stack_item = TimeStackItem.new(mock_type, *args)
125
135
 
126
136
  stack_backup = @_stack.dup
@@ -156,4 +166,10 @@ class Timecop
156
166
  unmock!
157
167
  end
158
168
  end
169
+
170
+ class SafeModeException < StandardError
171
+ def initialize
172
+ super "Safe mode is enabled, only calls passing a block are allowed."
173
+ end
174
+ end
159
175
  end
@@ -1,3 +1,3 @@
1
1
  class Timecop
2
- VERSION = "0.6.2.2"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -459,4 +459,37 @@ class TestTimecop < Test::Unit::TestCase
459
459
  end
460
460
  end
461
461
 
462
+ def test_raises_when_safe_mode_and_no_block
463
+ with_safe_mode do
464
+ assert_raise Timecop::SafeModeException do
465
+ Timecop.freeze
466
+ end
467
+ end
468
+ end
469
+
470
+ def test_no_raise_when_safe_mode_and_block_used
471
+ with_safe_mode do
472
+ assert_nothing_raised do
473
+ Timecop.freeze {}
474
+ end
475
+ end
476
+ end
477
+
478
+ def test_no_raise_when_not_safe_mode_and_no_block
479
+ with_safe_mode(false) do
480
+ assert_nothing_raised do
481
+ Timecop.freeze
482
+ end
483
+ end
484
+ end
485
+
486
+ private
487
+
488
+ def with_safe_mode(enabled=true)
489
+ mode = Timecop.safe_mode?
490
+ Timecop.safe_mode = enabled
491
+ yield
492
+ ensure
493
+ Timecop.safe_mode = mode
494
+ end
462
495
  end
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.6.2.2
4
+ version: 0.6.3
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: 2013-07-20 00:00:00.000000000 Z
12
+ date: 2013-08-04 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