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_or_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]
Calls superclass method
RSpec::Matchers::BuiltIn::BaseMatcher#description
# File lib/rspec/matchers/built_in/start_or_end_with.rb, line 27 def description return super unless Hash === expected english_name = EnglishPhrasing.split_words(self.class.matcher_name) description_of_expected = surface_descriptions_in(expected).inspect "#{english_name} #{description_of_expected}" end
failure_message()
click to toggle source
@api private @return [String]
Calls superclass method
RSpec::Matchers::BuiltIn::BaseMatcher::DefaultFailureMessages#failure_message
# File lib/rspec/matchers/built_in/start_or_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
match(_expected, actual)
click to toggle source
# File lib/rspec/matchers/built_in/start_or_end_with.rb, line 36 def match(_expected, actual) return false unless actual.respond_to?(:[]) begin return true if subsets_comparable? && subset_matches? element_matches? rescue ArgumentError @actual_does_not_have_ordered_elements = true return false end end
subsets_comparable?()
click to toggle source
# File lib/rspec/matchers/built_in/start_or_end_with.rb, line 48 def subsets_comparable? # Structs support the Enumerable interface but don't really have # the semantics of a subset of a larger set... return false if Struct === expected expected.respond_to?(:length) end