summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorYukihiro Matz Matsumoto <[email protected]>2013-02-25 12:25:04 +0900
committerYukihiro Matz Matsumoto <[email protected]>2013-02-25 12:25:04 +0900
commitd8d189711deb5df2e27947ae4ecc8dd7a6b96b54 (patch)
tree0e36abee232bcc0836d34bb29379f66f509da164 /test
parent815177afc7f5cef8e447bb9f2878d49fd0bd615c (diff)
parentf8bdc10cb153bbb55f49596d9c6b67a781cc8c14 (diff)
downloadmruby-d8d189711deb5df2e27947ae4ecc8dd7a6b96b54.tar.gz
mruby-d8d189711deb5df2e27947ae4ecc8dd7a6b96b54.zip
Merge branch 'pr-mrbtest-assert-ext' of https://github.com/iij/mruby into iij-pr-mrbtest-assert-ext
Diffstat (limited to 'test')
-rw-r--r--test/assert.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/assert.rb b/test/assert.rb
index 9f3231cd4..38bdfab20 100644
--- a/test/assert.rb
+++ b/test/assert.rb
@@ -79,6 +79,49 @@ def assert_nil(obj, msg = nil)
assert_true(obj.nil?, msg, diff)
end
+def assert_includes(collection, obj, msg = nil)
+ msg = "Expected #{collection.inspect} to include #{obj.inspect}" unless msg
+ diff = " Collection: #{collection.inspect}\n" +
+ " Object: #{obj.inspect}"
+ assert_true(collection.include?(obj), msg, diff)
+end
+
+def assert_instance_of(klass, obj, msg = nil)
+ msg = "Expected #{obj.inspect} to be an instance of #{klass}, not #{obj.class}" unless msg
+ assert_true(obj.instance_of?(klass), msg)
+end
+
+def assert_kind_of(klass, obj, msg = nil)
+ msg = "Expected #{obj.inspect} to be an kind of #{klass}, not #{obj.class}" unless msg
+ assert_true(obj.kind_of?(klass), msg)
+end
+
+def assert_raises(*exp)
+ if $mrbtest_assert
+ $mrbtest_assert_idx += 1
+ msg = exp.last.class == String ? exp.pop : nil
+ msg = msg.to_s + " : " if msg
+ should_raise = false
+ begin
+ yield
+ should_raise = true
+ rescue Exception => e
+ msg = "#{msg}#{exp.inspect} exception expected, not"
+ diff = " Class: <#{e.class}>\n" +
+ " Message: #{e.message}"
+ if exp.any?{|ex| ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class }
+ $mrbtest_assert.push([$mrbtest_assert_idx, msg, diff])
+ end
+ end
+
+ exp = exp.first if exp.first
+ if should_raise
+ msg = "#{msg}#{exp.inspect} expected but nothing was raised."
+ $mrbtest_assert.push([$mrbtest_assert_idx, msg, nil])
+ end
+ end
+end
+
##
# Report the test result and print all assertions
# which were reported broken.