Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions clockwork.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Gem::Specification.new do |s|
s.add_development_dependency "bundler", "~> 1.3"
s.add_development_dependency "rake"
s.add_development_dependency "daemons"
s.add_development_dependency "test-unit"
s.add_development_dependency "minitest", "~> 4.0"
s.add_development_dependency "minitest", "~> 5.8"
s.add_development_dependency "mocha"
end
1 change: 1 addition & 0 deletions gemfiles/activesupport4.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ platforms :rbx do
end

gem 'activesupport', '~> 4.0.0'
gem 'minitest', '~> 4.2'
gemspec :path=>"../"
42 changes: 20 additions & 22 deletions test/at_test.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
require File.expand_path('../../lib/clockwork', __FILE__)
require 'rubygems'
require 'test/unit'
require 'mocha/setup'
require 'time'
require 'active_support/time'
require 'active_support/test_case'
require "minitest/autorun"

class AtTest < ActiveSupport::TestCase
describe 'Clockwork::At' do
def time_in_day(hour, minute)
Time.new(2013, 1, 1, hour, minute, 0)
end

test '16:20' do
it '16:20' do
at = Clockwork::At.parse('16:20')
assert !at.ready?(time_in_day(16, 19))
assert at.ready?(time_in_day(16, 20))
assert !at.ready?(time_in_day(16, 21))
end

test '8:20' do
it '8:20' do
at = Clockwork::At.parse('8:20')
assert !at.ready?(time_in_day(8, 19))
assert at.ready?(time_in_day(8, 20))
assert !at.ready?(time_in_day(8, 21))
end

test '**:20 with two stars' do
it '**:20 with two stars' do
at = Clockwork::At.parse('**:20')

assert !at.ready?(time_in_day(15, 19))
Expand All @@ -37,7 +36,7 @@ def time_in_day(hour, minute)
assert !at.ready?(time_in_day(16, 21))
end

test '*:20 with one star' do
it '*:20 with one star' do
at = Clockwork::At.parse('*:20')

assert !at.ready?(time_in_day(15, 19))
Expand All @@ -49,7 +48,7 @@ def time_in_day(hour, minute)
assert !at.ready?(time_in_day(16, 21))
end

test '16:**' do
it '16:**' do
at = Clockwork::At.parse('16:**')

assert !at.ready?(time_in_day(15, 59))
Expand All @@ -59,7 +58,7 @@ def time_in_day(hour, minute)
assert !at.ready?(time_in_day(17, 00))
end

test '8:**' do
it '8:**' do
at = Clockwork::At.parse('8:**')

assert !at.ready?(time_in_day(7, 59))
Expand All @@ -69,7 +68,7 @@ def time_in_day(hour, minute)
assert !at.ready?(time_in_day(9, 00))
end

test 'Saturday 12:00' do
it 'Saturday 12:00' do
at = Clockwork::At.parse('Saturday 12:00')

assert !at.ready?(Time.new(2010, 1, 1, 12, 00))
Expand All @@ -78,42 +77,41 @@ def time_in_day(hour, minute)
assert at.ready?(Time.new(2010, 1, 9, 12, 00))
end

test 'sat 12:00' do
it 'sat 12:00' do
at = Clockwork::At.parse('sat 12:00')

assert !at.ready?(Time.new(2010, 1, 1, 12, 00))
assert at.ready?(Time.new(2010, 1, 2, 12, 00))
assert !at.ready?(Time.new(2010, 1, 3, 12, 00))
end

test 'invalid time 32:00' do
assert_raise Clockwork::At::FailedToParse do
it 'invalid time 32:00' do
assert_raises Clockwork::At::FailedToParse do
Clockwork::At.parse('32:00')
end
end

test 'invalid multi-line with Sat 12:00' do
assert_raise Clockwork::At::FailedToParse do
it 'invalid multi-line with Sat 12:00' do
assert_raises Clockwork::At::FailedToParse do
Clockwork::At.parse("sat 12:00\nreally invalid time")
end
end

test 'invalid multi-line with 8:30' do
assert_raise Clockwork::At::FailedToParse do
it 'invalid multi-line with 8:30' do
assert_raises Clockwork::At::FailedToParse do
Clockwork::At.parse("8:30\nreally invalid time")
end
end

test 'invalid multi-line with *:10' do
assert_raise Clockwork::At::FailedToParse do
it 'invalid multi-line with *:10' do
assert_raises Clockwork::At::FailedToParse do
Clockwork::At.parse("*:10\nreally invalid time")
end
end

test 'invalid multi-line with 12:**' do
assert_raise Clockwork::At::FailedToParse do
it 'invalid multi-line with 12:**' do
assert_raises Clockwork::At::FailedToParse do
Clockwork::At.parse("12:**\nreally invalid time")
end
end

end
21 changes: 11 additions & 10 deletions test/clockwork_test.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
require File.expand_path('../../lib/clockwork', __FILE__)
require 'test/unit'
require 'minitest/autorun'
require 'mocha/setup'

class ClockworkTest < Test::Unit::TestCase
setup do
describe Clockwork do
before do
@log_output = StringIO.new
Clockwork.configure do |config|
config[:sleep_timeout] = 0
config[:logger] = Logger.new(@log_output)
end
end

teardown do
after do
Clockwork.clear!
end

test 'should run events with configured logger' do
it 'should run events with configured logger' do
run = false
Clockwork.handler do |job|
run = job == 'myjob'
end
Clockwork.every(1.minute, 'myjob')
Clockwork.manager.expects(:loop).yields.then.returns
Clockwork.run

assert run
assert @log_output.string.include?('Triggering')
end

test 'should log event correctly' do
it 'should log event correctly' do
run = false
Clockwork.handler do |job|
run = job == 'an event'
Expand All @@ -39,7 +40,7 @@ class ClockworkTest < Test::Unit::TestCase
assert @log_output.string.include?("Triggering 'an event'")
end

test 'should pass event without modification to handler' do
it 'should pass event without modification to handler' do
event_object = Object.new
run = false
Clockwork.handler do |job|
Expand All @@ -51,7 +52,7 @@ class ClockworkTest < Test::Unit::TestCase
assert run
end

test 'should not run anything after reset' do
it 'should not run anything after reset' do
Clockwork.every(1.minute, 'myjob') { }
Clockwork.clear!
Clockwork.configure do |config|
Expand All @@ -63,15 +64,15 @@ class ClockworkTest < Test::Unit::TestCase
assert @log_output.string.include?('0 events')
end

test 'should pass all arguments to every' do
it 'should pass all arguments to every' do
Clockwork.every(1.second, 'myjob', if: lambda { |_| false }) { }
Clockwork.manager.expects(:loop).yields.then.returns
Clockwork.run
assert @log_output.string.include?('1 events')
assert !@log_output.string.include?('Triggering')
end

test 'support module re-open style' do
it 'support module re-open style' do
$called = false
module ::Clockwork
every(1.second, 'myjob') { $called = true }
Expand Down
Loading