0

私は Lua の初心者で、開発で単体テストを使用したいと考えています。そのために、シンプルで使いやすいフレームワークを使用することにしました

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

しかし、 foo.bar には到達できないようです...

attempt to index global 'foo' (a nil value)

彼らの外でdescribeは問題ありません。

誰かが foo.bar に到達できない理由を説明してもらえますdescribeか?

ありがとう

4

1 に答える 1

1

ほとんどの場合、describe 関数は、渡された関数の環境を設定して、他のコード ファイルに干渉しないようにします。

于 2012-09-18T12:37:09.800 に答える