Skip to content

Commit

Permalink
spec/resty/concurrent/timer_task: use spies instead of stubs
Browse files Browse the repository at this point in the history
TimerTask is now built calling GC.set_metatable_gc. That method returns
an object for which type() returns "userdata". Luassert only allows
creating stubs on objects for which type() returns "table".
  • Loading branch information
davidor committed Jun 26, 2018
1 parent b17ada1 commit 69d3c58
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions spec/resty/concurrent/timer_task_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ describe('TimerTask', function()
describe('when the task is active', function()
it('runs the task', function()
local timer_task = TimerTask.new(func, { args = args, interval = interval })
local func_stub = stub(timer_task, 'task')
local func_spy = spy.on(timer_task, 'task')

timer_task:execute(true)

assert.stub(func_stub).was_called_with(unpack(args))
assert.spy(func_spy).was_called_with(unpack(args))
end)

it('schedules the next one', function()
Expand All @@ -104,12 +104,12 @@ describe('TimerTask', function()
describe('when the task is not active', function()
it('does not run the task', function()
local timer_task = TimerTask.new(func, { args = args, interval = interval })
local func_stub = stub(timer_task, 'task')
local func_spy = spy.on(timer_task, 'task')
timer_task:cancel()

timer_task:execute(true)

assert.stub(func_stub).was_not_called()
assert.spy(func_spy).was_not_called()
end)

it('does not schedule another task', function()
Expand All @@ -125,12 +125,12 @@ describe('TimerTask', function()
describe('when the option to wait an interval instead of running now is passed', function()
it('does not run the task inmediately', function()
local timer_task = TimerTask.new(func, { args = args, interval = interval })
local func_stub = stub(timer_task, 'task')
local func_spy = spy.on(timer_task, 'task')

timer_task:execute(false)

-- It will be called in 'interval' seconds, but not now
assert.stub(func_stub).was_not_called()
assert.spy(func_spy).was_not_called()
end)

it('schedules the next one', function()
Expand Down

0 comments on commit 69d3c58

Please sign in to comment.