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

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

Constant Summary

Constant Summary

Constants inherited from BaseMatcher

BaseMatcher::UNDEFINED

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?, #supports_block_expectations?

Methods included from MatchAliases

#==, #===

Methods included from Pretty

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

Constructor Details

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

Instance Method Details

- (Object) description



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

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

- (Object) failure_message_for_should



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

- (Object) failure_message_for_should_not



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

- (Object) match(expected, actual)



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