lunarmodules / luassert

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

Add ref matcher to match against object references #124

Closed o-lim closed 9 years ago

o-lim commented 9 years ago

This allows using on_call_with, called_with, and returned_with to match against object references.

it("Test called_with() using refs", function()
  local match = require 'luassert.match'
  local s = spy.new(function() end)
  local t1 = { foo = { bar = { "test" } } }
  local t2 = { foo = { bar = { "test" } } }

  s(t1)
  t1.foo.bar = "value"

  assert.spy(s).was_not.called_with(t1)  -- no match since t1 was modified
  assert.spy(s).was.called_with(t2)  -- matches since t2 was the same as t1 at call site
  assert.spy(s).was_not.called_with(match.is_ref(t2))  -- does not match ref to t2
  assert.spy(s).was.called_with(match.is_ref(t1))  -- matches ref to t1
end)

This should resolve issue #123.

o-lim commented 9 years ago

@ajacksified could you incorporate this PR into the release?

DorianGray commented 9 years ago

Looks good!