class RSpec::Matchers::BuiltIn::StartAndEndWith

@api private Base class for the `end_with` and `start_with` matchers. Not intended to be instantiated directly.

Public Class Methods

new(*expected) click to toggle source
# File lib/rspec/matchers/built_in/start_and_end_with.rb, line 8
def initialize(*expected)
  @actual_does_not_have_ordered_elements = false
  @expected = expected.length == 1 ? expected.first : expected
end

Public Instance Methods

description() click to toggle source

@api private @return [String]

# File lib/rspec/matchers/built_in/start_and_end_with.rb, line 27
def description
  return super unless Hash === expected
  "#{name_to_sentence} #{surface_descriptions_in(expected).inspect}"
end
failure_message() click to toggle source

@api private @return [String]

# File lib/rspec/matchers/built_in/start_and_end_with.rb, line 15
def failure_message
  super.tap do |msg|
    if @actual_does_not_have_ordered_elements
      msg << ", but it does not have ordered elements"
    elsif !actual.respond_to?(:[])
      msg << ", but it cannot be indexed using #[]"
    end
  end
end

Private Instance Methods

actual_is_unordered() click to toggle source
# File lib/rspec/matchers/built_in/start_and_end_with.rb, line 46
def actual_is_unordered
  ArgumentError.new("#{actual.inspect} does not have ordered elements")
end
match(expected, actual) click to toggle source
# File lib/rspec/matchers/built_in/start_and_end_with.rb, line 34
def match(expected, actual)
  return false unless actual.respond_to?(:[])

  begin
    return subset_matches? if expected.respond_to?(:length)
    element_matches?
  rescue ArgumentError
    @actual_does_not_have_ordered_elements = true
    return false
  end
end