Class: Minicrest::CollectionItemMatcher Private

Inherits:
Matcher
  • Object
show all
Defined in:
lib/minicrest/collection_item_matcher.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Base class for matchers that apply a matcher to items in a collection.

Direct Known Subclasses

AllItems, NoItems, SomeItems

Instance Method Summary collapse

Methods inherited from Matcher

#&, #description, #failure_message, #matches?, #negated_failure_message, #|

Constructor Details

#initialize(item_matcher) ⇒ CollectionItemMatcher

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.

Creates a new collection item matcher.

Parameters:

  • item_matcher (Matcher)

    the matcher to apply to each item



13
14
15
16
# File 'lib/minicrest/collection_item_matcher.rb', line 13

def initialize(item_matcher)
  super()
  @item_matcher = item_matcher
end

Instance Method Details

#collection?(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.

Checks if actual is a collection.

Parameters:

  • actual (Object)

    the value to check

Returns:

  • (Boolean)

    true if actual is enumerable



22
23
24
25
26
# File 'lib/minicrest/collection_item_matcher.rb', line 22

def collection?(actual)
  actual.is_a?(Enumerable) || actual.respond_to?(:each)
rescue NoMethodError
  false
end