clockwork 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1c0df23cd1bd9f2a974f5d5461b162d5449858b
4
- data.tar.gz: 57d4d055c37fea9164a51ea16afb34cf72b6ca16
3
+ metadata.gz: c0e853cc4ad85d5e3814beac451289db63f3cfdf
4
+ data.tar.gz: 4d5b4f49d461f7a2b9e6670d122cc74c3d3ee1dc
5
5
  SHA512:
6
- metadata.gz: 61a97fce154912af62947c6591f771ce532e1b87bc4b25cd83d6983ac2d1618ebe9c98a4c2df7cc939a3af2d04aa9bef6b29169f3b38ca07eb63fece32a97fdc
7
- data.tar.gz: f9a24be2f061626b409b69fa43f53b0ee16da421d892a5b5afd4bc86623ce41e74ab598bf0b89a9451c42c0279cc76314b92f8fb1706922312cdf51c53092dee
6
+ metadata.gz: cdc0a27e31a8c45dc07aeedf1cb5c80e0983bb25dfee570568d91147a6b54d8524efc5d7ccc580f9a9ae09e0dd4126f562951a997864d142617ca44b3d4a3c2b
7
+ data.tar.gz: 68a028033d71834bd0c1904de8dfeaab9624593f1211cb9254483835c71489c7936ec9ffecef30fc70f5dd62884752b35b4c58575ab89dbbe5338eb8db4e77a4
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "clockwork"
3
- s.version = "1.2.0"
3
+ s.version = "1.2.1"
4
4
 
5
5
  s.authors = ["Adam Wiggins", "tomykaira"]
6
6
  s.license = 'MIT'
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency "bundler", "~> 1.3"
24
24
  s.add_development_dependency "rake"
25
25
  s.add_development_dependency "daemons"
26
- s.add_development_dependency "test-unit"
27
- s.add_development_dependency "minitest", "~> 4.0"
26
+ s.add_development_dependency "minitest", "~> 5.8"
28
27
  s.add_development_dependency "mocha"
29
28
  end
@@ -7,4 +7,5 @@ platforms :rbx do
7
7
  end
8
8
 
9
9
  gem 'activesupport', '~> 4.0.0'
10
+ gem 'minitest', '~> 4.2'
10
11
  gemspec :path=>"../"
@@ -1,31 +1,29 @@
1
1
  require File.expand_path('../../lib/clockwork', __FILE__)
2
- require 'rubygems'
3
- require 'test/unit'
2
+ require "minitest/autorun"
4
3
  require 'mocha/setup'
5
4
  require 'time'
6
5
  require 'active_support/time'
7
- require 'active_support/test_case'
8
6
 
9
- class AtTest < ActiveSupport::TestCase
7
+ describe 'Clockwork::At' do
10
8
  def time_in_day(hour, minute)
11
9
  Time.new(2013, 1, 1, hour, minute, 0)
12
10
  end
13
11
 
14
- test '16:20' do
12
+ it '16:20' do
15
13
  at = Clockwork::At.parse('16:20')
16
14
  assert !at.ready?(time_in_day(16, 19))
17
15
  assert at.ready?(time_in_day(16, 20))
18
16
  assert !at.ready?(time_in_day(16, 21))
19
17
  end
20
18
 
21
- test '8:20' do
19
+ it '8:20' do
22
20
  at = Clockwork::At.parse('8:20')
23
21
  assert !at.ready?(time_in_day(8, 19))
24
22
  assert at.ready?(time_in_day(8, 20))
25
23
  assert !at.ready?(time_in_day(8, 21))
26
24
  end
27
25
 
28
- test '**:20 with two stars' do
26
+ it '**:20 with two stars' do
29
27
  at = Clockwork::At.parse('**:20')
30
28
 
31
29
  assert !at.ready?(time_in_day(15, 19))
@@ -37,7 +35,7 @@ class AtTest < ActiveSupport::TestCase
37
35
  assert !at.ready?(time_in_day(16, 21))
38
36
  end
39
37
 
40
- test '*:20 with one star' do
38
+ it '*:20 with one star' do
41
39
  at = Clockwork::At.parse('*:20')
42
40
 
43
41
  assert !at.ready?(time_in_day(15, 19))
@@ -49,7 +47,7 @@ class AtTest < ActiveSupport::TestCase
49
47
  assert !at.ready?(time_in_day(16, 21))
50
48
  end
51
49
 
52
- test '16:**' do
50
+ it '16:**' do
53
51
  at = Clockwork::At.parse('16:**')
54
52
 
55
53
  assert !at.ready?(time_in_day(15, 59))
@@ -59,7 +57,7 @@ class AtTest < ActiveSupport::TestCase
59
57
  assert !at.ready?(time_in_day(17, 00))
60
58
  end
61
59
 
62
- test '8:**' do
60
+ it '8:**' do
63
61
  at = Clockwork::At.parse('8:**')
64
62
 
65
63
  assert !at.ready?(time_in_day(7, 59))
@@ -69,7 +67,7 @@ class AtTest < ActiveSupport::TestCase
69
67
  assert !at.ready?(time_in_day(9, 00))
70
68
  end
71
69
 
72
- test 'Saturday 12:00' do
70
+ it 'Saturday 12:00' do
73
71
  at = Clockwork::At.parse('Saturday 12:00')
74
72
 
75
73
  assert !at.ready?(Time.new(2010, 1, 1, 12, 00))
@@ -78,7 +76,7 @@ class AtTest < ActiveSupport::TestCase
78
76
  assert at.ready?(Time.new(2010, 1, 9, 12, 00))
79
77
  end
80
78
 
81
- test 'sat 12:00' do
79
+ it 'sat 12:00' do
82
80
  at = Clockwork::At.parse('sat 12:00')
83
81
 
84
82
  assert !at.ready?(Time.new(2010, 1, 1, 12, 00))
@@ -86,34 +84,33 @@ class AtTest < ActiveSupport::TestCase
86
84
  assert !at.ready?(Time.new(2010, 1, 3, 12, 00))
87
85
  end
88
86
 
89
- test 'invalid time 32:00' do
90
- assert_raise Clockwork::At::FailedToParse do
87
+ it 'invalid time 32:00' do
88
+ assert_raises Clockwork::At::FailedToParse do
91
89
  Clockwork::At.parse('32:00')
92
90
  end
93
91
  end
94
92
 
95
- test 'invalid multi-line with Sat 12:00' do
96
- assert_raise Clockwork::At::FailedToParse do
93
+ it 'invalid multi-line with Sat 12:00' do
94
+ assert_raises Clockwork::At::FailedToParse do
97
95
  Clockwork::At.parse("sat 12:00\nreally invalid time")
