mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Handle undefined methods with have_attributes matcher
Instead of producing a compilation error on missing/undefind methods, substitute in an "undefined" value. This shows better output to the user.
This commit is contained in:
parent
20e17851c6
commit
99ced17516
2 changed files with 14 additions and 1 deletions
|
@ -10,6 +10,16 @@ module Spectator::Matchers
|
|||
# Each key in the tuple is the attribute/method name,
|
||||
# and the corresponding value is the expected value to match against.
|
||||
struct AttributesMatcher(ExpectedType) < Matcher
|
||||
# Stand-in for undefined methods on types.
|
||||
private module Undefined
|
||||
extend self
|
||||
|
||||
# Text displayed when a method is undefined.
|
||||
def inspect(io)
|
||||
io << "<Method undefined>"
|
||||
end
|
||||
end
|
||||
|
||||
# Expected value and label.
|
||||
private getter expected
|
||||
|
||||
|
@ -51,7 +61,7 @@ module Spectator::Matchers
|
|||
{% begin %}
|
||||
{
|
||||
{% for attribute in ExpectedType.keys %}
|
||||
{{attribute}}: object.{{attribute}},
|
||||
{{attribute}}: object.responds_to?({{attribute.symbolize}}) ? object.{{attribute}} : Undefined,
|
||||
{% end %}
|
||||
}
|
||||
{% end %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue