Method missing kwargs test failure:

Fail: Method#call with undefined method -- only kwargs (mrbgems: mruby-method)
 - Assertion[6]
    NoMethodError exception expected, not
    Class: <TypeError>
    Message: <Array cannot be converted to Hash>
 - Assertion[9]
    Expected: {:kwarg1=>:val1, :kwarg2=>:val2}
      Actual: [:foo]
This commit is contained in:
Pete Kinnecom
2024-07-19 20:36:46 +00:00
parent 1fc8c20723
commit 509590c18d
+30
View File
@@ -138,6 +138,36 @@ assert 'Method#call with undefined method' do
assert_raise(NoMethodError) { m.call(:arg1, :arg2) }
end
assert 'Method#call with undefined method -- only kwargs' do
c = Class.new {
attr_accessor :m, :argv, :kwargs
def respond_to_missing?(m, b)
m == :foo
end
def method_missing(m, *argv, **kwargs)
@m = m
@argv = argv
@kwargs = kwargs
super
end
}
cc = c.new
assert_kind_of Method, cc.method(:foo)
# Calling cc.method(:foo) works
assert_raise(NoMethodError) { cc.method(:foo).call(kwarg1: :val1, kwarg2: :val2) }
assert_equal :foo, cc.m
assert_equal [], cc.argv
assert_equal({ kwarg1: :val1, kwarg2: :val2 }, cc.kwargs)
# calling cc.foo fails
assert_raise(NoMethodError) { cc.foo(kwarg1: :val1, kwarg2: :val2) }
assert_equal :foo, cc.m
assert_equal [], cc.argv
assert_equal({ kwarg1: :val1, kwarg2: :val2 }, cc.kwargs)
end
assert 'Method#source_location' do
skip if proc{}.source_location.nil?