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
|
@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Fixed
|
||||
- Fix usage of `be ===` and `be =~` [#34](https://github.com/icy-arctic-fox/spectator/issues/34)
|
||||
|
||||
### Changed
|
||||
- Elegantly handle missing/undefined methods with `have_attributes` matcher.
|
||||
|
||||
## [0.10.1] - 2021-09-16
|
||||
### Fixed
|
||||
- Fix `Spectator.configure` block calls to `filter_run_excluding` and `filter_run_including`. [#61](https://gitlab.com/arctic-fox/spectator/-/issues/61)
|
||||
|
|
|
@ -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…
Reference in a new issue