Class: MotionSpec::Matcher::MatchArray

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-spec/matcher/match_array.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_array) ⇒ MatchArray

Returns a new instance of MatchArray.



5
6
7
# File 'lib/motion-spec/matcher/match_array.rb', line 5

def initialize(expected_array)
  @expected_array = expected_array
end

Instance Method Details

#fail!(subject_array, negated) ⇒ Object

Raises:



19
20
21
22
23
24
25
# File 'lib/motion-spec/matcher/match_array.rb', line 19

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)


9
10
11
12
13
14
15
16
17
# File 'lib/motion-spec/matcher/match_array.rb', line 9

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