Class: Aruba::Matchers::BaseMatcher

Inherits:
Object
  • Object
show all
Includes:
DefaultFailureMessages, HashFormatting
Defined in:
lib/aruba/matchers/base/base_matcher.rb

Overview

Base Matcher

Direct Known Subclasses

IncludeAnObject

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

Instance Method Summary collapse

Methods included from DefaultFailureMessages

#failure_message, #failure_message_when_negated, has_default_failure_messages?

Methods included from HashFormatting

improve_hash_formatting

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

#actualObject (readonly)


15
16
17
# File 'lib/aruba/matchers/base/base_matcher.rb', line 15

def actual
  @actual
end

#expectedObject (readonly)


15
16
17
# File 'lib/aruba/matchers/base/base_matcher.rb', line 15

def expected
  @expected
end

#rescued_exceptionObject (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

Returns:

  • (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.

Returns:

  • (Boolean)

25
26
27
28
# File 'lib/aruba/matchers/base/base_matcher.rb', line 25

def matches?(actual)
  @actual = actual
  match(expected, actual)
end