Class: Spec::Matchers::MatchArray

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/matchers/match_array.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ MatchArray

Returns a new instance of MatchArray.



6
7
8
# File 'lib/spec/matchers/match_array.rb', line 6

def initialize(expected)
  @expected = expected
end

Instance Method Details

#descriptionObject



29
30
31
# File 'lib/spec/matchers/match_array.rb', line 29

def description
  "contain exactly #{_pretty_print(@expected)}"
end

#failure_message_for_shouldObject



17
18
19
20
21
22
23
# File 'lib/spec/matchers/match_array.rb', line 17

def failure_message_for_should
  message =  "expected collection contained:  #{@expected.sort.inspect}\n"
  message += "actual collection contained:    #{@actual.sort.inspect}\n"
  message += "the missing elements were:      #{@missing_items.sort.inspect}\n" unless @missing_items.empty?
  message += "the extra elements were:        #{@extra_items.sort.inspect}\n" unless @extra_items.empty?
  message
end

#failure_message_for_should_notObject



25
26
27
# File 'lib/spec/matchers/match_array.rb', line 25

def failure_message_for_should_not
  "Matcher does not support should_not"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
# File 'lib/spec/matchers/match_array.rb', line 10

def matches?(actual)
  @actual = actual        
  @extra_items = difference_between_arrays(@actual, @expected)
  @missing_items = difference_between_arrays(@expected, @actual)
  @extra_items.empty? & @missing_items.empty?
end