delorean 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +80 -0
- data/lib/delorean.rb +11 -0
- metadata +6 -6
- data/README.rdoc +0 -77
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Delorean [![Build Status](https://secure.travis-ci.org/bebanjo/delorean.png)](http://travis-ci.org/bebanjo/delorean)
|
2
|
+
|
3
|
+
Delorean lets you travel in time with Ruby by mocking `Time.now`
|
4
|
+
|
5
|
+
![](http://dl.dropbox.com/u/645329/delorean.png)
|
6
|
+
|
7
|
+
> Marty:: Wait a minute, Doc. Ah... Are you telling me that you built a time machine... out of a DeLorean?
|
8
|
+
>
|
9
|
+
> Doc:: The way I see it, if you're gonna build a time machine into a car, why not do it with some style?
|
10
|
+
|
11
|
+
## Install
|
12
|
+
|
13
|
+
$ [sudo] gem install delorean
|
14
|
+
|
15
|
+
Or add it to your `Gemfile`, etc.
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Let's travel in time!
|
20
|
+
|
21
|
+
require 'delorean'
|
22
|
+
|
23
|
+
# Date.today => Wed Feb 24
|
24
|
+
Delorean.time_travel_to "1 month ago" # Date.today => Sun Jan 24
|
25
|
+
Delorean.back_to_the_present # Date.today => Wed Feb 24
|
26
|
+
|
27
|
+
With a block:
|
28
|
+
|
29
|
+
Delorean.time_travel_to("1 month ago") do
|
30
|
+
# Inside the block, Time.now => Sun Jan 24 00:34:32 +0100 2010
|
31
|
+
sleep(5)
|
32
|
+
# And the time still goes by... Time.now => Sun Jan 24 00:34:37 +0100 2010
|
33
|
+
end
|
34
|
+
|
35
|
+
# Outside the block, Time.now => Wed Feb 24 00:34:35 +0100 2010
|
36
|
+
|
37
|
+
You can also `jump` which is like `sleep` but without losing time
|
38
|
+
|
39
|
+
# Time.now => Wed Feb 24 00:34:04 +0100 2010
|
40
|
+
Delorean.jump 30
|
41
|
+
# Time.now => Wed Feb 24 00:34:34 +0100 2010
|
42
|
+
|
43
|
+
## Testing
|
44
|
+
|
45
|
+
Time-travelling can be extremely useful when you're testing your application.
|
46
|
+
|
47
|
+
For example, in RSpec you may find convenient to include Delorean's DSL in your `spec_helper.rb`:
|
48
|
+
|
49
|
+
Spec::Runner.configure do |config|
|
50
|
+
config.include Delorean
|
51
|
+
...
|
52
|
+
|
53
|
+
Now you can time-travel in your examples, like this:
|
54
|
+
|
55
|
+
it "should show latest created user" do
|
56
|
+
|
57
|
+
time_travel_to(3.minutes.ago) { create_user :name => "John" }
|
58
|
+
time_travel_to(5.minutes.ago) { create_user :name => "Chris" }
|
59
|
+
|
60
|
+
get 'show'
|
61
|
+
|
62
|
+
response.should have_text("John")
|
63
|
+
response.should_not have_text("Chris")
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
Don't forget to go back to the present after each example:
|
68
|
+
|
69
|
+
after(:each) { back_to_the_present }
|
70
|
+
|
71
|
+
or its alternate syntax:
|
72
|
+
|
73
|
+
after(:each) { back_to_1985 }
|
74
|
+
|
75
|
+
## Credits
|
76
|
+
|
77
|
+
Delorean image based on [an original](http://www.gocarlo.com/lagalerie/archives/march05.htm) by [Giancarlo Pitocco](http://www.gocarlo.com/).
|
78
|
+
|
79
|
+
Copyright (c) 2010-2011 Luismi Cavallé, Sergio Gil and BeBanjo S.L. released under the MIT license
|
80
|
+
|
data/lib/delorean.rb
CHANGED
@@ -58,3 +58,14 @@ class << Time
|
|
58
58
|
alias_method :now_without_delorean, :now
|
59
59
|
def now; Delorean.now; end
|
60
60
|
end
|
61
|
+
|
62
|
+
if RUBY_VERSION >= "1.9.3"
|
63
|
+
class << Date
|
64
|
+
alias_method :today_without_delorean, :today
|
65
|
+
|
66
|
+
def today(sg=Date::ITALY)
|
67
|
+
t = Time.now
|
68
|
+
Date.civil(t.year, t.mon, t.mday)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
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: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
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: 2011-
|
19
|
+
date: 2011-11-11 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -86,10 +86,10 @@ executables: []
|
|
86
86
|
extensions: []
|
87
87
|
|
88
88
|
extra_rdoc_files:
|
89
|
-
- README.
|
89
|
+
- README.md
|
90
90
|
files:
|
91
91
|
- lib/delorean.rb
|
92
|
-
- README.
|
92
|
+
- README.md
|
93
93
|
- MIT-LICENSE
|
94
94
|
has_rdoc: true
|
95
95
|
homepage: http://github.com/bebanjo/delorean
|
data/README.rdoc
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
= Delorean
|
2
|
-
|
3
|
-
Delorean lets you travel in time with Ruby by mocking <tt>Time.now</tt>
|
4
|
-
|
5
|
-
http://dl.dropbox.com/u/645329/delorean.png
|
6
|
-
|
7
|
-
Marty:: Wait a minute, Doc. Ah... Are you telling me that you built a time machine... out of a DeLorean?
|
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
|
-
|
10
|
-
== Install
|
11
|
-
|
12
|
-
$ [sudo] gem install delorean
|
13
|
-
|
14
|
-
== Usage
|
15
|
-
|
16
|
-
Let's travel in time!
|
17
|
-
|
18
|
-
require 'delorean'
|
19
|
-
|
20
|
-
# Date.today => Wed Feb 24
|
21
|
-
Delorean.time_travel_to "1 month ago" # Date.today => Sun Jan 24
|
22
|
-
Delorean.back_to_the_present # Date.today => Wed Feb 24
|
23
|
-
|
24
|
-
With a block:
|
25
|
-
|
26
|
-
Delorean.time_travel_to("1 month ago") do
|
27
|
-
# Inside the block, Time.now => Sun Jan 24 00:34:32 +0100 2010
|
28
|
-
sleep(5)
|
29
|
-
# And the time still goes by... Time.now => Sun Jan 24 00:34:37 +0100 2010
|
30
|
-
end
|
31
|
-
|
32
|
-
# Outside the block, Time.now => Wed Feb 24 00:34:35 +0100 2010
|
33
|
-
|
34
|
-
You can also <tt>jump</tt> which is like <tt>sleep</tt> but without losing time
|
35
|
-
|
36
|
-
# Time.now => Wed Feb 24 00:34:04 +0100 2010
|
37
|
-
Delorean.jump 30
|
38
|
-
# Time.now => Wed Feb 24 00:34:34 +0100 2010
|
39
|
-
|
40
|
-
=== Testing
|
41
|
-
|
42
|
-
Time-travelling can be extremely useful when you're testing your application.
|
43
|
-
|
44
|
-
For example, in RSpec you may find convenient to include Delorean's DSL in your <tt>spec_helper.rb</tt>:
|
45
|
-
|
46
|
-
Spec::Runner.configure do |config|
|
47
|
-
config.include Delorean
|
48
|
-
...
|
49
|
-
|
50
|
-
Now you can time-travel in your examples, like this:
|
51
|
-
|
52
|
-
it "should show latest created user" do
|
53
|
-
|
54
|
-
time_travel_to(3.minutes.ago) { create_user :name => "John" }
|
55
|
-
time_travel_to(5.minutes.ago) { create_user :name => "Chris" }
|
56
|
-
|
57
|
-
get 'show'
|
58
|
-
|
59
|
-
response.should have_text("John")
|
60
|
-
response.should_not have_text("Chris")
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
Don't forget to go back to the present after each example:
|
65
|
-
|
66
|
-
after(:each) { back_to_the_present }
|
67
|
-
|
68
|
-
or its alternate syntax:
|
69
|
-
|
70
|
-
after(:each) { back_to_1985 }
|
71
|
-
|
72
|
-
== Credits
|
73
|
-
|
74
|
-
Delorean image based on an original[http://www.gocarlo.com/lagalerie/archives/march05.htm] by {Giancarlo Pitocco}[http://www.gocarlo.com/]
|
75
|
-
|
76
|
-
Copyright (c) 2010 Luismi Cavallé, Sergio Gil and BeBanjo S.L. released under the MIT license
|
77
|
-
|