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
22
23
24
25
26
27
28
|
# File 'lib/rbs/test/errors.rb', line 22
def self.format_param(param)
if param.name
"`#{param.type}` (#{param.name})"
else
"`#{param.type}`"
end
end
|
.inspect_(obj) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/rbs/test/errors.rb', line 30
def self.inspect_(obj)
if obj.respond_to?(:inspect)
obj.inspect
else
Test::INSPECT.bind(obj).call end
end
|
.to_string(error) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/rbs/test/errors.rb', line 38
def self.to_string(error)
method = "#{error.klass.name}#{error.method_name}"
case error
when ArgumentTypeError
"[#{method}] ArgumentTypeError: expected #{format_param error.param} but given `#{inspect_(error.value)}`"
when BlockArgumentTypeError
"[#{method}] BlockArgumentTypeError: expected #{format_param error.param} but given `#{inspect_(error.value)}`"
when ArgumentError
"[#{method}] ArgumentError: expected method type #{error.method_type}"
when BlockArgumentError
"[#{method}] BlockArgumentError: expected method type #{error.method_type}"
when ReturnTypeError
"[#{method}] ReturnTypeError: expected `#{error.type}` but returns `#{inspect_(error.value)}`"
when BlockReturnTypeError
"[#{method}] BlockReturnTypeError: expected `#{error.type}` but returns `#{inspect_(error.value)}`"
when UnexpectedBlockError
"[#{method}] UnexpectedBlockError: unexpected block is given for `#{error.method_type}`"
when MissingBlockError
"[#{method}] MissingBlockError: required block is missing for `#{error.method_type}`"
when UnresolvedOverloadingError
"[#{method}] UnresolvedOverloadingError: couldn't find a suitable overloading"
else
raise "Unexpected error: #{inspect_(error)}"
end
end
|