如何使用`must`定义Ruby Test :: Unit测试用例

时间:2015-03-13 16:27:34

标签: ruby unit-testing testunit

我有一个以下形式的测试用例:

require 'test/unit'
class SomeTests < Test::Unit::TestCase
  def test_should_do_action
   assert true
  end
end

并按照 A Test :: Unit Trick to know About 一书中的建议,使用must重新编写它:

require 'test/unit'
class SomeTests < Test::Unit::TestCase
  must "do action" do
    assert true
  end
end

当我运行它时,我收到undefined method 'must'错误,如下所示:

SomeTests.rb:3:in `<class:SomeTests>': undefined method `must' for     SomeTests:Class (NoMethodError)  from
SomeTests.rb:2:in `<top (required)>'    from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'   from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'   from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'   from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rake/rake_test_loader.rb:9:in `each'  from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rake/rake_test_loader.rb:9:in `block in <main>'   from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rake/rake_test_loader.rb:4:in `select'    from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rake/rake_test_loader.rb:4:in `<main>' rake aborted! Command failed with status (1): [ruby -w -I"lib" -I"/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0" "/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rake/rake_test_loader.rb" "test/**/*Tests.rb" ]
Tasks: TOP => default => test (See full trace by running task with --trace)

我认为must可能是minitest的一部分,所以我要求&#39; minitest / unit&#39;相反,但我仍然得到一个错误。我还假设must关键字不是rspec的一部分,我还没有使用它。

如何使其正常工作?

1 个答案:

答案 0 :(得分:1)

看起来这种方法不是开箱即用的,而是由第三方开发的。您需要添加描述here的代码。