test/test_rubype.rb in rubype-0.2.3 vs test/test_rubype.rb in rubype-0.2.4

- old
+ new

@@ -89,15 +89,25 @@ assert_correct_type({ [Any, Any] => Any }, [@numeric, @symbol], @numeric) end def test_type_info klass = Class.new.class_eval <<-RUBY_CODE - def test_mth + def test_mth(n1, n2) end typesig :test_mth, [Numeric, Numeric] => String RUBY_CODE + Object.const_set('MyClass', klass) - assert_equal klass.new.method(:test_mth).type_info, { [Numeric, Numeric] => String } + meth = klass.new.method(:test_mth) + assert_equal meth.type_info, { [Numeric, Numeric] => String } + assert_equal meth.arg_types, [Numeric, Numeric] + assert_equal meth.return_type, String + + err = assert_raises(Rubype::ReturnTypeError) { meth.(1,2) } + assert_equal err.message, "Expected MyClass#test_mth to return String but got nil instead" + + err = assert_raises(Rubype::ArgumentTypeError) { meth.(1,'2') } + assert_equal err.message, "Expected MyClass#test_mth's 2th argument to be Numeric but got \"2\" instead" end private def assert_equal_to_s(str, val) assert_equal str, val.to_s