【问题标题】:Unit Testing with Shoulda使用 Shoulda 进行单元测试
【发布时间】:2010-08-30 16:00:22
【问题描述】:

编辑:这个问题有时会发生

这似乎只发生在我从 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.

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

【问题讨论】:

  • 我试用时应该不是这样的。愿意给我们看一些代码吗?
  • 刚刚注意到它以我期望的方式工作(在失败时显示上下文和应该的消息)与不同的测试 - 将不得不更仔细地调查!忍受我,谢谢!

标签: ruby unit-testing shoulda


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 2023-03-11
    相关资源
    最近更新 更多