Class: Spec::Matchers::MatchArray

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/rspec-1.1.12/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/gems/rspec-1.1.12/lib/spec/matchers/match_array.rb', line 6

def initialize(expected)
  @expected = expected
end

Instance Method Details

#descriptionObject



29
30
31
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/match_array.rb', line 29

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

#failure_messageObject



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

def failure_message
  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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
# File 'lib/gems/rspec-1.1.12/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

#negative_failure_messageObject



25
26
27
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/match_array.rb', line 25

def negative_failure_message
  "Matcher does not support should_not"
end