在测试单元2.3.0中使用“忽略”功能时出错

| 我对自己的问题有些困惑。我正在使用ruby 1.8.7,rails 2.3.2。我正在尝试使用2.3.0测试单元中的“省略”功能。这是我的测试:
def test_create_reward_program
  omit(\"Pending\")

  reward_program = RewardProgram.find_by_program_name(\"test_foo\")
  assert_equal \"test_foo\", reward_program.program_name

end
当我运行“ rake test”时,得到以下信息:
1) Error:
test_create_reward_program(AwardControllerTest):
Test::Unit::OmittedError: Pending
    /test/functional/award_controller_test.rb:43:in `test_create_reward_program\'


148 tests, 261 assertions, 0 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
0%通过 我不知道为什么它应该将其标记为“遗漏”时将其标记为“错误”。有人知道吗 我还注意到这确实有效:
def test_create_reward_program
  omit \"Pending\" do
    reward_program = RewardProgram.find_by_program_name(\"test_foo\")
    assert_equal \"test_foo\", reward_program.program_name
  end        
end
我发现的所有教程和示例都表明我的第一个示例应该可行。     
已邀请:
查看Test :: Unit 2.3.0的代码,这就是代码的行为。除非给出阻止,否则它将抛出。 文档将“ 3”的来源列出为:
# File lib/test/unit/omission.rb, line 77
def omit(message=nil, &block)
  message ||= \"omitted.\"
  if block_given?
    omission = Omission.new(name, filter_backtrace(caller), message)
    add_omission(omission)
  else
    raise OmittedError.new(message)
  end
end
顺便说一句,如果您进行了升级,则与Minitest捆绑在一起的运行在Ruby 1.9.2p0上的Rails 3.1.0.rc1不会定义“ 3”,而是会添加“ 6”。例如:
# test/unit/bird_test.rb
require \'test_helper\'

class BirdTest < ActiveSupport::TestCase
  test \"creation\" do
    bird = Bird.new
    assert_not_nil bird
  end

  test \"not implemented\" do
    skip
    assert false
  end

end
使用
turn
宝石漂亮地打印输出,我得到:
$ rake test:units
Started

BirdTest:
     PASS creation (0.06s) 
     SKIP not implemented (0.00s) 

Finished in 0.060828 seconds.

2 tests, 1 assertions, 0 failures, 0 errors, 1 skips
    

要回复问题请先登录注册