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

发布于 2024-11-04 12:00:40 字数 945 浏览 4 评论 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

我找到的所有教程和示例都表明我的第一个示例应该有效。

I'm a bit stumped by my issue. I am using ruby 1.8.7, rails 2.3.2. I am attempting to using the 'omit' feature in Test Unit 2.3.0. Here is my test:

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

When I run 'rake test', I get the following:

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% passed

I don't know why it's marking it as 'error' when it should mark it as 'omission'. Anyone know?

I also noticed that this does work:

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

All the tutorials and examples I have found indicates that my first example should work.

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

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

发布评论

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

评论(1

メ斷腸人バ 2024-11-11 12:00:40

查看 Test::Unit 2.3.0 的代码,这正是编码的行为。除非给定一个块,否则它会抛出异常。

文档列出了源代码对于 omit 为:

# 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

顺便说一句,如果您升级了,在 Ruby 1.9.2p0 上运行的 Rails 3.1.0.rc1(捆绑 Minitest)不会定义 omit 但添加跳过。例如:

# 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 gem 漂亮地打印我的输出,我得到:

$ 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

Looking at the code for Test::Unit 2.3.0, that is precisely the coded behaviour. It throws unless given a block.

The documentation lists the source for omit as:

# 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

By the way, if you ever upgrade, Rails 3.1.0.rc1, running on Ruby 1.9.2p0, which bundles Minitest, does not define omit but adds skip. For example:

# 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

Using the turn gem to pretty-print my output, I get:

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