Class: RSpec::Matchers::BuiltIn::MatchArray

Inherits:
BaseMatcher
  • Object
show all
Defined in:
lib/rspec/matchers/built_in/match_array.rb

Instance Attribute Summary

Attributes inherited from BaseMatcher

#actual, #expected, #rescued_exception

Instance Method Summary collapse

Methods inherited from BaseMatcher

#==, #diffable?, #initialize, #match_unless_raises, #matches?

Methods included from Pretty

#_pretty_print, #expected_to_sentence, #name, #name_to_sentence, #split_words, #to_sentence, #underscore

Constructor Details

This class inherits a constructor from RSpec::Matchers::BuiltIn::BaseMatcher

Instance Method Details

#descriptionObject



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

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

#failure_message_for_shouldObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rspec/matchers/built_in/match_array.rb', line 12

def failure_message_for_should
  if actual.respond_to? :to_ary
    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?
  else
    message = "expected an array, actual collection was #{actual.inspect}"
  end

  message
end

#failure_message_for_should_notObject



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

def failure_message_for_should_not
  "Matcher does not support should_not"
end

#match(expected, actual) ⇒ Object



5
6
7
8
9
10
# File 'lib/rspec/matchers/built_in/match_array.rb', line 5

def match(expected, actual)
  return false unless actual.respond_to? :to_ary
  @extra_items = difference_between_arrays(actual, expected)
  @missing_items = difference_between_arrays(expected, actual)
  @extra_items.empty? & @missing_items.empty?
end