98
96
  end
99
97
  end
100
98
 
101
- test 'invalid multi-line with 8:30' do
102
- assert_raise Clockwork::At::FailedToParse do
99
+ it 'invalid multi-line with 8:30' do
100
+ assert_raises Clockwork::At::FailedToParse do
103
101
  Clockwork::At.parse("8:30\nreally invalid time")
104
102
  end
105
103
  end
106
104
 
107
- test 'invalid multi-line with *:10' do
108
- assert_raise Clockwork::At::FailedToParse do
105
+ it 'invalid multi-line with *:10' do
106
+ assert_raises Clockwork::At::FailedToParse do
109
107
  Clockwork::At.parse("*:10\nreally invalid time")
110
108
  end
111
109
  end
112
110
 
113
- test 'invalid multi-line with 12:**' do
114
- assert_raise Clockwork::At::FailedToParse do
111
+ it 'invalid multi-line with 12:**' do
112
+ assert_raises Clockwork::At::FailedToParse do
115
113
  Clockwork::At.parse("12:**\nreally invalid time")
116
114
  end
117
115
  end
118
-
119
116
  end
@@ -1,9 +1,9 @@
1
1
  require File.expand_path('../../lib/clockwork', __FILE__)
2
- require 'test/unit'
2
+ require 'minitest/autorun'
3
3
  require 'mocha/setup'
4
4
 
5
- class ClockworkTest < Test::Unit::TestCase
6
- setup do
5
+ describe Clockwork do
6
+ before do
7
7
  @log_output = StringIO.new
8
8
  Clockwork.configure do |config|
9
9
  config[:sleep_timeout] = 0
@@ -11,11 +11,11 @@ class ClockworkTest < Test::Unit::TestCase
11
11
  end
12
12
  end
13
13
 
14
- teardown do
14
+ after do
15
15
  Clockwork.clear!
16
16
  end
17
17
 
18
- test 'should run events with configured logger' do
18
+ it 'should run events with configured logger' do
19
19
  run = false
20
20
  Clockwork.handler do |job|
21
21
  run = job == 'myjob'
@@ -23,11 +23,12 @@ class ClockworkTest < Test::Unit::TestCase
23
23
  Clockwork.every(1.minute, 'myjob')
24
24
  Clockwork.manager.expects(:loop).yields.then.returns
25
25
  Clockwork.run
26
+
26
27
  assert run
27
28
  assert @log_output.string.include?('Triggering')
28
29
  end
29
30
 
30
- test 'should log event correctly' do
31
+ it 'should log event correctly' do
31
32
  run = false
32
33
  Clockwork.handler do |job|
33
34
  run = job == 'an event'
@@ -39,7 +40,7 @@ class ClockworkTest < Test::Unit::TestCase
39
40
  assert @log_output.string.include?("Triggering 'an event'")
40
41
  end
41
42
 
42
- test 'should pass event without modification to handler' do
43
+ it 'should pass event without modification to handler' do
43
44
  event_object = Object.new
44
45
  run = false
45
46
  Clockwork.handler do |job|
@@ -51,7 +52,7 @@ class ClockworkTest < Test::Unit::TestCase
51
52
  assert run
52
53
  end
53
54
 
54
- test 'should not run anything after reset' do
55
+ it 'should not run anything after reset' do
55
56
  Clockwork.every(1.minute, 'myjob') { }
56
57
  Clockwork.clear!
57
58
  Clockwork.configure do |config|
@@ -63,7 +64,7 @@ class ClockworkTest < Test::Unit::TestCase
63
64
  assert @log_output.string.include?('0 events')
64
65
  end
65
66
 
66
- test 'should pass all arguments to every' do
67
+ it 'should pass all arguments to every' do
67
68
  Clockwork.every(1.second, 'myjob', if: lambda { |_| false }) { }
68
69
  Clockwork.manager.expects(:loop).yields.then.returns
69
70
  Clockwork.run
@@ -71,7 +72,7 @@ class ClockworkTest < Test::Unit::TestCase
71
72
  assert !@log_output.string.include?('Triggering')
72
73
  end
73
74
 
74
- test 'support module re-open style' do
75
+ it 'support module re-open style' do
75
76
  $called = false
76
77
  module ::Clockwork
77
78
  every(1.second, 'myjob') { $called = true }
@@ -1,297 +1,290 @@
1
- require 'test/unit'
1
+ require "minitest/autorun"
2
2
  require 'mocha/setup'
3
3
  require 'time'
4
4
  require 'active_support/time'
5
- require 'active_support/test_case'
6
5
 
7
6
  require_relative '../../lib/clockwork'
8
7
  require_relative '../../lib/clockwork/database_events'
9
8
  require_relative 'test_helpers'
10
9
 
11
- module DatabaseEvents
10
+ describe Clockwork::DatabaseEvents::SyncPerformer do
11
+ before do
12
+ @now = Time.now
13
+ DatabaseEventModel.delete_all
14
+ DatabaseEventModel2.delete_all
12
15
 
13
- class SyncPerformerTest < ActiveSupport::TestCase
14
-
15
- setup do
16
- @now = Time.now
17
- DatabaseEventModel.delete_all
18
- DatabaseEventModel2.delete_all
19
-
20
- Clockwork.manager = @manager = Clockwork::DatabaseEvents::Manager.new
21
- class << @manager
22
- def log(msg); end # silence log output
23
- end
16
+ Clockwork.manager = @manager = Clockwork::DatabaseEvents::Manager.new
17
+ class << @manager
18
+ def log(msg); end # silence log output
24
19
  end
20
+ end
25
21
 
26
- describe "setup" do
27
- setup do
28
- @subject = Clockwork::DatabaseEvents::SyncPerformer
29
- end
22
+ after do
23
+ Clockwork.clear!
24
+ end
30
25
 
31
- describe "arguments" do
32
- def test_does_not_raise_error_with_valid_arguments
33
- @subject.setup(model: DatabaseEventModel, every: 1.minute) {}
34
- end
26
+ describe "setup" do
27
+ before do
28
+ @subject = Clockwork::DatabaseEvents::SyncPerformer
29
+ end
35
30
 
36
- def test_raises_argument_error_if_model_is_not_set
37
- error = assert_raises KeyError do
38
- @subject.setup(every: 1.minute) {}
39
- end
40
- assert_equal error.message, ":model must be set to the model class"
31
+ describe "arguments" do
32
+ it 'raises argument error if model is not set' do
33
+ error = assert_raises KeyError do
34
+ @subject.setup(every: 1.minute) {}
41
35
  end
36
+ assert_equal error.message, ":model must be set to the model class"
37
+ end
42
38
 
