类: RSpec::Matchers::BuiltIn::BaseMatcher 私有

继承
Object
  • Object
显示全部
包含
DefaultFailureMessages, Composable
定义于
lib/rspec/matchers/built_in/base_matcher.rb

概述

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

内部 用作 rspec-expectations 和 rspec-rails 附带的匹配器的基类。

警告

此类用于内部使用,可能会在未经通知的情况下更改。我们强烈建议您不要将自定义匹配器基于此类。如果/当此类发生更改时,我们将宣布此更改并删除此警告。

定义于命名空间下

模块: DefaultFailureMessages

常量摘要 收起

UNDEFINED =

此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它可能在将来被移除或更改。

用于检测何时没有将参数传递给 initializenil 不能使用,因为它是一个有效的传递值。

Object.new.freeze

实例方法摘要 收起

包含自 DefaultFailureMessages 的方法

#failure_message, #failure_message_when_negated

包含自 Composable 的方法

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

构造函数详细信息

#initialize(expected = UNDEFINED) ⇒BaseMatcher

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

返回 BaseMatcher 的一个新实例。

28
29
30
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 28
def initialize(expected=UNDEFINED)
  @expected = expected unless UNDEFINED.equal?(expected)
end

实例方法详细信息

#descriptionString

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

使用 EnglishPhrasing 生成描述。

返回

  • (String)
60
61
62
63
64
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 60
def description
  desc = EnglishPhrasing.split_words(self.class.matcher_name)
  desc << EnglishPhrasing.list(@expected) if defined?(@expected)
  desc
end

#diffable?Boolean

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

默认情况下,匹配器不可比较。覆盖此方法以使子类可比较。

返回

  • (Boolean)
69
70
71
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 69
def diffable?
  false
end

#expects_call_stack_jump?Boolean

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

返回

  • (Boolean)
87
88
89
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 87
def expects_call_stack_jump?
  false
end

#match_unless_raises(*exceptions) ⇒Object

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

用于包装一段代码,该代码将通过引发其中一个命名异常来指示失败。

这由 rspec-rails 用于其包装 rails 声明的一些匹配器。

47
48
49
50
51
52
53
54
55
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 47
def match_unless_raises(*exceptions)
  exceptions.unshift Exception if exceptions.empty?
  begin
    yield
    true
  rescue *exceptions => @rescued_exception
    false
  end
end

#matches?(actual) ⇒Boolean

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

指示匹配是否成功。委托给 match,它应在子类上定义。负责一致地初始化 actual 属性。

返回

  • (Boolean)
36
37
38
39
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 36
def matches?(actual)
  @actual = actual
  match(expected, actual)
end

#supports_block_expectations?Boolean

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

大多数匹配器是值匹配器(即用于与 expect(value) 一起使用),而不是块匹配器(即用于与 expect { } 一起使用),因此默认值为 false。块匹配器必须覆盖此方法以返回 true。

返回

  • (Boolean)
77
78
79
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 77
def supports_block_expectations?
  false
end