类: RSpec::Matchers::BuiltIn::RaiseError 私有

继承
Object
  • Object
显示全部
包含
Composable
定义在
lib/rspec/matchers/built_in/raise_error.rb

概述

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

提供 raise_error 的实现。不建议直接实例化。rubocop:disable Metrics/ClassLength rubocop:disable Lint/RescueException

常量摘要 折叠

UndefinedValue =

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

用作哨兵值,以便能够分辨用户是否未传递参数。我们不能使用 nil,因为我们需要以不同的方式警告 nil 被传递。它是一个 Object,而不是一个 Module,因为 Module 的 === 在与自身比较时不会评估为 true。

Object.new.freeze

实例方法摘要 折叠

Composable 包含的方法

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

构造函数详情

#initialize(expected_error_or_message, expected_message, &block) ⇒RaiseError

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

返回新的 RaiseError 实例。

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 18
def initialize(expected_error_or_message, expected_message, &block)
  @block = block
  @actual_error = nil
  @warn_about_bare_error = UndefinedValue === expected_error_or_message
  @warn_about_nil_error = expected_error_or_message.nil?
  case expected_error_or_message
  when nil, UndefinedValue
    @expected_error = Exception
    @expected_message = expected_message
  when String
    @expected_error = Exception
    @expected_message = expected_error_or_message
  else
    @expected_error = expected_error_or_message
    @expected_message = expected_message
  end
end

实例方法详情

#descriptionString

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

返回

  • (String)
113
114
115
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 113
def description
  "raise #{expected_error}"
end

#failure_messageString

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

返回

  • (String)
101
102
103
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 101
def failure_message
  @eval_block ? actual_error_message : "expected #{expected_error}#{given_error}"
end

#failure_message_when_negatedString

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

返回

  • (String)
107
108
109
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 107
def failure_message_when_negated
  "expected no #{expected_error}#{given_error}"
end

#with_message(expected_message) ⇒Object

指定预期错误消息。

39
40
41
42
43
44
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 39
def with_message(expected_message)
  raise_message_already_set if @expected_message
  @warn_about_bare_error = false
  @expected_message = expected_message
  self
end