class RSpec::Matchers::BuiltIn::Compound

@api private Base class for `and` and `or` compound matchers.

Attributes

matcher_1[R]

@private

matcher_2[R]

@private

Public Class Methods

new(matcher_1, matcher_2) click to toggle source
# File lib/rspec/matchers/built_in/compound.rb, line 10
def initialize(matcher_1, matcher_2)
  @matcher_1 = matcher_1
  @matcher_2 = matcher_2
end

Public Instance Methods

description() click to toggle source

@api private @return [String]

# File lib/rspec/matchers/built_in/compound.rb, line 23
def description
  singleline_message(matcher_1.description, matcher_2.description)
end
does_not_match?(actual) click to toggle source

@private

# File lib/rspec/matchers/built_in/compound.rb, line 16
def does_not_match?(actual)
  raise NotImplementedError,
    "`expect(...).not_to matcher.#{conjunction} matcher` is not supported"
end

Private Instance Methods

compound_failure_message() click to toggle source
# File lib/rspec/matchers/built_in/compound.rb, line 41
def compound_failure_message
  message_1 = matcher_1.failure_message
  message_2 = matcher_2.failure_message

  if multiline?(message_1) || multiline?(message_2)
    multiline_message(message_1, message_2)
  else
    singleline_message(message_1, message_2)
  end
end
indent_multiline_message(message) click to toggle source
# File lib/rspec/matchers/built_in/compound.rb, line 35
def indent_multiline_message(message)
  message.lines.map do |line|
    line =~ /\S/ ? '   ' + line : line
  end.join
end
initialize_copy(other) click to toggle source
Calls superclass method
# File lib/rspec/matchers/built_in/compound.rb, line 29
def initialize_copy(other)
  @matcher_1 = @matcher_1.clone
  @matcher_2 = @matcher_2.clone
  super
end
multiline?(message) click to toggle source
# File lib/rspec/matchers/built_in/compound.rb, line 60
def multiline?(message)
  message.lines.count > 1
end
multiline_message(message_1, message_2) click to toggle source
# File lib/rspec/matchers/built_in/compound.rb, line 52
def multiline_message(message_1, message_2)
  [
    indent_multiline_message(message_1.sub(/\n+\z/, '')),
    "...#{conjunction}:",
    indent_multiline_message(message_2.sub(/\A\n+/, ''))
  ].join("\n\n")
end
singleline_message(message_1, message_2) click to toggle source
# File lib/rspec/matchers/built_in/compound.rb, line 64
def singleline_message(message_1, message_2)
  [message_1, conjunction, message_2].join(' ')
end