Class: BaconExpect::Matcher::MatchArray

Inherits:
Object
  • Object
show all
Defined in:
lib/bacon-expect/matchers/match_array.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_array) ⇒ MatchArray

Returns a new instance of MatchArray.



3
4
5
# File 'lib/bacon-expect/matchers/match_array.rb', line 3

def initialize(expected_array)
  @expected_array = expected_array
end

Instance Method Details

#fail!(subject_array, negated) ⇒ Object

Raises:



17
18
19
# File 'lib/bacon-expect/matchers/match_array.rb', line 17

def fail!(subject_array, negated)
  raise FailedExpectation.new(FailMessageRenderer.message_for_match_array(negated, subject_array, @expected_array))
end

#matches?(subject_array) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
# File 'lib/bacon-expect/matchers/match_array.rb', line 7

def matches?(subject_array)
  return false unless subject_array.size == @expected_array.size
  array_copy = subject_array.dup
  @expected_array.all? do |item|
    has = array_copy.include?(item)
    array_copy.delete(item) if has
    has
  end
end