Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to mock os.execute() #614

Open
flowdopip opened this issue Aug 19, 2024 · 1 comment
Open

How to mock os.execute() #614

flowdopip opened this issue Aug 19, 2024 · 1 comment

Comments

@flowdopip
Copy link

flowdopip commented Aug 19, 2024

Hi, is there any documentation on mock os.execute()?

I´ve tried this way:

describe("Plugin: " .. plugin_name .. " - integration tests", function()
    local os_execute_mock
    lazy_setup(function()
        os_execute_mock = mock(os, "execute")
...

    describe("Verify cache behaviour", function()
        describe("When there is a cache miss, ", function()
            it("should return 200", function()
                local r = execute_test("/v1/prefix/route1", {})
                os_execute_mock.returns(0)

but I got this error: attempt to call field 'returns' (a nil value)

EDIT: properly display code block

@Tieske
Copy link
Member

Tieske commented Aug 28, 2024

I think your mocking is wrong, see https://lunarmodules.github.io/busted/#spies-mocks-stubs

Since you mock a single function you'll probably want to use either a stub or a spy, depending on whether you want the original function to execute or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants