Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default value to Spy constructor argument #156

Merged
merged 2 commits into from Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions spec/spies_spec.lua
Expand Up @@ -217,4 +217,10 @@ describe("Tests dealing with spies", function()
assert.spy(s).was_not.returned_with("foobar")
end)

it("checks spy.new can be constructed without arguments", function()
local s = spy.new()
s()
assert.spy(s).was.called(1)
end)

end)
1 change: 1 addition & 0 deletions src/spy.lua
Expand Up @@ -21,6 +21,7 @@ local spy_mt = {
local spy -- must make local before defining table, because table contents refers to the table (recursion)
spy = {
new = function(callback)
callback = callback or function() end
if not util.callable(callback) then
error("Cannot spy on type '" .. type(callback) .. "', only on functions or callable elements", util.errorlevel())
end
Expand Down