类: RSpec::Matchers::BuiltIn::RaiseError 私有
- 继承
-
Object
- Object
- RSpec::Matchers::BuiltIn::RaiseError
- 包含
- 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
实例方法摘要 折叠
- #description ⇒ String 私有
- #failure_message ⇒ String 私有
- #failure_message_when_negated ⇒ String 私有
-
#initialize(expected_error_or_message, expected_message, &block) ⇒ RaiseError 构造函数 私有
新的 RaiseError 实例。
-
#with_message(expected_message) ⇒ Object
指定预期错误消息。
从 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(, , &block) @block = block @actual_error = nil @warn_about_bare_error = UndefinedValue === @warn_about_nil_error = .nil? case when nil, UndefinedValue @expected_error = Exception @expected_message = when String @expected_error = Exception @expected_message = else @expected_error = @expected_message = end end |
实例方法详情
#description ⇒String
此方法属于私有 API 的一部分。 尽可能避免使用此方法,因为它可能在将来被删除或更改。
113 114 115 |
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 113 def description "raise #{expected_error}" end |
#failure_message ⇒String
此方法属于私有 API 的一部分。 尽可能避免使用此方法,因为它可能在将来被删除或更改。
101 102 103 |
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 101 def @eval_block ? : "expected #{expected_error}#{given_error}" end |
#failure_message_when_negated ⇒String
此方法属于私有 API 的一部分。 尽可能避免使用此方法,因为它可能在将来被删除或更改。
107 108 109 |
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 107 def "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 () if @expected_message @warn_about_bare_error = false @expected_message = self end |