Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local moduleFoo={}
- local moduleBaz= require("moduleBaz")
- moduleFoo.doSomething = function (arg)
- if moduleBaz.bar.neatMethod(arg) then
- --does something interesting
- end
- end
- return moduleFoo
- local moduleBaz={}
- moduleBaz.bar= {}
- moduleBaz.bar.neatMethod=function(arg)
- --does something neat
- end
- return moduleBaz
- package.loaded.moduleBaz= nil
- local moduleBaz = {}
- moduleBaz.bar = {}
- moduleBaz.bar.neatMethod= function(guid) return true end
- package.preload['moduleBaz'] = function ()
- return moduleBaz
- end
- local foo= require("moduleFoo")
- foo.doSomething('asdasdasda')--real moduleBaz is called, not my mock!
- return moduleBaz
- package.loaded.moduleBaz = {
- bar = {
- neatmethod = function(arg)
- -- your mock code here
- end,
- }
- }
- local moduleBaz={}
- moduleBaz.bar= {}
- moduleBaz.bar.neatMethod=function(arg)
- print "baz"
- return true
- end
- return moduleBaz
- local moduleFoo={}
- local moduleBaz= require("moduleBaz")
- moduleFoo.doSomething = function (arg)
- if moduleBaz.bar.neatMethod(arg) then
- print "foo"
- end
- end
- return moduleFoo
- package.loaded.moduleBaz= nil
- local moduleBaz = {}
- moduleBaz.bar = {}
- moduleBaz.bar.neatMethod= function(guid) print "mock" return true end
- package.preload['moduleBaz'] = function ()
- return moduleBaz
- end
- local foo= require("moduleFoo")
- foo.doSomething('asdasdasda')--real moduleBaz is called, not my mock!
Add Comment
Please, Sign In to add comment