Class: Spec::Matchers::Include

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

def initialize(*expecteds)
  @expecteds = expecteds
end

Instance Method Details

#descriptionObject



36
37
38
# File 'lib/spec/matchers/include.rb', line 36

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

#failure_message_for_shouldObject



28
29
30
# File 'lib/spec/matchers/include.rb', line 28

def failure_message_for_should
  _message
end

#failure_message_for_should_notObject



32
33
34
# File 'lib/spec/matchers/include.rb', line 32

def failure_message_for_should_not
  _message("not ")
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/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