Module: GUnit::Assertions
- Included in:
- TestCase
- Defined in:
- lib/gunit/assertions.rb
Instance Method Summary collapse
- #assert(*args, &blk) ⇒ Object
- #assert_equal(*args, &blk) ⇒ Object
- #assert_raises(*args, &blk) ⇒ Object
Instance Method Details
#assert(*args, &blk) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gunit/assertions.rb', line 8 def assert(*args, &blk) expected = true if blk actual = blk = args[0] else actual = args[0] = args[1] end actual = actual.call if actual.is_a?(Proc) unless actual == expected ||= "#{actual.to_s} != #{expected.to_s}" raise GUnit::AssertionFailure.new() end true end |
#assert_equal(*args, &blk) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gunit/assertions.rb', line 29 def assert_equal(*args, &blk) expected = args[0] if blk actual = blk = args[1] else actual = args[1] = args[2] end actual = actual.call if actual.is_a?(Proc) ||= "#{actual.to_s} != #{expected.to_s}" assert expected == actual, end |
#assert_raises(*args, &blk) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/gunit/assertions.rb', line 47 def assert_raises(*args, &blk) expected = args[0] = args[1] begin blk.call rescue Exception => e actual = e end bool = if actual.nil? false else case expected when String then actual.to_s == expected when Class then actual.is_a?(expected) when Nil then !actual.nil? else; actual == expected end end # bool = case # when actual.nil? # false # when expected.is_a?(String) # actual.to_s == expected # when expected.is_a?(Class) # actual.is_a?(expected) # when expected.nil? # !actual.nil? # else # actual == expected # end ||= case when !expected.nil? && !actual.nil? "Expected #{expected.to_s} to be raised, but got #{actual.to_s}" when !expected.nil? && actual.nil? "Expected #{expected.to_s} to be raised, but nothing raised" else "Nothing raised" end assert bool, end |