quantum_leap 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/quantum_leap.rb +10 -0
- data/lib/quantum_leap/version.rb +1 -1
- data/quantum_leap.gemspec +1 -0
- data/spec/quantum_spec.rb +32 -1
- data/spec/spec_helper.rb +1 -0
- metadata +26 -5
data/lib/quantum_leap.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'quantum_leap/version'
|
2
|
+
require 'date'
|
2
3
|
|
3
4
|
module QuantumLeap
|
4
5
|
extend self
|
@@ -18,6 +19,10 @@ module QuantumLeap
|
|
18
19
|
def now
|
19
20
|
Time.really_now - time_travel_offsets.inject(0, :+)
|
20
21
|
end
|
22
|
+
|
23
|
+
def date
|
24
|
+
now.to_date
|
25
|
+
end
|
21
26
|
end
|
22
27
|
|
23
28
|
class << Time
|
@@ -25,6 +30,11 @@ class << Time
|
|
25
30
|
def now; QuantumLeap.now; end
|
26
31
|
end
|
27
32
|
|
33
|
+
class << Date
|
34
|
+
alias_method :really_today, :today
|
35
|
+
def today; QuantumLeap.date; end
|
36
|
+
end
|
37
|
+
|
28
38
|
class Quantum
|
29
39
|
def self.leap(time = Time.now)
|
30
40
|
QuantumLeap.mock_current_time(time)
|
data/lib/quantum_leap/version.rb
CHANGED
data/quantum_leap.gemspec
CHANGED
data/spec/quantum_spec.rb
CHANGED
@@ -17,6 +17,11 @@ describe Quantum do
|
|
17
17
|
Time.now.must_be_within_delta(the_past, 1)
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'changes the current date' do
|
21
|
+
Quantum.leap(the_past)
|
22
|
+
Date.today.must_equal(the_past.to_date)
|
23
|
+
end
|
24
|
+
|
20
25
|
it 'returns the time' do
|
21
26
|
Quantum.leap(the_past).must_be_kind_of(Time)
|
22
27
|
end
|
@@ -33,6 +38,13 @@ describe Quantum do
|
|
33
38
|
Time.now.must_be_within_delta(the_present, 1)
|
34
39
|
end
|
35
40
|
|
41
|
+
it 'changes date only within the block' do
|
42
|
+
Quantum.leap(the_past) do
|
43
|
+
Date.today.must_equal(the_past.to_date)
|
44
|
+
end
|
45
|
+
Date.today.must_equal(the_present.to_date)
|
46
|
+
end
|
47
|
+
|
36
48
|
it 'returns the time' do
|
37
49
|
Quantum.leap(the_past) {}.must_be_kind_of(Time)
|
38
50
|
end
|
@@ -47,6 +59,11 @@ describe Quantum do
|
|
47
59
|
Time.now.must_be_within_delta(the_present, 1)
|
48
60
|
end
|
49
61
|
|
62
|
+
it 'defaults to the current date' do
|
63
|
+
Quantum.leap
|
64
|
+
Date.today.must_equal(the_present.to_date)
|
65
|
+
end
|
66
|
+
|
50
67
|
it 'returns the time' do
|
51
68
|
Quantum.leap.must_be_kind_of(Time)
|
52
69
|
end
|
@@ -55,13 +72,20 @@ describe Quantum do
|
|
55
72
|
describe 'with a block' do
|
56
73
|
the_present = Time.new
|
57
74
|
|
58
|
-
it '
|
75
|
+
it 'does not change time in or outside block' do
|
59
76
|
Quantum.leap do
|
60
77
|
Time.now.must_be_within_delta(the_present, 1)
|
61
78
|
end
|
62
79
|
Time.now.must_be_within_delta(the_present, 1)
|
63
80
|
end
|
64
81
|
|
82
|
+
it 'does not change date in or outside block' do
|
83
|
+
Quantum.leap do
|
84
|
+
Date.today.must_equal(the_present.to_date)
|
85
|
+
end
|
86
|
+
Date.today.must_equal(the_present.to_date)
|
87
|
+
end
|
88
|
+
|
65
89
|
it 'returns the time' do
|
66
90
|
Quantum.leap {}.must_be_kind_of(Time)
|
67
91
|
end
|
@@ -80,6 +104,13 @@ describe Quantum do
|
|
80
104
|
Time.now.must_be_within_delta(the_present, 1)
|
81
105
|
end
|
82
106
|
|
107
|
+
it 'returns to the present date' do
|
108
|
+
Quantum.leap(the_past)
|
109
|
+
Date.today.must_equal(the_past.to_date)
|
110
|
+
Quantum.leap_back
|
111
|
+
Date.today.must_equal(the_present.to_date)
|
112
|
+
end
|
113
|
+
|
83
114
|
it 'returns the time' do
|
84
115
|
Quantum.leap_back.must_be_kind_of(Time)
|
85
116
|
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,28 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: minitest-colorize
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
25
46
|
description: Righting wrongs in your test suite with time travel!
|
26
47
|
email:
|
27
48
|
- mattonrails@shortmail.com
|
@@ -61,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
82
|
version: '0'
|
62
83
|
requirements: []
|
63
84
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.8.
|
85
|
+
rubygems_version: 1.8.23
|
65
86
|
signing_key:
|
66
87
|
specification_version: 3
|
67
88
|
summary: Lets you change the current time in your tests
|