Module: RBS::Test::Errors
- Defined in:
- lib/rbs/test/errors.rb
Defined Under Namespace
Classes: ArgumentError, ArgumentTypeError, BlockArgumentError, BlockArgumentTypeError, BlockReturnTypeError, MissingBlockError, ReturnTypeError, UnexpectedBlockError, UnresolvedOverloadingError
Class Method Summary
collapse
Class Method Details
24
25
26
27
28
29
30
|
# File 'lib/rbs/test/errors.rb', line 24
def self.format_param(param)
if param.name
"`#{param.type}` (#{param.name})"
else
"`#{param.type}`"
end
end
|
.inspect_(obj) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/rbs/test/errors.rb', line 35
def self.inspect_(obj)
if RESPOND_TO.bind_call(obj, :inspect)
obj.inspect
else
Test::INSPECT.bind(obj).call end
end
|
.method_tag(error) ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/rbs/test/errors.rb', line 43
def self.method_tag(error)
if error.klass.singleton_class?
name = inspect_(error.klass).sub(/\A#<Class:(.*)>\z/, '\1')
method_name = ".#{error.method_name}"
else
name = error.klass.name
method_name = "##{error.method_name}"
end
"[#{name}#{method_name}]"
end
|
.to_string(error) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/rbs/test/errors.rb', line 54
def self.to_string(error)
case error
when ArgumentTypeError
"#{method_tag(error)} ArgumentTypeError: expected #{format_param error.param} but given `#{inspect_(error.value)}`"
when BlockArgumentTypeError
"#{method_tag(error)} BlockArgumentTypeError: expected #{format_param error.param} but given `#{inspect_(error.value)}`"
when ArgumentError
"#{method_tag(error)} ArgumentError: expected method type #{error.method_type}"
when BlockArgumentError
"#{method_tag(error)} BlockArgumentError: expected method type #{error.method_type}"
when ReturnTypeError
"#{method_tag(error)} ReturnTypeError: expected `#{error.type}` but returns `#{inspect_(error.value)}`"
when BlockReturnTypeError
"#{method_tag(error)} BlockReturnTypeError: expected `#{error.type}` but returns `#{inspect_(error.value)}`"
when UnexpectedBlockError
"#{method_tag(error)} UnexpectedBlockError: unexpected block is given for `#{error.method_type}`"
when MissingBlockError
"#{method_tag(error)} MissingBlockError: required block is missing for `#{error.method_type}`"
when UnresolvedOverloadingError
"#{method_tag(error)} UnresolvedOverloadingError: couldn't find a suitable overloading"
else
raise "Unexpected error: #{inspect_(error)}"
end
end
|