43
- def test_raises_argument_error_if_every_is_not_set
44
- error = assert_raises KeyError do
45
- @subject.setup(model: DatabaseEventModel) {}
46
- end
47
- assert_equal error.message, ":every must be set to the database sync frequency"
39
+ it 'raises argument error if every is not set' do
40
+ error = assert_raises KeyError do
41
+ @subject.setup(model: DatabaseEventModel) {}
48
42
  end
43
+ assert_equal error.message, ":every must be set to the database sync frequency"
49
44
  end
45
+ end
50
46
 
51
- context "when database reload frequency is greater than model frequency period" do
52
- setup do
53
- @events_run = []
54
- @sync_frequency = 1.minute
55
- end
47
+ describe "when database reload frequency is greater than model frequency period" do
48
+ before do
49
+ @events_run = []
50
+ @sync_frequency = 1.minute
51
+ end
56
52
 
57
- def test_fetches_and_registers_event_from_database
58
- DatabaseEventModel.create(:frequency => 10)
59
- setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
53
+ it 'fetches and registers event from database' do
54
+ DatabaseEventModel.create(:frequency => 10)
55
+ setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
60
56
 
61
- tick_at(@now, :and_every_second_for => 1.second)
57
+ tick_at(@now, :and_every_second_for => 1.second)
62
58
 
63
- assert_equal ["DatabaseEventModel:1"], @events_run
64
- end
59
+ assert_equal ["DatabaseEventModel:1"], @events_run
60
+ end
65
61
 
66
- def test_multiple_events_from_database_can_be_registered
67
- DatabaseEventModel.create(:frequency => 10)
68
- DatabaseEventModel.create(:frequency => 10)
69
- setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
62
+ it 'fetches and registers multiple events from database' do
63
+ DatabaseEventModel.create(:frequency => 10)
64
+ DatabaseEventModel.create(:frequency => 10)
65
+ setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
70
66
 
71
- tick_at(@now, :and_every_second_for => 1.second)
67
+ tick_at(@now, :and_every_second_for => 1.second)
72
68
 
73
- assert_equal ["DatabaseEventModel:1", "DatabaseEventModel:2"], @events_run
74
- end
69
+ assert_equal ["DatabaseEventModel:1", "DatabaseEventModel:2"], @events_run
70
+ end
75
71
 
76
- def test_event_from_database_does_not_run_again_before_frequency_specified_in_database
77
- model = DatabaseEventModel.create(:frequency => 10)
78
- setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
72
+ it 'does not run event again before frequency specified in database' do
73
+ model = DatabaseEventModel.create(:frequency => 10)
74
+ setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
79
75
 
80
- tick_at(@now, :and_every_second_for => model.frequency - 1.second)
81
- assert_equal 1, @events_run.length
82
- end
76
+ tick_at(@now, :and_every_second_for => model.frequency - 1.second)
77
+ assert_equal 1, @events_run.length
78
+ end
83
79
 
84
- def test_event_from_database_runs_repeatedly_with_frequency_specified_in_database
85
- model = DatabaseEventModel.create(:frequency => 10)
86
- setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
80
+ it 'runs event repeatedly with frequency specified in database' do
81
+ model = DatabaseEventModel.create(:frequency => 10)
82
+ setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
87
83
 
88
- tick_at(@now, :and_every_second_for => (2 * model.frequency) + 1.second)
84
+ tick_at(@now, :and_every_second_for => (2 * model.frequency) + 1.second)
89
85
 
90
- assert_equal 3, @events_run.length
91
- end
86
+ assert_equal 3, @events_run.length
87
+ end
92
88
 
93
- def test_reloaded_events_from_database_run_repeatedly
94
- model = DatabaseEventModel.create(:frequency => 10)
95
- setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
89
+ it 'runs reloaded events from database repeatedly' do
90
+ model = DatabaseEventModel.create(:frequency => 10)
91
+ setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
96
92
 
97
- tick_at(@now, :and_every_second_for => @sync_frequency - 1)
98
- model.update(:name => "DatabaseEventModel:1:Reloaded")
99
- tick_at(@now + @sync_frequency, :and_every_second_for => model.frequency * 2)
93
+ tick_at(@now, :and_every_second_for => @sync_frequency - 1)
94
+ model.update(:name => "DatabaseEventModel:1:Reloaded")
95
+ tick_at(@now + @sync_frequency, :and_every_second_for => model.frequency * 2)
100
96
 
101
- assert_equal ["DatabaseEventModel:1:Reloaded", "DatabaseEventModel:1:Reloaded"], @events_run[-2..-1]
102
- end
97
+ assert_equal ["DatabaseEventModel:1:Reloaded", "DatabaseEventModel:1:Reloaded"], @events_run[-2..-1]
98
+ end
103
99
 
104
- def test_reloading_events_from_database_with_modified_frequency_will_run_with_new_frequency
105
- model = DatabaseEventModel.create(:frequency => 10)
106
- setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
100
+ it 'updates modified event frequency with event reloading' do
101
+ model = DatabaseEventModel.create(:frequency => 10)
102
+ setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
107
103
 
108
- tick_at(@now, :and_every_second_for => @sync_frequency - 1.second)
109
- model.update(:frequency => 5)
110
- tick_at(@now + @sync_frequency, :and_every_second_for => 6.seconds)
104
+ tick_at(@now, :and_every_second_for => @sync_frequency - 1.second)
105
+ model.update(:frequency => 5)
106
+ tick_at(@now + @sync_frequency, :and_every_second_for => 6.seconds)
111
107
 
112
- # model runs at: 1, 11, 21, 31, 41, 51 (6 runs)
113
- # database sync happens at: 60
114
- # modified model runs at: 61 (next tick after reload) and then 66 (2 runs)
115
- assert_equal 8, @events_run.length
116
- end
108
+ # model runs at: 1, 11, 21, 31, 41, 51 (6 runs)
109
+ # database sync happens at: 60
110
+ # modified model runs at: 61 (next tick after reload) and then 66 (2 runs)
111
+ assert_equal 8, @events_run.length
112
+ end
117
113
 
118
- def test_stops_running_deleted_events_from_database
119
- model = DatabaseEventModel.create(:frequency => 10)
120
- setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
114
+ it 'stoped running deleted events from database' do
115
+ model = DatabaseEventModel.create(:frequency => 10)
116
+ setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
121
117
 
122
- tick_at(@now, :and_every_second_for => (@sync_frequency - 1.second))
123
- before = @events_run.dup
124
- model.delete!
125
- tick_at(@now + @sync_frequency, :and_every_second_for => @sync_frequency)
126
- after = @events_run
118
+ tick_at(@now, :and_every_second_for => (@sync_frequency - 1.second))
119
+ before = @events_run.dup
120
+ model.delete!
121
+ tick_at(@now + @sync_frequency, :and_every_second_for => @sync_frequency)
122
+ after = @events_run
127
123
 
