This allows mocks to be easily reverted to their original state.
describe("mocks", function()
local t = {
thing = function(msg) print(msg) end
}
after_each(function()
mock.revert(t) -- restores table to original state
end)
it("replaces a table with spies", function()
local m = mock(t) -- mocks the table with spies, so it will print
m.thing("Coffee")
assert.spy(m.thing).was.called_with("Coffee")
end)
it("replaces a table with stubs", function()
local m = mock(t, true) -- mocks the table with stubs, so it will not print
m.thing("Coffee")
assert.stub(m.thing).was.called_with("Coffee")
end)
end)
Updated mock.revert to return the original object. This makes it consistent with stub.revert and spy.revert, which will also return the original object.
This allows mocks to be easily reverted to their original state.
Fixes issue #59.