Closed ktalebian closed 4 years ago
not sure I get the issue you're trying to solve?
are you trying to run a single handler on each test, where the tests are spread over multiple files? and hence independent describe blocks?
How about:
-- tests/app/init.lua
require 'busted.runner'()
busted.describe('init', function()
require('tests.setup')() -- inject global before_each handler
describe('a test suite', function()
...
end)
end)
-- tests/setup.lua
return function()
before_each(function()
-- run anything here
end)
end
Another possibility:
require("busted").subscribe({"test", "start"}, function() <your code> end)
This can be put in --helper
script. I'm using this pattern to run some system tests: I set up my environment in {"suite", "start"}
and tear it down in {"suite", "end"}
.
nice example @Crack 👍
@ktalebian can we close this?
Yep.
I run my tests like
rusty tests/app/init.lua
. For all my tests, I want to have abefore_each
function that runs on all of my tests. I've been able to do this, but I think this is very hacky:Is this going to cause any issues? It seems to work fine. Is there a recommended way of doing this?