使用 Shoulda 进行单元测试

发布于 2024-09-16 09:42:39 字数 724 浏览 8 评论 0原文

编辑:此问题仅有时会发生

这似乎仅在我从 TextMate 中运行测试时才会发生(即使我指定 ruby​​ 使用 shebang 手动运行它)。如果我从终端运行它,那么一切都会很顺利......


这是一些代码:

require 'test/unit'
require 'shoulda'

class TestingTest < Test::Unit::TestCase
  context "My thing" do  
    should "always have this test fail, and give me this message" do
      assert false
    end
  end
end

我期望它告诉我类似的信息:

1) Failure:
test: My thing should always have this test fail, and give me this message (TestingTest)
# etc
An assert message, if one was given

但我得到:

1) Failure:
test:8
Failed assertion, no message given.

那么我错过了什么?上面的示例代码很简单,我认为我可以做到,但我看不出问题!

edit: this problem only happens sometimes

This only appears to happen when I run the test from within TextMate (even when I specify the ruby to run it from by hand with a shebang). If I run it from the terminal then everything is peachy…


Here's some code:

require 'test/unit'
require 'shoulda'

class TestingTest < Test::Unit::TestCase
  context "My thing" do  
    should "always have this test fail, and give me this message" do
      assert false
    end
  end
end

I'm expecting it to tell me something like:

1) Failure:
test: My thing should always have this test fail, and give me this message (TestingTest)
# etc
An assert message, if one was given

But I'm getting:

1) Failure:
test:8
Failed assertion, no message given.

So what am I missing? The example code above is as simple as I think I can make it and I can't see the problem!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

未蓝澄海的烟 2024-09-23 09:42:40

尝试继承 ActiveSupport::TestCase 而不是 Test::Unit::TestCase

try inheriting from ActiveSupport::TestCase instead of the Test::Unit::TestCase

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文