Class: Mocktail::Matchers::Includes

Inherits:
Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mocktail/matchers/includes.rb,
lib/mocktail/sorbet/mocktail/matchers/includes.rb

Direct Known Subclasses

IncludesHash, IncludesKey, IncludesString

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#is_mocktail_matcher?

Constructor Details

#initialize(*expecteds) ⇒ Includes

Returns a new instance of Includes.



9
10
11
# File 'lib/mocktail/matchers/includes.rb', line 9

def initialize(*expecteds)
  @expecteds = expecteds
end

Class Method Details

.matcher_nameObject



5
6
7
# File 'lib/mocktail/matchers/includes.rb', line 5

def self.matcher_name
  :includes
end

Instance Method Details

#inspectObject



22
23
24
# File 'lib/mocktail/matchers/includes.rb', line 22

def inspect
  "#{self.class.matcher_name}(#{@expecteds.map(&:inspect).join(", ")})"
end

#match?(actual) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
# File 'lib/mocktail/matchers/includes.rb', line 13

def match?(actual)
  @expecteds.all? { |expected|
    (actual.respond_to?(:include?) && actual.include?(expected)) ||
      (actual.is_a?(Hash) && expected.is_a?(Hash) && expected.all? { |k, v| actual[k] == v })
  }
rescue
  false
end