delorean 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +53 -11
- metadata +4 -3
data/README.rdoc
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
= Delorean
|
2
2
|
|
3
|
-
Delorean
|
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?
|
4
9
|
|
5
10
|
== Install
|
6
11
|
|
@@ -8,24 +13,61 @@ Delorean let you time-travel in Ruby by mocking <code>Time.now</code>
|
|
8
13
|
|
9
14
|
== Usage
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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:
|
16
25
|
|
17
26
|
Delorean.time_travel_to("1 month ago") do
|
18
|
-
# Inside the block:
|
19
|
-
# Time.now => Sun Jan 24 00:34:32 +0100 2010
|
27
|
+
# Inside the block, Time.now => Sun Jan 24 00:34:32 +0100 2010
|
20
28
|
sleep(5)
|
21
|
-
# And the time still goes
|
29
|
+
# And the time still goes by... Time.now => Sun Jan 24 00:34:37 +0100 2010
|
22
30
|
end
|
23
|
-
|
24
|
-
# Time.now => Wed Feb 24 00:34:35 +0100 2010
|
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
|
25
35
|
|
26
36
|
# Time.now => Wed Feb 24 00:34:04 +0100 2010
|
27
37
|
Delorean.jump 30
|
28
38
|
# Time.now => Wed Feb 24 00:34:34 +0100 2010
|
29
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
|
+
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
|
+
== Credits
|
69
|
+
|
70
|
+
Delorean image based on an original[http://www.gocarlo.com/lagalerie/archives/march05.htm] by {Giancarlo Pitocco}[http://www.gocarlo.com/]
|
71
|
+
|
30
72
|
Copyright (c) 2010 Luismi Cavallé, Sergio Gil and BeBanjo S.L. released under the MIT license
|
31
73
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delorean
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Luismi Cavall\xC3\xA9"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-02-
|
13
|
+
date: 2010-02-25 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -52,6 +52,7 @@ post_install_message:
|
|
52
52
|
rdoc_options:
|
53
53
|
- --main
|
54
54
|
- README.rdoc
|
55
|
+
- --charset=UTF-8
|
55
56
|
require_paths:
|
56
57
|
- lib
|
57
58
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -72,6 +73,6 @@ rubyforge_project:
|
|
72
73
|
rubygems_version: 1.3.5
|
73
74
|
signing_key:
|
74
75
|
specification_version: 3
|
75
|
-
summary:
|
76
|
+
summary: Delorean lets you travel in time with Ruby by mocking Time.now
|
76
77
|
test_files: []
|
77
78
|
|