类: RSpec::Matchers::BuiltIn::StartOrEndWith 私有

继承
BaseMatcher
  • Object
显示全部
定义在
lib/rspec/matchers/built_in/start_or_end_with.rb

概述

此类属于私有 API 部分。 应尽可能避免使用此类,因为它可能会在将来被移除或更改。

end_withstart_with 匹配器的基类。不建议直接实例化。

直接已知子类

EndWith, StartWith

常量摘要

BaseMatcher 继承的常量

BaseMatcher::UNDEFINED

实例方法摘要 折叠

BaseMatcher 继承的方法

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

BaseMatcher::DefaultFailureMessages 包含的方法

#failure_message_when_negated

Composable 包含的方法

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

构造函数详细信息

#initialize(*expected) ⇒StartOrEndWith

此方法属于私有 API 部分。 应尽可能避免使用此方法,因为它可能会在将来被移除或更改。

返回 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

实例方法详细信息

#descriptionString

此方法属于私有 API 部分。 应尽可能避免使用此方法,因为它可能会在将来被移除或更改。

返回

  • (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

此方法属于私有 API 部分。 应尽可能避免使用此方法,因为它可能会在将来被移除或更改。

返回

  • (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