Class: Spec::Matchers::Include

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/rspec-1.1.12/lib/spec/matchers/include.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(*expecteds) ⇒ Include

Returns a new instance of Include.



6
7
8
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/include.rb', line 6

def initialize(*expecteds)
  @expecteds = expecteds
end

Instance Method Details

#descriptionObject



36
37
38
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/include.rb', line 36

def description
  "include #{_pretty_print(@expecteds)}"
end

#failure_messageObject



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

def failure_message
  _message
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/include.rb', line 10

def matches?(actual)
  @actual = actual
  @expecteds.each do |expected|
    if actual.is_a?(Hash)
      if expected.is_a?(Hash)
        expected.each_pair do |k,v|
          return false unless actual[k] == v
        end
      else
        return false unless actual.has_key?(expected)
      end
    else
      return false unless actual.include?(expected)
    end
  end
  true
end

#negative_failure_messageObject



32
33
34
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/include.rb', line 32

def negative_failure_message
  _message("not ")
end