128
- assert_equal before, after
129
- end
124
+ assert_equal before, after
125
+ end
130
126
 
131
- def test_event_from_database_with_edited_name_switches_to_new_name
132
- model = DatabaseEventModel.create(:frequency => 10.seconds)
133
- setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
127
+ it 'updates event name with new name' do
128
+ model = DatabaseEventModel.create(:frequency => 10.seconds)
129
+ setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
134
130
 
135
- tick_at @now, :and_every_second_for => @sync_frequency - 1.second
136
- @events_run.clear
137
- model.update(:name => "DatabaseEventModel:1_modified")
138
- tick_at @now + @sync_frequency, :and_every_second_for => (model.frequency * 2)
131
+ tick_at @now, :and_every_second_for => @sync_frequency - 1.second
132
+ @events_run.clear
133
+ model.update(:name => "DatabaseEventModel:1_modified")
134
+ tick_at @now + @sync_frequency, :and_every_second_for => (model.frequency * 2)
139
135
 
140
- assert_equal ["DatabaseEventModel:1_modified", "DatabaseEventModel:1_modified"], @events_run
141
- end
136
+ assert_equal ["DatabaseEventModel:1_modified", "DatabaseEventModel:1_modified"], @events_run
137
+ end
142
138
 
143
- def test_event_from_database_with_edited_frequency_switches_to_new_frequency
144
- model = DatabaseEventModel.create(:frequency => 10)
145
- setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
139
+ it 'updates event frequency with new frequency' do
140
+ model = DatabaseEventModel.create(:frequency => 10)
141
+ setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
146
142
 
147
- tick_at @now, :and_every_second_for => @sync_frequency - 1.second
148
- @events_run.clear
149
- model.update(:frequency => 30)
150
- tick_at @now + @sync_frequency, :and_every_second_for => @sync_frequency - 1.seconds
143
+ tick_at @now, :and_every_second_for => @sync_frequency - 1.second
144
+ @events_run.clear
145
+ model.update(:frequency => 30)
146
+ tick_at @now + @sync_frequency, :and_every_second_for => @sync_frequency - 1.seconds
151
147
 
152
- assert_equal 2, @events_run.length
153
- end
148
+ assert_equal 2, @events_run.length
149
+ end
154
150
 
155
- def test_event_from_database_with_edited_at_runs_at_new_at
156
- model = DatabaseEventModel.create(:frequency => 1.day, :at => '10:30')
157
- setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
151
+ it 'updates event at with new at' do
152
+ model = DatabaseEventModel.create(:frequency => 1.day, :at => '10:30')
153
+ setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
158
154
 
159
- assert_will_run 'jan 1 2010 10:30:00'
160
- assert_wont_run 'jan 1 2010 09:30:00'
155
+ assert_will_run 'jan 1 2010 10:30:00'
156
+ assert_wont_run 'jan 1 2010 09:30:00'
161
157
 
162
- model.update(:at => '09:30')
163
- tick_at @now, :and_every_second_for => @sync_frequency + 1.second
158
+ model.update(:at => '09:30')
159
+ tick_at @now, :and_every_second_for => @sync_frequency + 1.second
164
160
 
165
- assert_will_run 'jan 1 2010 09:30:00'
166
- assert_wont_run 'jan 1 2010 10:30:00'
167
- end
161
+ assert_will_run 'jan 1 2010 09:30:00'
162
+ assert_wont_run 'jan 1 2010 10:30:00'
163
+ end
168
164
 
169
- context "when #name is defined" do
170
- def test_daily_event_from_database_with_at_should_only_run_once
171
- DatabaseEventModel.create(:frequency => 1.day, :at => next_minute(@now).strftime('%H:%M'))
172
- setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
165
+ describe "when #name is defined" do
166
+ it 'runs daily event with at from databse only once' do
167
+ DatabaseEventModel.create(:frequency => 1.day, :at => next_minute(@now).strftime('%H:%M'))
168
+ setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
173
169
 
174
- # tick from now, though specified :at time
175
- tick_at(@now, :and_every_second_for => (2 * @sync_frequency) + 1.second)
170
+ # tick from now, though specified :at time
171
+ tick_at(@now, :and_every_second_for => (2 * @sync_frequency) + 1.second)
176
172
 
177
- assert_equal 1, @events_run.length
178
- end
173
+ assert_equal 1, @events_run.length
179
174
  end
175
+ end
180
176
 
181
- context "when #name is not defined" do
182
-
183
- def test_daily_event_from_database_with_at_should_only_run_once
184
- DatabaseEventModelWithoutName.create(:frequency => 1.day, :at => next_minute(next_minute(@now)).strftime('%H:%M'))
185
- setup_sync(model: DatabaseEventModelWithoutName, :every => @sync_frequency, :events_run => @events_run)
186
-
187
- # tick from now, though specified :at time
188
- tick_at(@now, :and_every_second_for => (2 * @sync_frequency) + 1.second)
177
+ describe "when #name is not defined" do
178
+ it 'runs daily event with at from databse only once' do
179
+ DatabaseEventModelWithoutName.create(:frequency => 1.day, :at => next_minute(next_minute(@now)).strftime('%H:%M'))
180
+ setup_sync(model: DatabaseEventModelWithoutName, :every => @sync_frequency, :events_run => @events_run)
189
181
 
190
- assert_equal 1, @events_run.length
191
- end
182
+ # tick from now, though specified :at time
183
+ tick_at(@now, :and_every_second_for => (2 * @sync_frequency) + 1.second)
192
184
 
185
+ assert_equal 1, @events_run.length
193
186
  end
187
+ end
194
188
 
195
- def test_event_from_database_with_comma_separated_at_leads_to_multiple_event_ats
196
- DatabaseEventModel.create(:frequency => 1.day, :at => '16:20, 18:10')
197
- setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
189
+ it 'creates multiple event ats with comma separated at string' do
190
+ DatabaseEventModel.create(:frequency => 1.day, :at => '16:20, 18:10')
191
+ setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
198
192
 
199
- tick_at @now, :and_every_second_for => 1.second
193
+ tick_at @now, :and_every_second_for => 1.second
200
194
 
201
- assert_wont_run 'jan 1 2010 16:19:59'
202
- assert_will_run 'jan 1 2010 16:20:00'
203
- assert_wont_run 'jan 1 2010 16:20:01'
195
+ assert_wont_run 'jan 1 2010 16:19:59'
196
+ assert_will_run 'jan 1 2010 16:20:00'
197
+ assert_wont_run 'jan 1 2010 16:20:01'
204
198
 
