whenever-delorean 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +165 -0
- data/README.rdoc +38 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/lib/whenever-delorean.rb +103 -0
- data/spec/integration/whenever-delorean_spec.rb +83 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/unit/whenever-delorean_spec.rb +279 -0
- metadata +174 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ZenTest (4.8.3)
|
5
|
+
activesupport (3.2.13)
|
6
|
+
i18n (= 0.6.1)
|
7
|
+
multi_json (~> 1.0)
|
8
|
+
chronic (0.9.1)
|
9
|
+
delorean (2.1.0)
|
10
|
+
chronic
|
11
|
+
diff-lcs (1.1.3)
|
12
|
+
git (1.2.5)
|
13
|
+
i18n (0.6.1)
|
14
|
+
jeweler (1.8.4)
|
15
|
+
bundler (~> 1.0)
|
16
|
+
git (>= 1.2.5)
|
17
|
+
rake
|
18
|
+
rdoc
|
19
|
+
json (1.7.7)
|
20
|
+
multi_json (1.7.2)
|
21
|
+
parse-cron (0.1.2)
|
22
|
+
rake (10.0.4)
|
23
|
+
rdoc (3.12.2)
|
24
|
+
json (~> 1.4)
|
25
|
+
rspec (2.8.0)
|
26
|
+
rspec-core (~> 2.8.0)
|
27
|
+
rspec-expectations (~> 2.8.0)
|
28
|
+
rspec-mocks (~> 2.8.0)
|
29
|
+
rspec-core (2.8.0)
|
30
|
+
rspec-expectations (2.8.0)
|
31
|
+
diff-lcs (~> 1.1.2)
|
32
|
+
rspec-mocks (2.8.0)
|
33
|
+
whenever (0.8.2)
|
34
|
+
activesupport (>= 2.3.4)
|
35
|
+
chronic (>= 0.6.3)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
ZenTest
|
42
|
+
delorean (~> 2.1)
|
43
|
+
jeweler (~> 1.8.4)
|
44
|
+
parse-cron (~> 0.1.2)
|
45
|
+
rdoc (~> 3.12)
|
46
|
+
rspec (~> 2.8.0)
|
47
|
+
whenever (~> 0.8)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2012 Björn Blomqvist
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/README.rdoc
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
= whenever-delorean
|
2
|
+
|
3
|
+
Helper for integration testing. It helps you trigger your whener runners.
|
4
|
+
|
5
|
+
En example usage. The below will result in TestHelper.a_dummy_method being called 30 times
|
6
|
+
|
7
|
+
```
|
8
|
+
# config/schedule.rb
|
9
|
+
|
10
|
+
every 1.week, :at => '4:30 am' do
|
11
|
+
runner "TestHelper.something_else"
|
12
|
+
end
|
13
|
+
|
14
|
+
every 1.day, :at => '4:30 am' do
|
15
|
+
runner "TestHelper.a_dummy_method"
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
```
|
20
|
+
# In your integration test
|
21
|
+
WheneverDelorean.time_travel_to("30 days from now", :only => /a_dummy_method/)
|
22
|
+
```
|
23
|
+
|
24
|
+
== Contributing to whenever-delorean
|
25
|
+
|
26
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
27
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
28
|
+
* Fork the project.
|
29
|
+
* Start a feature/bugfix branch.
|
30
|
+
* Commit and push until you are happy with your contribution.
|
31
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
32
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
33
|
+
|
34
|
+
== Copyright
|
35
|
+
|
36
|
+
Copyright (c) 2013 Björn Blomqvist. See LICENSE.txt for
|
37
|
+
further details.
|
38
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "whenever-delorean"
|
18
|
+
gem.homepage = "http://github.com/bjornblomqvist/whenever-delorean"
|
19
|
+
gem.license = "LGPL"
|
20
|
+
gem.summary = %Q{Triggers your whener runners for you.}
|
21
|
+
gem.description = %Q{Helper for integration testing. It helps you trigger your whener runners.}
|
22
|
+
gem.email = "darwin.git@marianna.se"
|
23
|
+
gem.authors = ["Darwin"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
task :default => :spec
|
35
|
+
|
36
|
+
require 'rdoc/task'
|
37
|
+
Rake::RDocTask.new do |rdoc|
|
38
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
39
|
+
|
40
|
+
rdoc.rdoc_dir = 'rdoc'
|
41
|
+
rdoc.title = "whenever-delorean #{version}"
|
42
|
+
rdoc.rdoc_files.include('README*')
|
43
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'whenever'
|
2
|
+
require 'time'
|
3
|
+
require 'date'
|
4
|
+
require 'parse-cron'
|
5
|
+
|
6
|
+
class WheneverDelorean
|
7
|
+
|
8
|
+
def initialize(time, options)
|
9
|
+
@destination_time = parse_date(time)
|
10
|
+
@match = options[:only]
|
11
|
+
raise 'must set the :only => //, option' unless @match
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.time_travel_to(*arguments)
|
15
|
+
WheneverDelorean.new(*arguments).time_travel
|
16
|
+
end
|
17
|
+
|
18
|
+
def time_travel
|
19
|
+
run_jobs
|
20
|
+
Delorean.time_travel_to(destination_time)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def parse_date(time)
|
26
|
+
time = Chronic.parse(time) if time.is_a?(String)
|
27
|
+
time = Time.local(time.year, time.month, time.day) if time.is_a?(Date) && !time.is_a?(DateTime)
|
28
|
+
|
29
|
+
time
|
30
|
+
end
|
31
|
+
|
32
|
+
def destination_time
|
33
|
+
@destination_time
|
34
|
+
end
|
35
|
+
|
36
|
+
def run_jobs
|
37
|
+
jobs.each do |job|
|
38
|
+
Delorean.time_travel_to(job[:time])
|
39
|
+
eval(job[:runner])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def jobs
|
44
|
+
|
45
|
+
jobs = []
|
46
|
+
|
47
|
+
whenever_jobs.each do |whenever_job|
|
48
|
+
get_run_times(whenever_job[:cron_time]).each do |time|
|
49
|
+
jobs << {:runner => whenever_job[:runner], :time => time}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
jobs.sort {|a,b| a[:time] <=> b[:time] }
|
54
|
+
end
|
55
|
+
|
56
|
+
def whenever_jobs
|
57
|
+
|
58
|
+
to_return = []
|
59
|
+
|
60
|
+
raw_whenever_jobs.each_pair do |time,jobs|
|
61
|
+
jobs.each do |job|
|
62
|
+
if job.instance_variable_get("@template") == "runner"
|
63
|
+
job.instance_variable_set("@job_template","")
|
64
|
+
Whenever::Output::Cron.output(time,job) do |cron|
|
65
|
+
task = job.instance_variable_get("@options")[:task]
|
66
|
+
if should_include(task)
|
67
|
+
to_return << {:runner => task, :cron_time => cron}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
to_return
|
75
|
+
end
|
76
|
+
|
77
|
+
def should_include(string)
|
78
|
+
string.match(@match)
|
79
|
+
end
|
80
|
+
|
81
|
+
def raw_whenever_jobs
|
82
|
+
Whenever::JobList.new("job_type :runner, 'runner'\n"+schedule_data).instance_variable_get("@jobs")
|
83
|
+
end
|
84
|
+
|
85
|
+
def schedule_data
|
86
|
+
File.read(Rails.root+"/config/schedule.rb")
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_run_times(cron_time)
|
90
|
+
|
91
|
+
last_time = Time.now
|
92
|
+
times = []
|
93
|
+
|
94
|
+
cp = CronParser.new(cron_time)
|
95
|
+
while (last_time < destination_time)
|
96
|
+
last_time = cp.next(last_time)
|
97
|
+
times << last_time if last_time < destination_time
|
98
|
+
end
|
99
|
+
|
100
|
+
times
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
#
|
4
|
+
# TestWhenever.time_travel_to("1 month ago", :only => /uehtnosuao/)
|
5
|
+
#
|
6
|
+
|
7
|
+
describe "WheneverDelorean" do
|
8
|
+
|
9
|
+
describe ".time_travel_to" do
|
10
|
+
|
11
|
+
it "should take us to the supplied time and trigger all whenever jobbs we pass" do
|
12
|
+
|
13
|
+
Rails.should_receive(:root).and_return("/dummy-rails-root")
|
14
|
+
File.should_receive(:read).with("/dummy-rails-root/config/schedule.rb").and_return(%{
|
15
|
+
every 1.day, :at => '4:30 am' do
|
16
|
+
runner "TestHelper.a_dummy_method"
|
17
|
+
end
|
18
|
+
})
|
19
|
+
|
20
|
+
TestHelper.should_receive(:a_dummy_method).exactly(30).times
|
21
|
+
|
22
|
+
WheneverDelorean.time_travel_to("30 days from now", :only => /a_dummy_method/)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should only run runners matching the regex' do
|
26
|
+
|
27
|
+
Rails.should_receive(:root).and_return("/dummy-rails-root")
|
28
|
+
File.should_receive(:read).with("/dummy-rails-root/config/schedule.rb").and_return(%{
|
29
|
+
every 1.day, :at => '4:30 am' do
|
30
|
+
runner "TestHelper.a_dummy_method"
|
31
|
+
end
|
32
|
+
|
33
|
+
every 1.day, :at => '5:30 am' do
|
34
|
+
runner "TestHelper.a_dummy"
|
35
|
+
end
|
36
|
+
})
|
37
|
+
|
38
|
+
TestHelper.should_receive(:a_dummy_method).exactly(5).times
|
39
|
+
|
40
|
+
WheneverDelorean.time_travel_to("5 days from now", :only => /a_dummy_method/)
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should be able to handle multable runners' do
|
45
|
+
|
46
|
+
Rails.should_receive(:root).and_return("/dummy-rails-root")
|
47
|
+
File.should_receive(:read).with("/dummy-rails-root/config/schedule.rb").and_return(%{
|
48
|
+
every 1.day, :at => '4:30 am' do
|
49
|
+
runner "TestHelper.a_dummy_method"
|
50
|
+
end
|
51
|
+
|
52
|
+
every 1.day, :at => '5:30 am' do
|
53
|
+
runner "TestHelper.a_dummy_method"
|
54
|
+
end
|
55
|
+
})
|
56
|
+
|
57
|
+
TestHelper.should_receive(:a_dummy_method).exactly(10).times
|
58
|
+
|
59
|
+
WheneverDelorean.time_travel_to("5 days from now", :only => /a_dummy_method/)
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should ignore rake tasks' do
|
64
|
+
|
65
|
+
Rails.should_receive(:root).and_return("/dummy-rails-root")
|
66
|
+
File.should_receive(:read).with("/dummy-rails-root/config/schedule.rb").and_return(%{
|
67
|
+
every 1.day, :at => '4:30 am' do
|
68
|
+
rake "TestHelper.a_dummy_method"
|
69
|
+
end
|
70
|
+
|
71
|
+
every 1.day, :at => '5:30 am' do
|
72
|
+
runner "TestHelper.a_dummy_method"
|
73
|
+
end
|
74
|
+
})
|
75
|
+
|
76
|
+
TestHelper.should_receive(:a_dummy_method).exactly(5).times
|
77
|
+
|
78
|
+
WheneverDelorean.time_travel_to("5 days from now", :only => /a_dummy_method/)
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'delorean'
|
5
|
+
require 'whenever-delorean'
|
6
|
+
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
8
|
+
# in ./support/ and its subdirectories.
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
class TestHelper
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
class Rails
|
20
|
+
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,279 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "WheneverDelorean" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
Delorean.back_to_the_present
|
7
|
+
WheneverDelorean.any_instance.stub(:parse_date)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".time_travel_to" do
|
11
|
+
|
12
|
+
it "should create a new instance with the given arguments and call time_travel" do
|
13
|
+
|
14
|
+
whenever_delorean = mock("WheneverDelorean")
|
15
|
+
whenever_delorean.should_receive(:time_travel)
|
16
|
+
|
17
|
+
WheneverDelorean.should_receive(:new).with("3 days from now").and_return(whenever_delorean)
|
18
|
+
|
19
|
+
WheneverDelorean.time_travel_to("3 days from now")
|
20
|
+
|
21
|
+
whenever_delorean.should_receive(:time_travel)
|
22
|
+
WheneverDelorean.should_receive(:new).with("3 days from now", :only => /something/).and_return(whenever_delorean)
|
23
|
+
|
24
|
+
WheneverDelorean.time_travel_to("3 days from now", :only => /something/)
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#time_travel" do
|
30
|
+
|
31
|
+
subject { WheneverDelorean.new(nil,{:only => /./}) }
|
32
|
+
|
33
|
+
it 'should run all the jobs at the correct time and then time travel to the given time' do
|
34
|
+
|
35
|
+
dummy_time = mock("A dummy time")
|
36
|
+
|
37
|
+
subject.should_receive(:run_jobs)
|
38
|
+
subject.should_receive(:destination_time).and_return(dummy_time)
|
39
|
+
Delorean.should_receive(:time_travel_to).with(dummy_time)
|
40
|
+
|
41
|
+
subject.time_travel
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#parse_date" do
|
48
|
+
|
49
|
+
subject { WheneverDelorean.new(nil,{:only => /./}) }
|
50
|
+
|
51
|
+
it 'should covert string to time when posible' do
|
52
|
+
|
53
|
+
WheneverDelorean.any_instance.unstub(:parse_date)
|
54
|
+
WheneverDelorean.any_instance.stub(:initialize)
|
55
|
+
|
56
|
+
Chronic.should_receive(:parse).with("1 days ago").and_return("dummy result")
|
57
|
+
subject.send(:parse_date,"1 days ago").should == "dummy result"
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should let instances of time pass throu' do
|
62
|
+
|
63
|
+
WheneverDelorean.any_instance.unstub(:parse_date)
|
64
|
+
WheneverDelorean.any_instance.stub(:initialize)
|
65
|
+
|
66
|
+
t = Time.now
|
67
|
+
|
68
|
+
subject.send(:parse_date,t).should == t
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should convert date instances to time' do
|
73
|
+
|
74
|
+
WheneverDelorean.any_instance.unstub(:parse_date)
|
75
|
+
WheneverDelorean.any_instance.stub(:initialize)
|
76
|
+
|
77
|
+
date = Date.new
|
78
|
+
|
79
|
+
subject.send(:parse_date,date).class.should == Time
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#destination_time' do
|
86
|
+
|
87
|
+
it 'should return the the supplied destination_time in new' do
|
88
|
+
|
89
|
+
time_mock = mock("time mock")
|
90
|
+
|
91
|
+
WheneverDelorean.any_instance.should_receive(:parse_date).with(time_mock).and_return("result")
|
92
|
+
WheneverDelorean.new(time_mock, :only => //).send(:destination_time).should == "result"
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#run_jobs" do
|
99
|
+
|
100
|
+
subject { WheneverDelorean.new(nil,{:only => /./}) }
|
101
|
+
|
102
|
+
it 'should iterate all the jobs and run time at the correct time' do
|
103
|
+
|
104
|
+
jobs = [{:runner => "TestHelper.dummy_method1", :time => Time.new(2010,01,01)}, {:runner => "TestHelper.dummy_method1", :time => Time.new(2010,01,01)}]
|
105
|
+
|
106
|
+
subject.should_receive(:jobs).and_return(jobs)
|
107
|
+
|
108
|
+
jobs.each do |job|
|
109
|
+
Delorean.should_receive(:time_travel_to).with(job[:time])
|
110
|
+
TestHelper.should_receive(job[:runner].match(/\.(.+)/)[1])
|
111
|
+
end
|
112
|
+
|
113
|
+
subject.send(:run_jobs)
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "#jobs" do
|
119
|
+
|
120
|
+
subject { WheneverDelorean.new(nil,{:only => /./}) }
|
121
|
+
|
122
|
+
it 'should return all whenever jobs that should be run sorted acording to time' do
|
123
|
+
|
124
|
+
subject.should_receive(:whenever_jobs).and_return([
|
125
|
+
{:runner => "dummy1", :cron_time => "dummy_cron_time_1"},
|
126
|
+
{:runner => "dummy2", :cron_time => "dummy_cron_time_2"}
|
127
|
+
])
|
128
|
+
|
129
|
+
subject.should_receive(:get_run_times).with("dummy_cron_time_1").and_return([Time.new(2010,01,01),Time.new(2010,01,02)])
|
130
|
+
subject.should_receive(:get_run_times).with("dummy_cron_time_2").and_return([Time.new(2010,01,01),Time.new(2010,01,02)])
|
131
|
+
|
132
|
+
subject.send(:jobs).should == [
|
133
|
+
{:runner => "dummy1", :time => Time.new(2010,01,01)},
|
134
|
+
{:runner => "dummy2", :time => Time.new(2010,01,01)},
|
135
|
+
{:runner => "dummy1", :time => Time.new(2010,01,02)},
|
136
|
+
{:runner => "dummy2", :time => Time.new(2010,01,02)}
|
137
|
+
]
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '#get_run_times' do
|
144
|
+
|
145
|
+
subject { WheneverDelorean.new(nil,{:only => /./}) }
|
146
|
+
|
147
|
+
it 'should return all the run times for a cron time between now and destination_time' do
|
148
|
+
|
149
|
+
Time.should_receive(:now).and_return(Time.new(2010,01,01))
|
150
|
+
|
151
|
+
subject.should_receive(:destination_time).exactly(7).times.and_return(Time.new(2010,01,03))
|
152
|
+
|
153
|
+
cron_parser_dummy = mock("cron_parser_dummy")
|
154
|
+
CronParser.should_receive(:new).with("dummy_cron_time").and_return(cron_parser_dummy)
|
155
|
+
|
156
|
+
cron_parser_dummy.should_receive(:next).with(Time.new(2010,01,01)).and_return(Time.new(2010,01,01,01))
|
157
|
+
cron_parser_dummy.should_receive(:next).with(Time.new(2010,01,01,01)).and_return(Time.new(2010,01,02,01))
|
158
|
+
cron_parser_dummy.should_receive(:next).with(Time.new(2010,01,02,01)).and_return(Time.new(2010,01,03,01))
|
159
|
+
|
160
|
+
|
161
|
+
subject.send(:get_run_times,"dummy_cron_time").should == [Time.new(2010,01,01,01),Time.new(2010,01,02,01)]
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "should_include" do
|
168
|
+
|
169
|
+
subject { WheneverDelorean.new(nil, :only => /foo/) }
|
170
|
+
|
171
|
+
it 'should return true when the given string matches the regex given at init' do
|
172
|
+
|
173
|
+
subject.send(:should_include,"boo").should be_false
|
174
|
+
subject.send(:should_include,"foo").should be_true
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#whenever_jobs' do
|
181
|
+
|
182
|
+
subject { WheneverDelorean.new(nil,{:only => /./}) }
|
183
|
+
|
184
|
+
it 'should get the whenever jobs and return them as simple hashes' do
|
185
|
+
|
186
|
+
raw_jobs = {:month => [mock('job1'),mock('job2')]}
|
187
|
+
|
188
|
+
subject.should_receive(:raw_whenever_jobs).and_return(raw_jobs)
|
189
|
+
|
190
|
+
raw_jobs.each_pair do |time,jobs|
|
191
|
+
jobs.each_with_index do |job,index|
|
192
|
+
job.should_receive(:instance_variable_get).with("@template").and_return("runner")
|
193
|
+
job.should_receive(:instance_variable_get).with("@options").and_return({:task => "dummy#{index+1}"})
|
194
|
+
job.should_receive(:instance_variable_set).with("@job_template",'')
|
195
|
+
subject.should_receive(:should_include).with("dummy#{index+1}").and_return(true)
|
196
|
+
Whenever::Output::Cron.should_receive(:output).with(time,job).and_yield("dummy_cron_time_#{index+1}")
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
subject.send(:whenever_jobs).should == [
|
201
|
+
{:runner => "dummy1", :cron_time => "dummy_cron_time_1"},
|
202
|
+
{:runner => "dummy2", :cron_time => "dummy_cron_time_2"}
|
203
|
+
]
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'should skip all jobs that does not match the supplied regex ' do
|
208
|
+
|
209
|
+
raw_jobs = {:month => [mock('job1'),mock('job2')]}
|
210
|
+
|
211
|
+
subject.should_receive(:raw_whenever_jobs).and_return(raw_jobs)
|
212
|
+
|
213
|
+
raw_jobs.each_pair do |time,jobs|
|
214
|
+
jobs.each_with_index do |job,index|
|
215
|
+
job.should_receive(:instance_variable_get).with("@template").and_return("runner")
|
216
|
+
job.should_receive(:instance_variable_get).with("@options").and_return({:task => "dummy#{index+1}"})
|
217
|
+
job.should_receive(:instance_variable_set).with("@job_template",'')
|
218
|
+
subject.should_receive(:should_include).with("dummy#{index+1}").and_return(false)
|
219
|
+
Whenever::Output::Cron.should_receive(:output).with(time,job).and_yield("dummy_cron_time_#{index+1}")
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
subject.send(:whenever_jobs).should == []
|
224
|
+
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'should skip none runner jobs' do
|
228
|
+
|
229
|
+
raw_jobs = {:month => [mock('job1'),mock('job2')]}
|
230
|
+
|
231
|
+
subject.should_receive(:raw_whenever_jobs).and_return(raw_jobs)
|
232
|
+
|
233
|
+
raw_jobs.each_pair do |time,jobs|
|
234
|
+
jobs.each_with_index do |job,index|
|
235
|
+
job.should_receive(:instance_variable_get).with("@template").and_return("some thing else")
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
subject.send(:whenever_jobs).should == []
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
describe "#raw_whenever_jobs" do
|
246
|
+
|
247
|
+
subject { WheneverDelorean.new(nil,{:only => /./}) }
|
248
|
+
|
249
|
+
it 'should return the raw whenever jobs' do
|
250
|
+
|
251
|
+
subject.should_receive(:schedule_data).and_return("dummy_schdule_data")
|
252
|
+
|
253
|
+
dummy_jobs_list = mock("jobs_list")
|
254
|
+
Whenever::JobList.should_receive(:new).with("job_type :runner, 'runner'\n"+"dummy_schdule_data").and_return(dummy_jobs_list)
|
255
|
+
|
256
|
+
dummy_jobs = mock("jobs")
|
257
|
+
dummy_jobs_list.should_receive(:instance_variable_get).with("@jobs").and_return(dummy_jobs)
|
258
|
+
|
259
|
+
subject.send(:raw_whenever_jobs).should == dummy_jobs
|
260
|
+
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
describe "#schedule_data" do
|
265
|
+
|
266
|
+
subject { WheneverDelorean.new(nil,{:only => /./}) }
|
267
|
+
|
268
|
+
it 'should return the data from the config/schedule.rb file' do
|
269
|
+
|
270
|
+
Rails.should_receive(:root).and_return("/dummy_root")
|
271
|
+
File.should_receive(:read).with("/dummy_root/config/schedule.rb").and_return("dummy data")
|
272
|
+
|
273
|
+
subject.send(:schedule_data).should == "dummy data"
|
274
|
+
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: whenever-delorean
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Darwin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: delorean
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: whenever
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.8'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.8'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: parse-cron
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.1.2
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.1.2
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.8.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.8.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rdoc
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '3.12'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '3.12'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: jeweler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.8.4
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.4
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: ZenTest
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: Helper for integration testing. It helps you trigger your whener runners.
|
127
|
+
email: darwin.git@marianna.se
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.rdoc
|
133
|
+
files:
|
134
|
+
- .document
|
135
|
+
- .rspec
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.rdoc
|
140
|
+
- Rakefile
|
141
|
+
- VERSION
|
142
|
+
- lib/whenever-delorean.rb
|
143
|
+
- spec/integration/whenever-delorean_spec.rb
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
- spec/unit/whenever-delorean_spec.rb
|
146
|
+
homepage: http://github.com/bjornblomqvist/whenever-delorean
|
147
|
+
licenses:
|
148
|
+
- LGPL
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ! '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
segments:
|
160
|
+
- 0
|
161
|
+
hash: 136335431411580159
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
none: false
|
164
|
+
requirements:
|
165
|
+
- - ! '>='
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
requirements: []
|
169
|
+
rubyforge_project:
|
170
|
+
rubygems_version: 1.8.24
|
171
|
+
signing_key:
|
172
|
+
specification_version: 3
|
173
|
+
summary: Triggers your whener runners for you.
|
174
|
+
test_files: []
|