Skip to content

Instantly share code, notes, and snippets.

@jschmid1
Created November 23, 2021 10:09
Show Gist options
  • Select an option

  • Save jschmid1/4e67b07ca25ba21fd3aee8eb8e17b429 to your computer and use it in GitHub Desktop.

Select an option

Save jschmid1/4e67b07ca25ba21fd3aee8eb8e17b429 to your computer and use it in GitHub Desktop.
-- in a it/describe block you can do this to simulate a side-effect
-- similar to python-unittest's side_effect https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.side_effect
local called = false
local side_effect = function()
-- adding a side_effect that causes to fail the `request_uri` the first time
-- but succeed the second time.
if not called then
called = true
return false, "err"
end
return true, nil
end
local s_request_uri = stub(httpc, "request_uri").invokes(side_effect)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment