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
18 19 20 |
# File 'lib/rspec/dry/struct/matcher.rb', line 18 def description "have #{@attr_name.inspect} attribute" end |
#failure_message ⇒ Object
22 23 24 25 |
# File 'lib/rspec/dry/struct/matcher.rb', line 22 def return (@actual) if @actual_attribute.nil? (@actual) end |
#failure_message_when_negated ⇒ Object
27 28 29 |
# File 'lib/rspec/dry/struct/matcher.rb', line 27 def "#{(@actual)}, but it was found" end |
#matches?(actual) ⇒ Boolean
12 13 14 15 16 |
# File 'lib/rspec/dry/struct/matcher.rb', line 12 def matches?(actual) @actual = actual @actual_attribute = actual.schema[@attr_name] attr_present? && correct_attr_type? end |