Class: IncludeMatcher

Inherits:
Object show all
Defined in:
lib/mspec/matchers/include.rb

Instance Method Summary collapse

Constructor Details

#initialize(*expected) ⇒ IncludeMatcher

Returns a new instance of IncludeMatcher


2
3
4
# File 'lib/mspec/matchers/include.rb', line 2

def initialize(*expected)
  @expected = expected
end

Instance Method Details

#failure_messageObject


17
18
19
# File 'lib/mspec/matchers/include.rb', line 17

def failure_message
  ["Expected #{@actual.inspect}", "to include #{@element.inspect}"]
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)

6
7
8
9
10
11
12
13
14
15
# File 'lib/mspec/matchers/include.rb', line 6

def matches?(actual)
  @actual = actual
  @expected.each do |e|
    @element = e
    unless @actual.include?(e)
      return false
    end
  end
  return true
end

#negative_failure_messageObject


21
22
23
# File 'lib/mspec/matchers/include.rb', line 21

def negative_failure_message
  ["Expected #{@actual.inspect}", "not to include #{@element.inspect}"]
end