forked from kevin-j-m/clockwork-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.rb
73 lines (58 loc) · 1.54 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require "clockwork"
require "timecop"
require "clockwork/test/event"
require "clockwork/test/job_history"
require "clockwork/test/manager"
require "clockwork/test/version"
module Clockwork
module Methods
def every(period, job, options={}, &block)
::Clockwork.manager.every(period, job, options, &block)
::Clockwork::Test.manager.every(period, job, options, &block)
end
end
module Test
class << self
def included(klass)
klass.send "include", Methods
klass.extend Methods
klass.send "include", ::Clockwork::Methods
klass.extend ::Clockwork::Methods
end
def manager
@manager ||= Clockwork::Test::Manager.new
end
def manager=(manager)
@manager = manager
end
end
module Methods
def run(opts = {})
file = opts[:file] || "./config/clock.rb"
run_opts = {
max_ticks: opts[:max_ticks],
start_time: opts[:start_time],
end_time: opts[:end_time],
tick_speed: opts[:tick_speed]
}
# TODO parse file rather than loading it
# and overloading Clockwork::Methods::every
load file
manager.run(run_opts)
end
def clear!
Clockwork::Test.manager = Clockwork::Test::Manager.new
end
def ran_job?(job)
manager.ran_job?(job)
end
def times_run(job)
manager.times_run(job)
end
def block_for(job)
manager.block_for(job)
end
end
extend Methods, ::Clockwork::Methods
end
end