Class: Aruba::Matchers::BaseMatcher
- Inherits:
-
Object
- Object
- Aruba::Matchers::BaseMatcher
- Includes:
- DefaultFailureMessages, HashFormatting
- Defined in:
- lib/aruba/matchers/base/base_matcher.rb
Overview
Base Matcher
Direct Known Subclasses
Defined Under Namespace
Modules: DefaultFailureMessages, HashFormatting
Constant Summary collapse
- UNDEFINED =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Used to detect when no arg is passed to
initialize
.nil
cannot be used because it's a valid value to pass. Object.new.freeze
Instance Attribute Summary collapse
- #actual ⇒ Object readonly
- #expected ⇒ Object readonly
- #rescued_exception ⇒ Object readonly
Instance Method Summary collapse
-
#description_of(object) ⇒ Object
Returns the description of the given object in a way that is aware of composed matchers.
-
#initialize(expected = UNDEFINED) ⇒ BaseMatcher
constructor
A new instance of BaseMatcher.
- #iterable? ⇒ Boolean
-
#matches?(actual) ⇒ Boolean
private
Indicates if the match is successful.
Methods included from DefaultFailureMessages
#failure_message, #failure_message_when_negated, has_default_failure_messages?
Methods included from HashFormatting
Constructor Details
#initialize(expected = UNDEFINED) ⇒ BaseMatcher
Returns a new instance of BaseMatcher.
17 18 19 |
# File 'lib/aruba/matchers/base/base_matcher.rb', line 17 def initialize(expected = UNDEFINED) @expected = expected unless UNDEFINED.equal?(expected) end |
Instance Attribute Details
#actual ⇒ Object (readonly)
15 16 17 |
# File 'lib/aruba/matchers/base/base_matcher.rb', line 15 def actual @actual end |
#expected ⇒ Object (readonly)
15 16 17 |
# File 'lib/aruba/matchers/base/base_matcher.rb', line 15 def expected @expected end |
#rescued_exception ⇒ Object (readonly)
15 16 17 |
# File 'lib/aruba/matchers/base/base_matcher.rb', line 15 def rescued_exception @rescued_exception end |
Instance Method Details
#description_of(object) ⇒ Object
Returns the description of the given object in a way that is
aware of composed matchers. If the object is a matcher with
a description
method, returns the description; otherwise
returns object.inspect
.
91 92 93 |
# File 'lib/aruba/matchers/base/base_matcher.rb', line 91 def description_of(object) Aruba::Matchers::ObjectFormatter.format(object) end |
#iterable? ⇒ Boolean
30 31 32 |
# File 'lib/aruba/matchers/base/base_matcher.rb', line 30 def iterable? @actual.respond_to?(:each_with_index) end |
#matches?(actual) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Indicates if the match is successful. Delegates to match
, which
should be defined on a subclass. Takes care of consistently
initializing the actual
attribute.
25 26 27 28 |
# File 'lib/aruba/matchers/base/base_matcher.rb', line 25 def matches?(actual) @actual = actual match(expected, actual) end |