类: RSpec::Matchers::BuiltIn::RespondTo 私有
- 继承
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::Matchers::BuiltIn::RespondTo
- 定义在
- lib/rspec/matchers/built_in/respond_to.rb
概述
此类属于私有 API 的一部分。 尽可能避免使用此类,因为它可能会在将来被移除或修改。
提供 respond_to
的实现。 不打算直接实例化。
常量摘要
从 BaseMatcher 继承的常量
实例方法摘要 折叠
-
#argument ⇒ Object (另称: #arguments)
无操作。
- #description ⇒ String 私有
- #failure_message ⇒ String 私有
- #failure_message_when_negated ⇒ String 私有
-
#ignoring_method_signature_failure! ⇒ Object 私有
由其他匹配器用来抑制检查。
-
#initialize(*names) ⇒ RespondTo 构造函数 私有
RespondTo 的一个新实例。
-
#with(n) ⇒ Object
指定预期参数的数量。
-
#with_any_keywords ⇒ Object (另称: #and_any_keywords)
指定方法接受任何关键字,即
-
#with_keywords(*keywords) ⇒ Object (另称: #and_keywords)
指定关键字参数(如果有)。
-
#with_unlimited_arguments ⇒ Object (另称: #and_unlimited_arguments)
指定参数数量没有上限,即
从 BaseMatcher 继承的方法
#diffable?, #expects_call_stack_jump?, #match_unless_raises, #supports_block_expectations?
从 Composable 包含的方法
#===, #and, #description_of, #or, should_enumerate?, surface_descriptions_in, unreadable_io?, #values_match?
构造函数详细信息
#initialize(*names) ⇒RespondTo
此方法属于私有 API 的一部分。 尽可能避免使用此方法,因为它可能会在将来被移除或修改。
返回 RespondTo 的一个新实例。
10 11 12 13 14 15 16 17 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 10 def initialize(*names) @names = names @expected_arity = nil @expected_keywords = [] @ignoring_method_signature_failure = false @unlimited_arguments = nil @arbitrary_keywords = nil end |
实例方法详细信息
#argument ⇒Object 另称: arguments
无操作。 旨在用作使用 with
时的语法糖。
71 72 73 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 71 def argument self end |
#description ⇒String
此方法属于私有 API 的一部分。 尽可能避免使用此方法,因为它可能会在将来被移除或修改。
100 101 102 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 100 def description "respond to #{pp_names}#{with_arity}" end |
#failure_message ⇒String
此方法属于私有 API 的一部分。 尽可能避免使用此方法,因为它可能会在将来被移除或修改。
88 89 90 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 88 def "expected #{actual_formatted} to respond to #{@failing_method_names.map { |name| description_of(name) }.join(', ')}#{with_arity}" end |
#failure_message_when_negated ⇒String
此方法属于私有 API 的一部分。 尽可能避免使用此方法,因为它可能会在将来被移除或修改。
94 95 96 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 94 def .sub(/to respond to/, 'not to respond to') end |
#ignoring_method_signature_failure! ⇒Object
此方法属于私有 API 的一部分。 尽可能避免使用此方法,因为它可能会在将来被移除或修改。
由其他匹配器用来抑制检查
106 107 108 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 106 def ignoring_method_signature_failure! @ignoring_method_signature_failure = true end |
#with(n) ⇒Object
指定预期参数的数量。
24 25 26 27 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 24 def with(n) @expected_arity = n self end |
#with_any_keywords ⇒Object 另称: and_any_keywords
指定方法接受任何关键字,即方法具有形如 **kw_args 的星号关键字参数。
48 49 50 51 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 48 def with_any_keywords @arbitrary_keywords = true self end |
#with_keywords(*keywords) ⇒Object 另称: and_keywords
指定关键字参数(如果有)。
36 37 38 39 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 36 def with_keywords(*keywords) @expected_keywords = keywords self end |
#with_unlimited_arguments ⇒Object 另称: and_unlimited_arguments
指定参数数量没有上限,即方法具有形如 *args 的星号参数。
60 61 62 63 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 60 def with_unlimited_arguments @unlimited_arguments = true self end |