Class: RSpec::Matchers::BuiltIn::StartOrEndWith Private

Inherits:
BaseMatcher
  • Object
show all
Defined in:
lib/rspec/matchers/built_in/start_or_end_with.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Base class for the end_with and start_with matchers. Not intended to be instantiated directly.

Direct Known Subclasses

EndWith, StartWith

Constant Summary

Constants inherited from BaseMatcher

BaseMatcher::UNDEFINED

Instance Method Summary collapse

Methods inherited from BaseMatcher

#diffable?, #expects_call_stack_jump?, #match_unless_raises, #matches?, #supports_block_expectations?

Methods included from BaseMatcher::DefaultFailureMessages

#failure_message_when_negated

Methods included from Composable

#===, #and, #description_of, #or, should_enumerate?, surface_descriptions_in, unreadable_io?, #values_match?

Constructor Details

#initialize(*expected) ⇒ StartOrEndWith

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of StartOrEndWith.



8
9
10
11
# 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

Instance Method Details

#descriptionString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


27
28
29
30
31
32
# 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_messageString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


15
16
17
18
19
20
21
22
23
# 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