Class: ElabsMatchers::Matchers::OnlyInclude::OnlyIncludeMatcher

Inherits:
Struct
  • Object
show all
Defined in:
lib/elabs_matchers/matchers/only_include.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual



7
8
9
# File 'lib/elabs_matchers/matchers/only_include.rb', line 7

def actual
  @actual
end

#elementsObject

Returns the value of attribute elements

Returns:

  • (Object)

    the current value of elements



6
7
8
# File 'lib/elabs_matchers/matchers/only_include.rb', line 6

def elements
  @elements
end

Instance Method Details

#failure_messageObject Also known as: failure_message_for_should



16
17
18
# File 'lib/elabs_matchers/matchers/only_include.rb', line 16

def failure_message
  "Expected #{actual.inspect} to only include #{elements.inspect}."
end

#failure_message_when_negatedObject Also known as: failure_message_for_should_not



21
22
23
# File 'lib/elabs_matchers/matchers/only_include.rb', line 21

def failure_message_when_negated
  "Expected #{actual.inspect} to not only include #{elements.inspect}, but it did."
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
# File 'lib/elabs_matchers/matchers/only_include.rb', line 9

def matches?(actual)
  @actual = actual
  elements.uniq.length == elements.length and
  actual.length == elements.length and
  elements.all? { |element| actual.include?(element) }
end