Class: RSpec::Dry::Struct::Matcher
- Inherits:
-
Object
- Object
- RSpec::Dry::Struct::Matcher
- Defined in:
- lib/rspec/dry/struct/matcher.rb
Instance Attribute Summary collapse
-
#attr_name ⇒ Object
readonly
Returns the value of attribute attr_name.
-
#attr_type ⇒ Object
readonly
Returns the value of attribute attr_type.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(attr_name, attr_type = nil) ⇒ Matcher
constructor
A new instance of Matcher.
- #matches?(actual) ⇒ Boolean
Constructor Details
#initialize(attr_name, attr_type = nil) ⇒ Matcher
Returns a new instance of Matcher.
7 8 9 10 |
# File 'lib/rspec/dry/struct/matcher.rb', line 7 def initialize(attr_name, attr_type = nil) @attr_name = attr_name @attr_type = attr_type end |
Instance Attribute Details
#attr_name ⇒ Object (readonly)
Returns the value of attribute attr_name.
5 6 7 |
# File 'lib/rspec/dry/struct/matcher.rb', line 5 def attr_name @attr_name end |
#attr_type ⇒ Object (readonly)
Returns the value of attribute attr_type.
5 6 7 |
# File 'lib/rspec/dry/struct/matcher.rb', line 5 def attr_type @attr_type end |
Instance Method Details
#description ⇒ Object
22 23 24 |
# File 'lib/rspec/dry/struct/matcher.rb', line 22 def description "have #{@attr_name.inspect} attribute" end |
#failure_message ⇒ Object
26 27 28 29 |
# File 'lib/rspec/dry/struct/matcher.rb', line 26 def return (@actual) if @actual_attribute.nil? (@actual) end |
#failure_message_when_negated ⇒ Object
31 32 33 |
# File 'lib/rspec/dry/struct/matcher.rb', line 31 def "#{unexpected_message(@actual)}, but it was found" end |
#matches?(actual) ⇒ Boolean
12 13 14 15 16 17 18 19 20 |
# File 'lib/rspec/dry/struct/matcher.rb', line 12 def matches?(actual) @actual = actual attribute = actual.schema.find do |attr| attr.name == @attr_name end @actual_attribute = attribute.type if attribute attr_present? && correct_attr_type? end |