lunarmodules / luassert

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

removed argument on stub function, added check on spy so it only accepts... #34

Closed Tieske closed 11 years ago

Tieske commented 11 years ago

... functions as values to spy on.

ajacksified commented 11 years ago

What about tables with meta indexes that can be called as functions?

Tieske commented 11 years ago

I'd say that it is up to the user to spy on the __call metamethod instead of on the table. Possibly a future enhancement.

nilnor commented 11 years ago

I'd say that it is up to the user to spy on the __call metamethod instead of on the table

That does not seem very user friendly. Conceivably you might spy on external code when verifying interactions, and then you have to worry about the implementation of that code? Besides, checking for __call is trivial, so why not do that?

Tieske commented 11 years ago

updated it, realized that spying on __call would not only spy on an individual object but spy on all objects sharing that same metatable. That could make testing harder, so added it.

Tieske commented 11 years ago

PS. busted documentation should be updated for spy example; local s = spy.new() should become local s = spy.new(function() end)

ajacksified commented 11 years ago

Looks awesome - although I'll follow up so you can run spy.new with no arguments to create a generic function spy without having to duplicate (function() end) often. I'll check for no arguments rather than a nil argument specifically so that we can still throw errors if you pass in something that shouldn't be nil.

Tieske commented 11 years ago

Looks awesome - although I'll follow up so you can run spy.new with no arguments to create a generic function spy without having to duplicate (function() end) often. I'll check for no arguments rather than a nil argument specifically so that we can still throw errors if you pass in something that shouldn't be nil.

That would be creating a stub. So instead of spy.new(function() end) it should be stub.new() to create a 'blank' spy.