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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With