Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Lua中的busted无法访问模块_Lua_Lua Busted - Fatal编程技术网

使用Lua中的busted无法访问模块

使用Lua中的busted无法访问模块,lua,lua-busted,Lua,Lua Busted,我是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", fun

我是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)
除了
描述之外
它们没有问题

有人能解释一下为什么foo.bar在
description
中无法访问吗


感谢

很可能,descripe函数设置了传递函数的环境,以防止它干扰其他代码文件。

不确定这是否是您的帖子或代码中的错误,但您有
foor.bar=newclass(“foo.bar”)
指令
foo.bar:doSomething=function()返回“foo-bar”end
也是一个语法错误。它可以是
foo.bar.doSomething=function(self)…
function foo.bar:doSomething()…
。因此,请检查您的代码并更正问题。我更正了代码并合并了两个文件。