lunarmodules / luassert

Assertion library for Lua
MIT License
202 stars 77 forks source link

Clear call history for spies/stubs/mocks #99

Closed o-lim closed 9 years ago

o-lim commented 9 years ago

This allows the call history for spies/stubs/mocks to be cleared without reverting the spy/stub/mock.

it("Makes sure call history for spy can be cleared", function()
   local s = spy.new(function() return "foobar" end)
   s()
   s("test")
   s:clear()
   assert.spy(s).was_not.called()
   assert.spy(s).was_not.returned_with("foobar")
end)

it("Makes sure call history for mocks can be cleared", function()
  test.foo = { bar = function() return "foobar" end }
  mock(test)
  test.key()
  test.key("test")
  test.foo.bar()
  test.foo.bar("hello world")
  assert.spy(test.key).was.called()
  assert.spy(test.foo.bar).was.called()
  mock.clear(test)
  assert.spy(test.key).was_not.called()
  assert.spy(test.foo.bar).was_not.called()
end)

Note: This is on top of PR #96