class RSpec::Matchers::BuiltIn::MatchArray

Public Instance Methods

description() click to toggle source
# File lib/rspec/matchers/built_in/match_array.rb, line 23
def description
  "contain exactly #{_pretty_print(expected)}"
end
failure_message_for_should() click to toggle source
# File lib/rspec/matchers/built_in/match_array.rb, line 11
def failure_message_for_should
  message =  "expected collection contained:  #{safe_sort(expected).inspect}\n"
  message += "actual collection contained:    #{safe_sort(actual).inspect}\n"
  message += "the missing elements were:      #{safe_sort(@missing_items).inspect}\n" unless @missing_items.empty?
  message += "the extra elements were:        #{safe_sort(@extra_items).inspect}\n"   unless @extra_items.empty?
  message
end
failure_message_for_should_not() click to toggle source
# File lib/rspec/matchers/built_in/match_array.rb, line 19
def failure_message_for_should_not
  "Matcher does not support should_not"
end
match(expected, actual) click to toggle source
# File lib/rspec/matchers/built_in/match_array.rb, line 5
def match(expected, actual)
  @extra_items = difference_between_arrays(actual, expected)
  @missing_items = difference_between_arrays(expected, actual)
  @extra_items.empty? & @missing_items.empty?
end

Private Instance Methods

difference_between_arrays(array_1, array_2) click to toggle source
# File lib/rspec/matchers/built_in/match_array.rb, line 33
def difference_between_arrays(array_1, array_2)
  difference = array_1.dup
  array_2.each do |element|
    if index = difference.index(element)
      difference.delete_at(index)
    end
  end
  difference
end
safe_sort(array) click to toggle source
# File lib/rspec/matchers/built_in/match_array.rb, line 29
def safe_sort(array)
  array.sort rescue array
end