205
- assert_wont_run 'jan 1 2010 18:09:59'
206
- assert_will_run 'jan 1 2010 18:10:00'
207
- assert_wont_run 'jan 1 2010 18:10:01'
208
- end
199
+ assert_wont_run 'jan 1 2010 18:09:59'
200
+ assert_will_run 'jan 1 2010 18:10:00'
201
+ assert_wont_run 'jan 1 2010 18:10:01'
202
+ end
209
203
 
210
- def test_syncing_multiple_database_models_works
211
- DatabaseEventModel.create(:frequency => 10)
212
- setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
204
+ it 'allows syncing multiple database models' do
205
+ DatabaseEventModel.create(:frequency => 10)
206
+ setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
213
207
 
214
- DatabaseEventModel2.create(:frequency => 10)
215
- setup_sync(model: DatabaseEventModel2, :every => @sync_frequency, :events_run => @events_run)
208
+ DatabaseEventModel2.create(:frequency => 10)
209
+ setup_sync(model: DatabaseEventModel2, :every => @sync_frequency, :events_run => @events_run)
216
210
 
217
- tick_at(@now, :and_every_second_for => 1.second)
211
+ tick_at(@now, :and_every_second_for => 1.second)
218
212
 
219
- assert_equal ["DatabaseEventModel:1", "DatabaseEventModel2:1"], @events_run
220
- end
213
+ assert_equal ["DatabaseEventModel:1", "DatabaseEventModel2:1"], @events_run
221
214
  end
215
+ end
222
216
 
223
- context "when database reload frequency is less than model frequency period" do
224
- setup do
225
- @events_run = []
226
- end
217
+ describe "when database reload frequency is less than model frequency period" do
218
+ before do
219
+ @events_run = []
220
+ end
227
221
 
228
- def test_the_event_only_runs_once_within_the_model_frequency_period
229
- DatabaseEventModel.create(:frequency => 5.minutes)
230
- setup_sync(model: DatabaseEventModel, :every => 1.minute, :events_run => @events_run)
222
+ it 'runs event only once within the model frequency period' do
223
+ DatabaseEventModel.create(:frequency => 5.minutes)
224
+ setup_sync(model: DatabaseEventModel, :every => 1.minute, :events_run => @events_run)
231
225
 
232
- tick_at(@now, :and_every_second_for => 5.minutes)
226
+ tick_at(@now, :and_every_second_for => 5.minutes)
233
227
 
234
- assert_equal 1, @events_run.length
235
- end
228
+ assert_equal 1, @events_run.length
236
229
  end
230
+ end
237
231
 
238
- context "with database event with :at as empty string" do
239
- setup do
240
- @events_run = []
232
+ describe "with database event :at set to empty string" do
233
+ before do
234
+ @events_run = []
241
235
 
242
- DatabaseEventModel.create(:frequency => 10)
243
- setup_sync(model: DatabaseEventModel, :every => 1.minute, :events_run => @events_run)
244
- end
236
+ DatabaseEventModel.create(:frequency => 10)
237
+ setup_sync(model: DatabaseEventModel, :every => 1.minute, :events_run => @events_run)
238
+ end
245
239
 
246
- def test_it_does_not_raise_an_error
247
- begin
248
- tick_at(Time.now, :and_every_second_for => 10.seconds)
249
- rescue => e
250
- assert false, "Raised an error: #{e.message}"
251
- end
240
+ it 'does not raise an error' do
241
+ begin
242
+ tick_at(Time.now, :and_every_second_for => 10.seconds)
243
+ rescue => e
244
+ assert false, "Raised an error: #{e.message}"
252
245
  end
246
+ end
253
247
 
254
- def test_the_event_runs
255
- begin
256
- tick_at(Time.now, :and_every_second_for => 10.seconds)
257
- rescue => e
258
- end
259
- assert_equal 1, @events_run.length
248
+ it 'runs the event' do
249
+ begin
250
+ tick_at(Time.now, :and_every_second_for => 10.seconds)
251
+ rescue
260
252
  end
253
+ assert_equal 1, @events_run.length
261
254
  end
255
+ end
262
256
 
263
- context "with task that respond to `tz`" do
264
- setup do
265
- @events_run = []
266
- @utc_time_now = Time.now.utc
257
+ describe "with task that responds to `tz`" do
258
+ before do
259
+ @events_run = []
260
+ @utc_time_now = Time.now.utc
267
261
 
268
- DatabaseEventModel.create(:frequency => 1.days, :at => @utc_time_now.strftime('%H:%M'), :tz => 'America/Montreal')
269
- setup_sync(model: DatabaseEventModel, :every => 1.minute, :events_run => @events_run)
270
- end
262
+ DatabaseEventModel.create(:frequency => 1.days, :at => @utc_time_now.strftime('%H:%M'), :tz => 'America/Montreal')
263
+ setup_sync(model: DatabaseEventModel, :every => 1.minute, :events_run => @events_run)
264
+ end
271
265
 
272
- def test_it_does_not_raise_an_error
273
- begin
274
- tick_at(@utc_time_now, :and_every_second_for => 10.seconds)
275
- rescue => e
276
- assert false, "Raised an error: #{e.message}"
277
- end
266
+ it 'does not raise an error' do
267
+ begin
268
+ tick_at(@utc_time_now, :and_every_second_for => 10.seconds)
269
+ rescue => e
270
+ assert false, "Raised an error: #{e.message}"
278
271
  end
272
+ end
279
273
 
280
- def test_it_do_not_runs_the_task_as_utc
281
- begin
282
- tick_at(@utc_time_now, :and_every_second_for => 3.hours)
283
- rescue => e
284
- end
285
- assert_equal 0, @events_run.length
274
+ it 'does not run the event based on UTC' do
275
+ begin
276
+ tick_at(@utc_time_now, :and_every_second_for => 3.hours)
277
+ rescue
286
278
  end
279
+ assert_equal 0, @events_run.length
280
+ end
287
281
 
288
- def test_it_does_runs_the_task_as_est
289
- begin
290
- tick_at(@utc_time_now, :and_every_second_for => 5.hours)
291
- rescue => e
292
- end
293
- assert_equal 1, @events_run.length
282
+ it 'runs the event based on America/Montreal tz' do
283
+ begin
284
+ tick_at(@utc_time_now, :and_every_second_for => 5.hours)
285
+ rescue
294
286
  end
287
+ assert_equal 1, @events_run.length
295
288
  end
296
289
  end
297
290
  end
@@ -1,34 +1,34 @@
1
1
  require File.expand_path('../../lib/clockwork', __FILE__)
