mirror of
https://github.com/plashchynski/crono.git
synced 2026-03-27 03:41:38 +01:00
Add rake task to check cronotab.rb syntax
This commit is contained in:
12
spec/assets/bad_cronotab.rb
Normal file
12
spec/assets/bad_cronotab.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
# This is an example of a bad cronotab for tests
|
||||
|
||||
class TestJob
|
||||
def perform
|
||||
puts 'Test!'
|
||||
end
|
||||
end
|
||||
|
||||
# This is an error, because you can use `on` options with
|
||||
# a period less than 7 days.
|
||||
|
||||
Crono.perform(TestJob).every 5.days, on: :sunday
|
||||
9
spec/assets/good_cronotab.rb
Normal file
9
spec/assets/good_cronotab.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
# This is an example of a good cronotab for tests
|
||||
|
||||
class TestJob
|
||||
def perform
|
||||
puts 'Test!'
|
||||
end
|
||||
end
|
||||
|
||||
Crono.perform(TestJob).every 5.seconds
|
||||
@@ -4,11 +4,20 @@ require 'rake'
|
||||
load 'tasks/crono_tasks.rake'
|
||||
Rake::Task.define_task(:environment)
|
||||
|
||||
describe 'crono:clean' do
|
||||
it 'should clean unused tasks from DB' do
|
||||
Crono::CronoJob.create!(job_id: 'used_job')
|
||||
expect(Crono).to receive(:load_cronotab)
|
||||
Rake::Task['crono:clean'].invoke
|
||||
expect(Crono::CronoJob.where(job_id: 'used_job')).not_to exist
|
||||
describe 'rake' do
|
||||
describe 'crono:clean' do
|
||||
it 'should clean unused tasks from DB' do
|
||||
Crono::CronoJob.create!(job_id: 'used_job')
|
||||
ENV['CRONOTAB'] = File.expand_path('../../assets/good_cronotab.rb', __FILE__)
|
||||
Rake::Task['crono:clean'].invoke
|
||||
expect(Crono::CronoJob.where(job_id: 'used_job')).not_to exist
|
||||
end
|
||||
end
|
||||
|
||||
describe 'crono:check' do
|
||||
it 'should check cronotab syntax' do
|
||||
ENV['CRONOTAB'] = File.expand_path('../../assets/bad_cronotab.rb', __FILE__)
|
||||
expect { Rake::Task['crono:check'].invoke }.to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,6 +6,7 @@ describe Crono::Web do
|
||||
let(:app) { Crono::Web }
|
||||
|
||||
before do
|
||||
Crono::CronoJob.destroy_all
|
||||
@test_job_id = 'Perform TestJob every 5 seconds'
|
||||
@test_job_log = 'All runs ok'
|
||||
@test_job = Crono::CronoJob.create!(
|
||||
|
||||
Reference in New Issue
Block a user