I'm a beginer with Lua and I would like to use unit tests in my devs. I decided to use busted a simple and easy to use framework to do that.
require "yaci"
require "busted"
foo = {}
foor.bar = newclass( "foo.bar" )
function foo.bar:doSomething() return "foo bar" end
describe("Unit tests for Foo.Bar", function()
it("A first test", function()
local to_test = foo.bar()
local text = to_test:doSomething()
local a = { test = say }
local b = { test = "foo bar" }
assert.same( a, b )
end)
end
But foo.bar looks to be unreachable...
attempt to index global 'foo' (a nil value)
Outside of describe
theire is no problem.
Could someone explain me why foo.bar is unreachable in describe
?
Thanks
Most likely, the describe function sets the environment of the passed function to prevent it from interfering with other code files.