2
- require 'active_support/test_case'
2
+ require "minitest/autorun"
3
3
 
4
- class EventTest < ActiveSupport::TestCase
5
- describe "#thread?" do
6
- setup do
7
- @manager = mock
4
+ describe Clockwork::Event do
5
+ describe '#thread?' do
6
+ before do
7
+ @manager = Class.new
8
8
  end
9
9
 
10
- describe "manager config thread option set to true" do
11
- setup do
10
+ describe 'manager config thread option set to true' do
11
+ before do
12
12
  @manager.stubs(:config).returns({ :thread => true })
13
13
  end
14
14
 
15
- test "is true" do
15
+ it 'is true' do
16
16
  event = Clockwork::Event.new(@manager, nil, nil, nil)
17
17
  assert_equal true, event.thread?
18
18
  end
19
19
 
20
- test "is false when event thread option set" do
20
+ it 'is false when event thread option set' do
21
21
  event = Clockwork::Event.new(@manager, nil, nil, nil, :thread => false)
22
22
  assert_equal false, event.thread?
23
23
  end
24
24
  end
25
25
 
26
- describe "manager config thread option not set" do
27
- setup do
26
+ describe 'manager config thread option not set' do
27
+ before do
28
28
  @manager.stubs(:config).returns({})
29
29
  end
30
30
 
31
- test "is true if event thread option is true" do
31
+ it 'is true if event thread option is true' do
32
32
  event = Clockwork::Event.new(@manager, nil, nil, nil, :thread => true)
33
33
  assert_equal true, event.thread?
34
34
  end
@@ -1,13 +1,11 @@
1
1
  require File.expand_path('../../lib/clockwork', __FILE__)
2
- require 'rubygems'
3
- require 'test/unit'
2
+ require "minitest/autorun"
4
3
  require 'mocha/setup'
5
4
  require 'time'
6
5
  require 'active_support/time'
7
- require 'active_support/test_case'
8
6
 
9
- class ManagerTest < ActiveSupport::TestCase
10
- setup do
7
+ describe Clockwork::Manager do
8
+ before do
11
9
  @manager = Clockwork::Manager.new
12
10
  class << @manager
13
11
  def log(msg); end
@@ -29,7 +27,7 @@ class ManagerTest < ActiveSupport::TestCase
29
27
  assert_equal 0, @manager.tick(t).size
30
28
  end
31
29
 
32
- test "once a minute" do
30
+ it "once a minute" do
33
31
  @manager.every(1.minute, 'myjob')
34
32
 
35
33
  assert_will_run(t=Time.now)
@@ -37,7 +35,7 @@ class ManagerTest < ActiveSupport::TestCase
37
35
  assert_will_run(t+60)
38
36
  end
39
37
 
40
- test "every three minutes" do
38
+ it "every three minutes" do
41
39
  @manager.every(3.minutes, 'myjob')
42
40
 
43
41
  assert_will_run(t=Time.now)
@@ -45,7 +43,7 @@ class ManagerTest < ActiveSupport::TestCase
45
43
  assert_will_run(t+3*60)
46
44
  end
47
45
 
48
- test "once an hour" do
46
+ it "once an hour" do
49
47
  @manager.every(1.hour, 'myjob')
50
48
 
51
49
  assert_will_run(t=Time.now)
@@ -53,7 +51,7 @@ class ManagerTest < ActiveSupport::TestCase
53
51
  assert_will_run(t+60*60)
54
52
  end
55
53
 
56
- test "once a week" do
54
+ it "once a week" do
57
55
  @manager.every(1.week, 'myjob')
58
56
 
59
57
  assert_will_run(t=Time.now)
@@ -61,7 +59,7 @@ class ManagerTest < ActiveSupport::TestCase
61
59
  assert_will_run(t+60*60*24*7)
62
60
  end
63
61
 
64
- test "won't drift later and later" do
62
+ it "won't drift later and later" do
65
63
  @manager.every(1.hour, 'myjob')
66
64
 
67
65
  assert_will_run(Time.parse("10:00:00.5"))
@@ -69,20 +67,20 @@ class ManagerTest < ActiveSupport::TestCase
69
67
  assert_will_run(Time.parse("11:00:00.0"))
70
68
  end
71
69
 
72
- test "aborts when no handler defined" do
70
+ it "aborts when no handler defined" do
73
71
  manager = Clockwork::Manager.new
74
- assert_raise(Clockwork::Manager::NoHandlerDefined) do
72
+ assert_raises(Clockwork::Manager::NoHandlerDefined) do
75
73
  manager.every(1.minute, 'myjob')
76
74
  end
77
75
  end
78
76
 
79
- test "aborts when fails to parse" do
80
- assert_raise(Clockwork::At::FailedToParse) do
77
+ it "aborts when fails to parse" do
78
+ assert_raises(Clockwork::At::FailedToParse) do
81
79
  @manager.every(1.day, "myjob", :at => "a:bc")
82
80
  end
83
81
  end
84
82
 
85
- test "general handler" do
83
+ it "general handler" do
86
84
  $set_me = 0
87
85
  @manager.handler { $set_me = 1 }
88
86
  @manager.every(1.minute, 'myjob')
@@ -90,7 +88,7 @@ class ManagerTest < ActiveSupport::TestCase
90
88
  assert_equal 1, $set_me
91
89
  end
92
90
 
93
- test "event-specific handler" do
91
+ it "event-specific handler" do
94
92
  $set_me = 0
95
93
  @manager.every(1.minute, 'myjob') { $set_me = 2 }
96
94
  @manager.tick(Time.now)
@@ -98,7 +96,7 @@ class ManagerTest < ActiveSupport::TestCase
98
96
  assert_equal 2, $set_me
99
97
  end
100
98
 
101
- test "should pass time to the general handler" do
99
+ it "should pass time to the general handler" do
102
100
  received = nil
103
101
  now = Time.now
104
102
  @manager.handler { |job, time| received = time }
@@ -107,7 +105,7 @@ class ManagerTest < ActiveSupport::TestCase
107
105
  assert_equal now, received
108
106
  end
109
107
 
110
- test "should pass time to the event-specific handler" do
108
+ it "should pass time to the event-specific handler" do
111
109
  received = nil
112
110
  now = Time.now
113
111
  @manager.every(1.minute, 'myjob') { |job, time| received = time }
@@ -115,20 +113,18 @@ class ManagerTest < ActiveSupport::TestCase
115
113
  assert_equal now, received
116
114
  end
117
115
 
118
- test "exceptions are trapped and logged" do
116
+ it "exceptions are trapped and logged" do
119
117
  @manager.handler { raise 'boom' }
