Created
April 6, 2015 19:11
-
-
Save starius/ab8d6aa7929d18a31df0 to your computer and use it in GitHub Desktop.
busted example with global functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processEvent(e) | |
eventId = getEventType(e) | |
if eventId == 3 then | |
return 3 | |
else | |
return 0 | |
end | |
end | |
describe("processEvent", function() | |
it("calls getEventType with the event", function() | |
local getEventType_argument | |
function getEventType(x) | |
getEventType_argument = x | |
end | |
processEvent(42) | |
assert.equal(getEventType_argument, 42) | |
end) | |
it("returns 3 if getEventType returns 3", function() | |
function getEventType() | |
return 3 | |
end | |
assert.equal(processEvent(), 3) | |
end) | |
it("returns 0 if getEventType returns not 3", function() | |
function getEventType() | |
return 42 | |
end | |
assert.equal(processEvent(), 0) | |
end) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment