lua-users home
lua-l archive

Re: Is there similar autospeccing thing in lemock?

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2014年8月8日 11:24, albert_200200 wrote:
[ lunit.setprivfenv()
lunit.import "assertions"
lunit.import "checks"

require("lemock")


local ut = lunit.TestCase("public.add function test")
function ut:test()
local public = require("public")
mc = lemock.controller()
mock_add_internal = mc:mock()
package.loaded.public.add_internal = mock_add_internal
mock_add_internal(2, 3); mc:returns(5)
mc:replay()
local result = public.add(2, 3)
assert_equal(5, result)

mc:verify()
end
lunit.run()


Now take such situation, I modify public.add_internal'code as below:
public.lua
---------------------------------------------------
local M = {}
function M.add_internal(a, b, c)
return a+b+c
--add_internal may call some global function, so I should mock add_internal
end
function M.add(a, b)
return M.add_internal(a, b)
end
return M

But I leave the test.lua unmodified, the unittest would pass too.
Is there a way to solve this problem? Could someone know how to solve this problem? It really bothers me for a while.

AltStyle によって変換されたページ (->オリジナル) /