Commit e60f5f5c authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

Always through `assert_true` for assertion methods in `test/assert.rb`

parent fc883de4
...@@ -88,15 +88,11 @@ def assert_true(ret, msg = nil, diff = nil) ...@@ -88,15 +88,11 @@ def assert_true(ret, msg = nil, diff = nil)
end end
def assert_false(ret, msg = nil, diff = nil) def assert_false(ret, msg = nil, diff = nil)
if $mrbtest_assert if ret
$mrbtest_assert_idx += 1 msg ||= "Expected #{ret.inspect} to be false"
if ret diff ||= assertion_diff(false, ret)
msg = "Expected #{ret.inspect} to be false" unless msg
diff = assertion_diff(false, ret) unless diff
$mrbtest_assert.push([$mrbtest_assert_idx, msg, diff])
end
end end
assert_true(!ret, msg, diff)
!ret !ret
end end
...@@ -171,41 +167,33 @@ def assert_not_include(collection, obj, msg = nil) ...@@ -171,41 +167,33 @@ def assert_not_include(collection, obj, msg = nil)
end end
def assert_raise(*exc) def assert_raise(*exc)
return true unless $mrbtest_assert
$mrbtest_assert_idx += 1
msg = (exc.last.is_a? String) ? exc.pop : nil msg = (exc.last.is_a? String) ? exc.pop : nil
begin begin
yield yield
msg ||= "Expected to raise #{exc} but nothing was raised."
diff = nil
$mrbtest_assert.push [$mrbtest_assert_idx, msg, diff]
false
rescue *exc rescue *exc
true assert_true(true)
rescue Exception => e rescue Exception => e
msg ||= "Expected to raise #{exc}, not" msg ||= "Expected to raise #{exc}, not"
diff = " Class: <#{e.class}>\n" + diff = " Class: <#{e.class}>\n" +
" Message: #{e.message}" " Message: #{e.message}"
$mrbtest_assert.push [$mrbtest_assert_idx, msg, diff] assert_true(false, msg, diff)
false else
msg ||= "Expected to raise #{exc} but nothing was raised."
diff = ""
assert_true(false, msg, diff)
end end
end end
def assert_nothing_raised(msg = nil) def assert_nothing_raised(msg = nil)
return true unless $mrbtest_assert
$mrbtest_assert_idx += 1
begin begin
yield yield
true
rescue Exception => e rescue Exception => e
msg ||= "Expected not to raise #{e} but it raised" msg ||= "Expected not to raise #{e} but it raised"
diff = " Class: <#{e.class}>\n" + diff = " Class: <#{e.class}>\n" +
" Message: #{e.message}" " Message: #{e.message}"
$mrbtest_assert.push [$mrbtest_assert_idx, msg, diff] assert_true(false, msg, diff)
false else
assert_true(true)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment