Class: Test::Unit::TestCase
- Inherits:
-
Object
- Object
- Test::Unit::TestCase
- Defined in:
- lib/test/unit.rb
Instance Method Summary collapse
- #assert(test, msg = "failed assertion (no message given)") ⇒ Object
- #assert_equal(exp, act, msg = nil) ⇒ Object
- #assert_in_delta(exp, act, delta, msg = nil) ⇒ Object
- #assert_instance_of(cls, obj, msg = nil) ⇒ Object
- #assert_kind_of(cls, obj, msg = nil) ⇒ Object
- #assert_match(exp, act, msg = nil) ⇒ Object
- #assert_nil(obj, msg = nil) ⇒ Object
- #assert_not_equal(exp, act, msg = nil) ⇒ Object
- #assert_not_nil(obj, msg = nil) ⇒ Object
- #assert_not_same(exp, act, msg = nil) ⇒ Object
- #assert_nothing_raised ⇒ Object
- #assert_operator(o1, op, o2, msg = "") ⇒ Object
- #assert_raises(exp, msg = nil) ⇒ Object (also: #assert_raise)
- #assert_same(exp, act, msg = nil) ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
Instance Method Details
#assert(test, msg = "failed assertion (no message given)") ⇒ Object
39 40 41 |
# File 'lib/test/unit.rb', line 39 def assert(test, msg="failed assertion (no message given)") raise Test::Assertion, msg unless test end |
#assert_equal(exp, act, msg = nil) ⇒ Object
43 44 45 |
# File 'lib/test/unit.rb', line 43 def assert_equal(exp, act, msg=nil) assert exp == act, msg || "Expected #{act.inspect} to be equal to #{exp.inspect}" end |
#assert_in_delta(exp, act, delta, msg = nil) ⇒ Object
47 48 49 |
# File 'lib/test/unit.rb', line 47 def assert_in_delta(exp, act, delta, msg=nil) assert((exp.to_f - act.to_f).abs <= delta.to_f, msg || "Expected #{exp} to be within #{delta} of #{act}") end |
#assert_instance_of(cls, obj, msg = nil) ⇒ Object
51 52 53 |
# File 'lib/test/unit.rb', line 51 def assert_instance_of(cls, obj, msg=nil) assert cls === obj, msg || "Expected #{obj} to be a #{cls}" end |
#assert_kind_of(cls, obj, msg = nil) ⇒ Object
55 56 57 |
# File 'lib/test/unit.rb', line 55 def assert_kind_of(cls, obj, msg=nil) assert obj.kind_of?(cls), msg || "Expected #{obj.inspect} to be a kind of #{cls}" end |
#assert_match(exp, act, msg = nil) ⇒ Object
59 60 61 |
# File 'lib/test/unit.rb', line 59 def assert_match(exp, act, msg=nil) assert act =~ exp, msg || "Expected #{act.inspect} to match #{exp.inspect}" end |
#assert_nil(obj, msg = nil) ⇒ Object
63 64 65 |
# File 'lib/test/unit.rb', line 63 def assert_nil(obj, msg=nil) assert obj.nil?, msg || "Expected #{obj.inspect} to be nil" end |
#assert_not_equal(exp, act, msg = nil) ⇒ Object
67 68 69 |
# File 'lib/test/unit.rb', line 67 def assert_not_equal(exp, act, msg=nil) assert exp != act, msg || "Expected #{act.inspect} to not be equal to #{exp.inspect}" end |
#assert_not_nil(obj, msg = nil) ⇒ Object
71 72 73 |
# File 'lib/test/unit.rb', line 71 def assert_not_nil(obj, msg=nil) assert ! obj.nil?, msg || "Expected #{obj.inspect} to not be nil" end |
#assert_not_same(exp, act, msg = nil) ⇒ Object
75 76 77 |
# File 'lib/test/unit.rb', line 75 def assert_not_same(exp, act, msg=nil) assert ! exp.equal?(act), msg || "Expected #{act.inspect} to not be the same as #{exp.inspect}" end |
#assert_nothing_raised ⇒ Object
98 |
# File 'lib/test/unit.rb', line 98 def assert_nothing_raised; yield; end |
#assert_operator(o1, op, o2, msg = "") ⇒ Object
94 95 96 |
# File 'lib/test/unit.rb', line 94 def assert_operator(o1, op, o2, msg="") assert o1.__send__(op, o2), msg || "Expected #{o1}.#{op}(#{o2}) to be true" end |
#assert_raises(exp, msg = nil) ⇒ Object Also known as: assert_raise
79 80 81 82 83 84 85 86 87 |
# File 'lib/test/unit.rb', line 79 def assert_raises(exp, msg=nil) begin yield assert false, "Expected #{exp} to be raised" rescue Exception => e assert exp === e, msg || "Expected #{exp} to be raised, but got #{e.class}" return e end end |
#assert_same(exp, act, msg = nil) ⇒ Object
90 91 92 |
# File 'lib/test/unit.rb', line 90 def assert_same(exp, act, msg=nil) assert exp.equal?(act), msg || "Expected #{act.inspect} to be the same as #{exp.inspect}" end |
#setup ⇒ Object
36 |
# File 'lib/test/unit.rb', line 36 def setup; end |
#teardown ⇒ Object
37 |
# File 'lib/test/unit.rb', line 37 def teardown; end |