updated the tests. Fixes #4

This commit is contained in:
kikito 2012-10-27 18:44:20 +02:00
parent e18c83a9a4
commit 8dd3dae68b

View File

@ -1,6 +1,6 @@
local cron = require 'cron'
local cron = require 'cron'
context( 'cron', function()
describe( 'cron', function()
local counter = 0
local function count(amount)
@ -14,16 +14,16 @@ context( 'cron', function()
cron.reset()
end)
context('update', function()
test( 'Should throw an error if dt is a negative number', function()
describe('.update', function()
it('throws an error if dt is a negative number', function()
assert_error(function() cron.update() end)
assert_error(function() cron.update(-1) end)
assert_not_error(function() cron.update(1) end)
end)
end)
context('reset', function()
test('Should cancel all timed actions', function()
describe('.reset', function()
it('Cancels all timed actions', function()
cron.after(1, count)
cron.after(2, count)
cron.update(1)
@ -33,7 +33,7 @@ context( 'cron', function()
assert_equal(counter, 1)
end)
test('Should cancel all periodical actions', function()
it('Cancels all periodical actions', function()
cron.every(1, count)
cron.update(1)
assert_equal(counter, 1)
@ -44,8 +44,8 @@ context( 'cron', function()
end)
context( 'after', function()
test( 'Should throw error if time is not a positive number, or callback is not callable', function()
describe('.after', function()
it('Throws error if time is not a positive number, or callback is not callable', function()
assert_error(function() cron.after('error', count) end)
assert_error(function() cron.after(2, 'error') end)
assert_error(function() cron.after(-2, count) end)
@ -53,8 +53,8 @@ context( 'cron', function()
assert_not_error(function() cron.after(2, count) end)
assert_not_error(function() cron.after(2, countable) end)
end)
test( 'Should execute timed actions are executed only once, at the right time', function()
it('Executes timed actions only once, at the right time', function()
cron.after(2, count)
cron.after(4, count)
cron.update(1)
@ -67,15 +67,15 @@ context( 'cron', function()
assert_equal(counter, 2)
end)
test( 'Should pass on parameters to the function, if specified', function()
it('Passes on parameters to the function, if specified', function()
cron.after(1, count, 2)
cron.update(1)
assert_equal(counter, 2)
end)
end)
context( 'every', function()
test( 'Should throw error if time is not a positive number, or callback is not function', function()
describe('.every', function()
it('Throws errors if time is not a positive number, or callback is not function', function()
assert_error(function() cron.every('error', count) end)
assert_error(function() cron.every(2, 'error') end)
assert_error(function() cron.every(-2, count) end)
@ -84,7 +84,7 @@ context( 'cron', function()
assert_not_error(function() cron.every(2, countable) end)
end)
test( 'Should execute periodical actions periodically', function()
it('Executes periodical actions periodically', function()
cron.every(3, count)
cron.update(1)
assert_equal(counter, 0)
@ -96,21 +96,21 @@ context( 'cron', function()
assert_equal(counter, 2)
end)
test( 'Should execute the same action multiple times on a single update if appropiate', function()
it('Executes the same action multiple times on a single update if appropiate', function()
cron.every(1, count)
cron.update(2)
assert_equal(counter, 2)
end)
test( 'Should respect parameters', function()
it('Respects parameters', function()
cron.every(1, count, 2)
cron.update(2)
assert_equal(counter, 4)
end)
end)
context( 'cancel', function()
test( 'Should allow the cancelation of timed actions', function()
describe('.cancel', function()
it('Cancels timed entries', function()
local id = cron.after(1, count)
cron.update(1)
assert_equal(counter, 1)
@ -119,7 +119,7 @@ context( 'cron', function()
assert_equal(counter, 1)
end)
test( 'Should allow the cancelation of periodical actions', function()
it('Cancels periodical entries', function()
local id = cron.every(1, count)
cron.update(1)
assert_equal(counter, 1)
@ -128,7 +128,4 @@ context( 'cron', function()
assert_equal(counter, 1)
end)
end)
end)