Skip to content

Commit

Permalink
spec/policy: check that allows to define a __gc() that runs when GC'd
Browse files Browse the repository at this point in the history
  • Loading branch information
davidor committed Jun 28, 2018
1 parent a9a3589 commit 976ee2a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions spec/policy_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,17 @@ describe('policy', function()
assert.same(phases, res)
end)
end)

describe('garbage collection', function()
it('runs __gc metamethod when a policy instance is garbage-collected', function()
local MyPolicy, mt = policy.new('my_policy', '1.0')
mt.__gc = function() end
local gc_spy = spy.on(mt, '__gc')
assert(MyPolicy.new())

collectgarbage()

assert.spy(gc_spy).was_called(1)
end)
end)
end)

0 comments on commit 976ee2a

Please sign in to comment.