lunarmodules / busted

Elegant Lua unit testing.
https://lunarmodules.github.io/busted/
MIT License
1.39k stars 184 forks source link

stub's called_with error report is not clear #655

Closed ffbh123456 closed 2 years ago

ffbh123456 commented 3 years ago

The following code reports an error, it prompted that this parameter list does not match, but this information is too little, I think it should output the expected parameter list and the current parameter list, by comparing the parameter list, I can locate the problem more conveniently

assert.stub(stub).called_with("parameter")
# test.lua @ 75
# Failure message: test.lua:80: Function was not called with the arguments
# stack traceback:
#       test.lua:80: in function <test.lua:77>
# 
Tieske commented 3 years ago

here's a similar issue for spy; https://github.com/Olivine-Labs/busted/issues/578

Maybe the solution can be added to the stub as well?

ffbh123456 commented 3 years ago

@Tieske Hi, I used spy, but I found that his error report is similar to that of stub, and no information about the parameter list is output.

test(
            "test",
            function()
                local test = require "test"
                local s = spy.on(test,"fun")
                test.fun("i am info msg")
                assert.spy(s).called_with("i am info msg11111")
                mock.revert(test)
            end
        )
# Failure message:test.lua:75: Function was not called with the arguments
# stack traceback:
#       test.lua:75: in function <test.lua:71>
# 
Tieske commented 3 years ago

@ZhouJiaZhi that code is not released yet. Have you tried with latest master?

ffbh123456 commented 3 years ago

@Tieske I just reinstalled the latest version of busted, and his error report is still unclear.

alerque commented 3 years ago

The latest release version or the latest Git branch HEAD? How exactly did you install it that you know you have the latest non-versioned master branch?

Tieske commented 3 years ago

@ZhouJiaZhi it's like @alerque mentioned; use the lastest version from the Github repo, since the change has not yet been released in a a Busted release.

Try:

git clone https://github.com/Olivine-Labs/busted.git
cd busted
luarocks make

And then test again.

ffbh123456 commented 3 years ago

@alerque @Tieske Hi, I will show you the detailed information as follows, 1.I re-git clone the busted warehouse, then uninstall and reinstall

截屏2020-12-07 22 03 54

2.my unit test image

Tieske commented 3 years ago

@ZhouJiaZhi sorry, my mistake, those changes were not made to Busted, but to Luassert. So use the latest master branch of Luassert instead.

ffbh123456 commented 3 years ago

@Tieske I do not konw how to install luassert, and what version of luaassert is busted using? Why not set luassert as a busted submodule?

Tieske commented 3 years ago

busted has a dependency on luassert, and it will automatically be installed when you install busted. Problem here is that the functionality you want hasn't been released yet.

try this

git clone https://github.com/Olivine-Labs/luassert.git
cd luassert
luarocks remove luassert --force
luarocks make
alerque commented 2 years ago

This should be resolved as both luassert and busted have gotten new releases. If for some reason this still does not work as expected please let us know, but I presume the latest releases should have the code you needed in place now.