120
118
  @manager.every(1.minute, 'myjob')
121
119
 
122
- logger = Logger.new(StringIO.new)
123
- @manager.configure { |c| c[:logger] = logger }
124
- logger.expects(:error)
125
-
126
- assert_nothing_raised do
127
- @manager.tick(Time.now)
128
- end
120
+ mocked_logger = MiniTest::Mock.new
121
+ mocked_logger.expect :error, true, [RuntimeError]
122
+ @manager.configure { |c| c[:logger] = mocked_logger }
123
+ @manager.tick(Time.now)
124
+ mocked_logger.verify
129
125
  end
130
126
 
131
- test "exceptions still set the last timestamp to avoid spastic error loops" do
127
+ it "exceptions still set the last timestamp to avoid spastic error loops" do
132
128
  @manager.handler { raise 'boom' }
133
129
  event = @manager.every(1.minute, 'myjob')
134
130
  @manager.stubs(:log_error)
@@ -136,7 +132,7 @@ class ManagerTest < ActiveSupport::TestCase
136
132
  assert_equal t, event.last
137
133
  end
138
134
 
139
- test "should be configurable" do
135
+ it "should be configurable" do
140
136
  @manager.configure do |config|
141
137
  config[:sleep_timeout] = 200
142
138
  config[:logger] = "A Logger"
@@ -150,25 +146,25 @@ class ManagerTest < ActiveSupport::TestCase
150
146
  assert_equal true, @manager.config[:thread]
151
147
  end
152
148
 
153
- test "configuration should have reasonable defaults" do
149
+ it "configuration should have reasonable defaults" do
154
150
  assert_equal 1, @manager.config[:sleep_timeout]
155
151
  assert @manager.config[:logger].is_a?(Logger)
156
152
  assert_equal 10, @manager.config[:max_threads]
157
153
  assert_equal false, @manager.config[:thread]
158
154
  end
159
155
 
160
- test "should accept unnamed job" do
156
+ it "should accept unnamed job" do
161
157
  event = @manager.every(1.minute)
162
158
  assert_equal 'unnamed', event.job
163
159
  end
164
160
 
165
- test "should accept options without job name" do
161
+ it "should accept options without job name" do
166
162
  event = @manager.every(1.minute, {})
167
163
  assert_equal 'unnamed', event.job
168
164
  end
169
165
 
170
166
  describe ':at option' do
171
- test "once a day at 16:20" do
167
+ it "once a day at 16:20" do
172
168
  @manager.every(1.day, 'myjob', :at => '16:20')
173
169
 
174
170
  assert_wont_run 'jan 1 2010 16:19:59'
@@ -178,7 +174,7 @@ class ManagerTest < ActiveSupport::TestCase
178
174
  assert_will_run 'jan 2 2010 16:20:00'
179
175
  end
180
176
 
181
- test "twice a day at 16:20 and 18:10" do
177
+ it "twice a day at 16:20 and 18:10" do
182
178
  @manager.every(1.day, 'myjob', :at => ['16:20', '18:10'])
183
179
 
184
180
  assert_wont_run 'jan 1 2010 16:19:59'
@@ -192,18 +188,18 @@ class ManagerTest < ActiveSupport::TestCase
192
188
  end
193
189
 
194
190
  describe ':tz option' do
195
- test "time zone is not set by default" do
191
+ it "time zone is not set by default" do
196
192
  assert @manager.config[:tz].nil?
197
193
  end
198
194
 
199
- test "should be able to specify a different timezone than local" do
195
+ it "should be able to specify a different timezone than local" do
200
196
  @manager.every(1.day, 'myjob', :at => '10:00', :tz => 'UTC')
201
197
 
202
198
  assert_wont_run 'jan 1 2010 10:00:00 EST'
203
199
  assert_will_run 'jan 1 2010 10:00:00 UTC'
204
200
  end
205
201
 
206
- test "should be able to specify a different timezone than local for multiple times" do
202
+ it "should be able to specify a different timezone than local for multiple times" do
207
203
  @manager.every(1.day, 'myjob', :at => ['10:00', '8:00'], :tz => 'UTC')
208
204
 
209
205
  assert_wont_run 'jan 1 2010 08:00:00 EST'
@@ -212,7 +208,7 @@ class ManagerTest < ActiveSupport::TestCase
212
208
  assert_will_run 'jan 1 2010 10:00:00 UTC'
213
209
  end
214
210
 
215
- test "should be able to configure a default timezone to use for all events" do
211
+ it "should be able to configure a default timezone to use for all events" do
216
212
  @manager.configure { |config| config[:tz] = 'UTC' }
217
213
  @manager.every(1.day, 'myjob', :at => '10:00')
218
214
 
@@ -220,7 +216,7 @@ class ManagerTest < ActiveSupport::TestCase
220
216
  assert_will_run 'jan 1 2010 10:00:00 UTC'
221
217
  end
222
218
 
223
- test "should be able to override a default timezone in an event" do
219
+ it "should be able to override a default timezone in an event" do
224
220
  @manager.configure { |config| config[:tz] = 'UTC' }
225
221
  @manager.every(1.day, 'myjob', :at => '10:00', :tz => 'EST')
226
222
 
@@ -230,19 +226,19 @@ class ManagerTest < ActiveSupport::TestCase
230
226
  end
231
227
 
232
228
  describe ':if option' do
233
- test ":if true then always run" do
229
+ it ":if true then always run" do
234
230
  @manager.every(1.second, 'myjob', :if => lambda { |_| true })
235
231
 
236
232
  assert_will_run 'jan 1 2010 16:20:00'
237
233
  end
238
234
 
239
- test ":if false then never run" do
235
+ it ":if false then never run" do
240
236
  @manager.every(1.second, 'myjob', :if => lambda { |_| false })
241
237
 
242
238
  assert_wont_run 'jan 1 2010 16:20:00'
243
239
  end
244
240
 
245
- test ":if the first day of month" do
241
+ it ":if the first day of month" do
246
242
  @manager.every(1.second, 'myjob', :if => lambda { |t| t.day == 1 })
247
243
 
248
244
  assert_will_run 'jan 1 2010 16:20:00'
@@ -250,7 +246,7 @@ class ManagerTest < ActiveSupport::TestCase
250
246
  assert_will_run 'feb 1 2010 16:20:00'
251
247
  end
252
248
 
253
- test ":if it is compared to a time with zone" do
249
+ it ":if it is compared to a time with zone" do
254
250
  tz = 'America/Chicago'
255
251
  time = Time.utc(2012,5,25,10,00)
