Skip to content

thehiflyer/MoC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

MoC is a mocking framework for lua written by hiflyer (hiflyer@fearlessgames.se)
The design of MoC is inspired by the excellent java mocking framework Mockachino written by krka. Thanks also goes to krka for helping me with the initial draft.

MoC is licensed under the MIT license which is supplied in the source code.

The name MoC indicates that it's a mocking framework but it is really an initialism for Made of Cheese


How do I use MoC?

Download the file moc.lua and callhandler.lua and add it to a path your lua require can reach. Since moc references callhandler you need keep them both in the directory se/hiflyer/moc
That's it, MoC is now ready to use.


To create a mock object, just call

local mock = MoC:New()

You can now use the object and all methods on it will record usage

mock:Foo()
mock:Bar("Yadda, yadda")
mock:Bar("Yadda, yadda")

And then verify that the methods were called

verifyNever():on(mock):Foo() -- will fail
verifyOnce():on(mock):Foo() -- will succeed
verifyAtLeast(2):on(mock):Bar() -- will fail
verifyAtLeast(2):on(mock):Bar("Yadda, yadda") -- will succeed


Stubbing

To have a method call return values


when(mock:GetSize()):thenReturn(3, 4)

local w, h = mock:GetSize()
assertEquals(3, w)
assertEquals(4, h)

verifyOnce():on(mock):GetSize()


For more example usage, have a look at the test cases supplied in the test folder. These tests run in any environment specifying the assert* functions, in the case of MoC development they were run on the Kahlua machine using the kahlua-test project.

Version History:

0.2
	- Support for stubbing
	- Support for parameter matching verification on verification and stubbing

0.1
	- Initial version
	- Support for verification of calls (no parameter matching)


TODO:
	- Add support for matchers
	- Add build tools to the MoC project

About

a mocking framework for lua

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages