quantum_leap 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,9 +24,18 @@ Or install it yourself as:
24
24
 
25
25
  require 'quantum_leap'
26
26
 
27
- Quantum.leap(Time.now + 60)
27
+ Quantum.leap(Time.new(1956, 9, 13, 15, 00))
28
+ sam.must_be_kind_of(Pilot)
29
+ sam.must_win_baseball_game
28
30
  Quantum.leap_back
29
31
 
32
+ Or with a block:
33
+
34
+ Quantum.leap(Time.new(1974, 10, 24, 15, 00)) do
35
+ sam.must_be_kind_of(Boxer)
36
+ sam.must_win_the_championship
37
+ end
38
+
30
39
  ## Contributing
31
40
 
32
41
  1. Fork it
@@ -1,3 +1,3 @@
1
1
  module QuantumLeap
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/quantum_leap.rb CHANGED
@@ -28,6 +28,12 @@ end
28
28
  class Quantum
29
29
  def self.leap(time)
30
30
  QuantumLeap.mock_current_time(time)
31
+ return unless block_given?
32
+ begin
33
+ yield
34
+ ensure
35
+ QuantumLeap.reset
36
+ end
31
37
  end
32
38
 
33
39
  def self.leap_back
data/spec/quantum_spec.rb CHANGED
@@ -3,18 +3,37 @@ require 'quantum_leap'
3
3
 
4
4
  describe Quantum do
5
5
 
6
+ after do
7
+ Quantum.leap_back
8
+ end
9
+
6
10
  describe '.leap' do
7
- the_past = Time.new(1956, 9, 13, 15, 00)
11
+ describe 'without a block' do
12
+ let(:the_present) { Time.new }
13
+ let(:the_past) { Time.new(1956, 9, 13, 15, 00) }
8
14
 
9
- it 'changes the current time' do
10
- Quantum.leap(the_past)
11
- Time.now.must_be_close_to(the_past)
15
+ it 'changes the current time' do
16
+ Quantum.leap(the_past)
17
+ Time.now.must_be_close_to(the_past)
18
+ end
19
+ end
20
+
21
+ describe 'with a block' do
22
+ let(:the_present) { Time.new }
23
+ let(:the_past) { Time.new(1974, 10, 24, 15, 00) }
24
+
25
+ it 'changes time only within the block' do
26
+ Quantum.leap(the_past) do
27
+ Time.now.must_be_close_to(the_past)
28
+ end
29
+ Time.now.must_be_within_delta(the_present, 1)
30
+ end
12
31
  end
13
32
  end
14
33
 
15
34
  describe '.leap_back' do
16
- the_present = Time.new
17
- the_past = Time.new(1972, 6, 15, 15, 00)
35
+ let(:the_present) { Time.new }
36
+ let(:the_past) { Time.new(1972, 6, 15, 15, 00) }
18
37
 
19
38
  it 'returns to the present time' do
20
39
  Quantum.leap(the_past)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quantum_leap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-30 00:00:00.000000000 Z
12
+ date: 2012-05-31 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Righting wrongs in your test suite with time travel!
15
15
  email: