0

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

Thomas W
  • 14,757
  • 6
  • 48
  • 67
MARTIN Damien
  • 996
  • 2
  • 15
  • 36
  • Unsure if this is a typo in your post or your code, but you have `foor.bar = newclass( "foo.bar")` – Josh Sep 18 '12 at 03:51
  • The instruction `foo.bar:doSomething = function() return "foo bar" end ` is also a syntax error. It can either be `foo.bar.doSomething = function(self)...` or `function foo.bar:doSomething()...` . So please check your code and correct the question. – prapin Sep 18 '12 at 11:39
  • I corrected my code and merged the two files. – MARTIN Damien Sep 18 '12 at 12:34

1 Answers1

1

Most likely, the describe function sets the environment of the passed function to prevent it from interfering with other code files.

Puppy
  • 144,682
  • 38
  • 256
  • 465