Closed xpol closed 9 years ago
It seems like there could be situations where someone wants both behaviors in a single spy. Would something like assert.spy(s).was.called_with(assert.reference(Foo)) be acceptable to force called_with to compare by reference instead of by value?
This is solved by using the is_ref
matcher. Just pass match.is_ref(foo)
to called_with
describe('Foo', function()
it(':add() calls Bar.callback()', function()
local s = spy.on(Bar, 'callback')
local match = require 'luassert.match`
Foo:add(Bar) -- make a deep copy of Foo, before Foo.bar sets to Bar
assert.spy(s).was.called(1) -- OK
assert.spy(s).was.called_with(match.is_ref(Foo)) -- passes called_with compares against a reference to Foo
end)
end)
See also issue #123, which the original issue referring to this behavior, and was resolved by PR #124, which introduced the is_ref
matcher.
@o-lim Thank you very much!
Lets see and example:
assert.spy(s).was.called_with(Foo)
Failure because theFoo
was not same asFooCopy
.So, I think it is needs that we have option in
spy
orcalled_with
just keep a reference to its calling args and compare args by==
(or something else).