lunarmodules / luassert

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

Add returned_with assertion and fix on_call_with #96

Closed o-lim closed 9 years ago

o-lim commented 9 years ago

This adds the returned_with assertion for spies.

local spy.new(function() return 1, 2, 3 end)
s()
assert.spy(s).was.returned_with(1, 2, 3)

Also works with don't cares.

local spy.new(function() return 1, 2, 3 end)
local _ = spy._
s()
assert.spy(s).was.returned_with(1, _, 3)

Fix on_call_with to match against don't care arguments.

local test = {}
local _ = stub._
stub(test, "key").on_call_with(_).returns("foo")
assert.is_nil(test.key())
assert.is_nil(test.key(1, 2))
assert.is_equal("foo", test.key(1))
assert.is_equal("foo", test.key(2))
assert.is_equal("foo", test.key('a'))
assert.is_equal("foo", test.key('b'))
assert.is_equal("foo", test.key({}))