Class: RSpec::Matchers::MatchArray

Inherits:
Object
  • Object
show all
Includes:
Pretty
Defined in:
lib/rspec/matchers/match_array.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from Pretty

#_pretty_print, #split_words, #to_sentence

Constructor Details

#initialize(expected) ⇒ MatchArray

Returns a new instance of MatchArray.



7
8
9
# File 'lib/rspec/matchers/match_array.rb', line 7

def initialize(expected)
  @expected = expected
end

Instance Method Details

#descriptionObject



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

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

#failure_message_for_shouldObject



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

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_notObject



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

def failure_message_for_should_not
  "Matcher does not support should_not"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


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

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