256
252
  @manager.every(1.second, 'myjob', tz: tz, :if => lambda { |t|
@@ -259,15 +255,15 @@ class ManagerTest < ActiveSupport::TestCase
259
255
  assert_will_run time
260
256
  end
261
257
 
262
- test ":if is not callable then raise ArgumentError" do
263
- assert_raise(ArgumentError) do
258
+ it ":if is not callable then raise ArgumentError" do
259
+ assert_raises(ArgumentError) do
264
260
  @manager.every(1.second, 'myjob', :if => true)
265
261
  end
266
262
  end
267
263
  end
268
264
 
269
265
  describe "max_threads" do
270
- test "should warn when an event tries to generate threads more than max_threads" do
266
+ it "should warn when an event tries to generate threads more than max_threads" do
271
267
  logger = Logger.new(STDOUT)
272
268
  @manager.configure do |config|
273
269
  config[:max_threads] = 1
@@ -281,7 +277,7 @@ class ManagerTest < ActiveSupport::TestCase
281
277
  @manager.tick(Time.now)
282
278
  end
283
279
 
284
- test "should not warn when thread is managed by others" do
280
+ it "should not warn when thread is managed by others" do
285
281
  begin
286
282
  t = Thread.new { sleep 5 }
287
283
  logger = Logger.new(StringIO.new)
@@ -301,15 +297,15 @@ class ManagerTest < ActiveSupport::TestCase
301
297
  end
302
298
 
303
299
  describe "callbacks" do
304
- test "should not accept unknown callback name" do
305
- assert_raise(RuntimeError, "Unsupported callback unknown_callback") do
300
+ it "should not accept unknown callback name" do
301
+ assert_raises(RuntimeError, "Unsupported callback unknown_callback") do
306
302
  @manager.on(:unknown_callback) do
307
303
  true
308
304
  end
309
305
  end
310
306
  end
311
307
 
312
- test "should run before_tick callback once on tick" do
308
+ it "should run before_tick callback once on tick" do
313
309
  counter = 0
314
310
  @manager.on(:before_tick) do
315
311
  counter += 1
@@ -318,7 +314,7 @@ class ManagerTest < ActiveSupport::TestCase
318
314
  assert_equal 1, counter
319
315
  end
320
316
 
321
- test "should not run events if before_tick returns false" do
317
+ it "should not run events if before_tick returns false" do
322
318
  @manager.on(:before_tick) do
323
319
  false
324
320
  end
@@ -326,7 +322,7 @@ class ManagerTest < ActiveSupport::TestCase
326
322
  @manager.tick
327
323
  end
328
324
 
329
- test "should run before_run twice if two events are registered" do
325
+ it "should run before_run twice if two events are registered" do
330
326
  counter = 0
331
327
  @manager.on(:before_run) do
332
328
  counter += 1
@@ -337,7 +333,7 @@ class ManagerTest < ActiveSupport::TestCase
337
333
  assert_equal 2, counter
338
334
  end
339
335
 
340
- test "should run even jobs only" do
336
+ it "should run even jobs only" do
341
337
  counter = 0
342
338
  ran = false
343
339
  @manager.on(:before_run) do
@@ -350,7 +346,7 @@ class ManagerTest < ActiveSupport::TestCase
350
346
  assert ran
351
347
  end
352
348
 
353
- test "should run after_run callback for each event" do
349
+ it "should run after_run callback for each event" do
354
350
  counter = 0
355
351
  @manager.on(:after_run) do
356
352
  counter += 1
@@ -361,7 +357,7 @@ class ManagerTest < ActiveSupport::TestCase
361
357
  assert_equal 2, counter
362
358
  end
363
359
 
364
- test "should run after_tick callback once" do
360
+ it "should run after_tick callback once" do
365
361
  counter = 0
366
362
  @manager.on(:after_tick) do
367
363
  counter += 1
@@ -372,7 +368,7 @@ class ManagerTest < ActiveSupport::TestCase
372
368
  end
373
369
 
374
370
  describe 'error_handler' do
375
- setup do
371
+ before do
376
372
  @errors = []
377
373
  @manager.error_handler do |e|
378
374
  @errors << e
@@ -383,24 +379,24 @@ class ManagerTest < ActiveSupport::TestCase
383
379
  @manager.configure do |config|
384
380
  config[:logger] = Logger.new(@string_io)
385
381
  end
386
- @manager.every(1.second, 'myjob') { raise 'test error' }
382
+ @manager.every(1.second, 'myjob') { raise 'it error' }
387
383
  end
388
384
 
389
- test 'registered error_handler handles error from event' do
385
+ it 'registered error_handler handles error from event' do
390
386
  @manager.tick
391
- assert_equal ['test error'], @errors.map(&:message)
387
+ assert_equal ['it error'], @errors.map(&:message)
392
388
  end
393
389
 
394
- test 'error is notified to logger and handler' do
390
+ it 'error is notified to logger and handler' do
395
391
  @manager.tick
396
- assert @string_io.string.include?('test error')
392
+ assert @string_io.string.include?('it error')
397
393
  end
398
394
 
399
- test 'error in handler will NOT be suppressed' do
395
+ it 'error in handler will NOT be suppressed' do
400
396
  @manager.error_handler do |e|
401
397
  raise e.message + ' re-raised'
402
398
  end
403
- assert_raise(RuntimeError, 'test error re-raised') do
399
+ assert_raises(RuntimeError, 'it error re-raised') do
404
400
  @manager.tick
405
401
  end
406
402
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clockwork
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Wiggins
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-14 00:00:00.000000000 Z
12
+ date: 2016-04-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tzinfo
@@ -81,34 +81,20 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
- - !ruby/object:Gem::Dependency
85
- name: test-unit
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: '0'
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: '0'
98
84
  - !ruby/object:Gem::Dependency
99
85
  name: minitest
100
86
  requirement: !ruby/object:Gem::Requirement
101
87
  requirements:
102
88
  - - "~>"
103
89
  - !ruby/object:Gem::Version
104
- version: '4.0'
90
+ version: '5.8'
105
91
  type: :development
106
92
  prerelease: false
107
93
  version_requirements: !ruby/object:Gem::Requirement
108
94
  requirements:
109
95
  - - "~>"
110
96
  - !ruby/object:Gem::Version
111
- version: '4.0'
97
+ version: '5.8'
112
98
  - !ruby/object:Gem::Dependency
113
99
  name: mocha
114
100
  requirement: !ruby/object:Gem::Requirement
@@ -184,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
170
  version: '0'
185
171
  requirements: []
186
172
  rubyforge_project:
187
- rubygems_version: 2.2.2
173
+ rubygems_version: 2.5.1
188
174
  signing_key:
189
175
  specification_version: 4
190
176
  summary: A scheduler process to replace cron.