delorean 0.2.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +21 -17
- data/lib/delorean.rb +10 -9
- metadata +8 -9
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Luismi Cavallé & Sergio Gil
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@ Delorean lets you travel in time with Ruby by mocking <tt>Time.now</tt>
|
|
4
4
|
|
5
5
|
http://dl.dropbox.com/u/645329/delorean.png
|
6
6
|
|
7
|
-
Marty:: Wait a minute, Doc. Ah... Are you telling me that you built a time machine... out of a DeLorean?
|
7
|
+
Marty:: Wait a minute, Doc. Ah... Are you telling me that you built a time machine... out of a DeLorean?
|
8
8
|
Doc:: The way I see it, if you're gonna build a time machine into a car, why not do it with some style?
|
9
9
|
|
10
10
|
== Install
|
@@ -20,23 +20,23 @@ Let's travel in time!
|
|
20
20
|
# Date.today => Wed Feb 24
|
21
21
|
Delorean.time_travel_to "1 month ago" # Date.today => Sun Jan 24
|
22
22
|
Delorean.back_to_the_present # Date.today => Wed Feb 24
|
23
|
-
|
23
|
+
|
24
24
|
With a block:
|
25
|
-
|
26
|
-
Delorean.time_travel_to("1 month ago") do
|
25
|
+
|
26
|
+
Delorean.time_travel_to("1 month ago") do
|
27
27
|
# Inside the block, Time.now => Sun Jan 24 00:34:32 +0100 2010
|
28
28
|
sleep(5)
|
29
29
|
# And the time still goes by... Time.now => Sun Jan 24 00:34:37 +0100 2010
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# Outside the block, Time.now => Wed Feb 24 00:34:35 +0100 2010
|
33
|
-
|
33
|
+
|
34
34
|
You can also <tt>jump</tt> which is like <tt>sleep</tt> but without losing time
|
35
|
-
|
35
|
+
|
36
36
|
# Time.now => Wed Feb 24 00:34:04 +0100 2010
|
37
37
|
Delorean.jump 30
|
38
38
|
# Time.now => Wed Feb 24 00:34:34 +0100 2010
|
39
|
-
|
39
|
+
|
40
40
|
=== Testing
|
41
41
|
|
42
42
|
Time-travelling can be extremely useful when you're testing your application.
|
@@ -46,28 +46,32 @@ For example, in RSpec you may find convenient to include Delorean's DSL in your
|
|
46
46
|
Spec::Runner.configure do |config|
|
47
47
|
config.include Delorean
|
48
48
|
...
|
49
|
-
|
49
|
+
|
50
50
|
Now you can time-travel in your examples, like this:
|
51
51
|
|
52
52
|
it "should show latest created user" do
|
53
|
-
|
53
|
+
|
54
54
|
time_travel_to(3.minutes.ago) { create_user :name => "John" }
|
55
55
|
time_travel_to(5.minutes.ago) { create_user :name => "Chris" }
|
56
|
-
|
56
|
+
|
57
57
|
get 'show'
|
58
|
-
|
58
|
+
|
59
59
|
response.should have_text("John")
|
60
60
|
response.should_not have_text("Chris")
|
61
|
-
|
61
|
+
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
Don't forget to go back to the present after each example:
|
65
65
|
|
66
66
|
after(:each) { back_to_the_present }
|
67
|
-
|
67
|
+
|
68
|
+
or its alternate syntax:
|
69
|
+
|
70
|
+
after(:each) { back_to_1985 }
|
71
|
+
|
68
72
|
== Credits
|
69
73
|
|
70
74
|
Delorean image based on an original[http://www.gocarlo.com/lagalerie/archives/march05.htm] by {Giancarlo Pitocco}[http://www.gocarlo.com/]
|
71
|
-
|
75
|
+
|
72
76
|
Copyright (c) 2010 Luismi Cavallé, Sergio Gil and BeBanjo S.L. released under the MIT license
|
73
|
-
|
77
|
+
|
data/lib/delorean.rb
CHANGED
@@ -2,7 +2,7 @@ require 'chronic'
|
|
2
2
|
|
3
3
|
module Delorean
|
4
4
|
extend self
|
5
|
-
|
5
|
+
|
6
6
|
def time_travel_to(time, options={})
|
7
7
|
mock_current_time(time, options)
|
8
8
|
return unless block_given?
|
@@ -14,34 +14,35 @@ module Delorean
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def back_to_the_present
|
17
|
-
reset
|
17
|
+
reset
|
18
18
|
end
|
19
|
+
alias :back_to_1985 :back_to_the_present
|
19
20
|
|
20
21
|
def jump(seconds)
|
21
22
|
mock_current_time Time.now + seconds
|
22
23
|
end
|
23
|
-
|
24
|
+
|
24
25
|
def now
|
25
26
|
Time.now_without_delorean - time_travel_offsets.inject(0){ |sum, val| sum + val }
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
private
|
29
|
-
|
30
|
+
|
30
31
|
def time_travel_offsets
|
31
32
|
@@time_travel_offsets ||= []
|
32
33
|
end
|
33
|
-
|
34
|
+
|
34
35
|
def reset
|
35
36
|
@@time_travel_offsets = []
|
36
37
|
end
|
37
|
-
|
38
|
+
|
38
39
|
def mock_current_time(time, options={})
|
39
40
|
time = Chronic.parse(time, options) if time.is_a?(String)
|
40
41
|
time = Time.local(time.year, time.month, time.day) if time.is_a?(Date)
|
41
|
-
|
42
|
+
|
42
43
|
time_travel_offsets.push Time.now - time
|
43
44
|
end
|
44
|
-
|
45
|
+
|
45
46
|
def restore_previous_time
|
46
47
|
time_travel_offsets.pop
|
47
48
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delorean
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
7
|
- 1
|
10
|
-
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Luismi Cavall\xC3\xA9"
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2011-03-01 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -76,15 +76,14 @@ extra_rdoc_files:
|
|
76
76
|
files:
|
77
77
|
- lib/delorean.rb
|
78
78
|
- README.rdoc
|
79
|
+
- MIT-LICENSE
|
79
80
|
has_rdoc: true
|
80
81
|
homepage: http://github.com/bebanjo/delorean
|
81
82
|
licenses: []
|
82
83
|
|
83
84
|
post_install_message:
|
84
|
-
rdoc_options:
|
85
|
-
|
86
|
-
- README.rdoc
|
87
|
-
- --charset=UTF-8
|
85
|
+
rdoc_options: []
|
86
|
+
|
88
87
|
require_paths:
|
89
88
|
- lib
|
90
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|