【问题标题】:Module unreachable using busted in Lua在 Lua 中使用 busted 无法访问模块
【发布时间】:2012-09-17 21:33:58
【问题描述】:

我是 Lua 的初学者,我想在我的开发人员中使用单元测试。 我决定使用busted 一个简单易用的框架来做到这一点。

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 中无法访问吗?

谢谢

【问题讨论】:

  • 不确定这是否是您的帖子或代码中的拼写错误,但您有 foor.bar = newclass( "foo.bar")
  • 指令foo.bar:doSomething = function() return "foo bar" end 也是语法错误。它可以是 foo.bar.doSomething = function(self)...function foo.bar:doSomething()... 。所以请检查您的代码并更正问题。
  • 我更正了我的代码并合并了两个文件。

标签: lua lua-busted


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 1970-01-01
    • 2023-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多