module RSpec::Matchers::Composable
def ===(value)
Delegates to `#matches?`. Allows matchers to be used in composable
def ===(value) matches?(value) end
def and(matcher)
- Note: - The negative form (`expect(...).not_to matcher.and other`)
def and(matcher) BuiltIn::Compound::And.new self, matcher end
def description_of(object)
supporting matcher arguments.
`failure_message_when_negated` implementation if you are
`description`, `failure_message` or
You are encouraged to use this in your custom matcher's
returns `object.inspect`.
a `description` method, returns the description; otherwise
aware of composed matchers. If the object is a matcher with
Returns the description of the given object in a way that is
def description_of(object) RSpec::Support::ObjectFormatter.format(object) end
def or(matcher)
- Note: - The negative form (`expect(...).not_to matcher.or other`)
def or(matcher) BuiltIn::Compound::Or.new self, matcher end
def should_enumerate?(item)
- Api: - private
def should_enumerate?(item) Array === item && item.none? { |subitem| subitem.equal?(item) } end
def surface_descriptions_in(item)
containing matchers.
supporting any arguments which may be a data structure
`failure_message_when_negated` implementation if you are
`description`, `failure_message` or
You are encouraged to use this in your custom matcher's
the normal `#inspect` output.
will provide descriptions of any contained matchers rather than
into a new data structure that, when `#inspect` is called on it,
Transforms the given data structure (typically a hash or array)
def surface_descriptions_in(item) if Matchers.is_a_describable_matcher?(item) DescribableItem.new(item) elsif Hash === item Hash[surface_descriptions_in(item.to_a)] elsif Struct === item || unreadable_io?(item) RSpec::Support::ObjectFormatter.format(item) elsif should_enumerate?(item) item.map { |subitem| surface_descriptions_in(subitem) } else item end end
def unreadable_io?(object)
- Api: - private
def unreadable_io?(object) return false unless IO === object object.each {} # STDOUT is enumerable but raises an error false rescue IOError true end
def values_match?(expected, actual)
-
actual
(Object
) -- the actual value -
expected
(Object
) -- what is expected
def values_match?(expected, actual) expected = with_matchers_cloned(expected) Support::FuzzyMatcher.values_match?(expected, actual) end
def with_matchers_cloned(object)
- Private: -
def with_matchers_cloned(object) if Matchers.is_a_matcher?(object) object.clone elsif Hash === object Hash[with_matchers_cloned(object.to_a)] elsif should_enumerate?(object) object.map { |subobject| with_matchers_cloned(subobject) } else object end end