diff options
Diffstat (limited to 'test/helper.rb')
-rw-r--r-- | test/helper.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/helper.rb b/test/helper.rb new file mode 100644 index 0000000..d628122 --- /dev/null +++ b/test/helper.rb @@ -0,0 +1,25 @@ +require "asn1kit" +require "test/unit" +require "pp" + +class ASN1KitTestCase < Test::Unit::TestCase + def B(ary) + [ary.join].pack("H*") + end + + def assert_raise_with_message(exception, pattern, msg = nil, &block) + unless pattern.is_a?(String) or pattern.is_a?(Regexp) + raise TypeError, "expected message must be a kind of String or Regexp" + end + + msg ||= "Exception %s with message %p is raised" % [exception, pattern] + raised = assert_raise(exception, msg) { yield } + + if pattern.is_a?(Regexp) + assert_match(pattern, raised.message, msg) + else + assert_equal(pattern, raised.message, msg) + end + raised + end +end |