Class: RSpec::Matchers::BuiltIn::RespondTo Private
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::Matchers::BuiltIn::RespondTo
- Defined in:
- lib/rspec/matchers/built_in/respond_to.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Provides the implementation for respond_to
.
Not intended to be instantiated directly.
Constant Summary
Constants inherited from BaseMatcher
Instance Method Summary collapse
-
#argument ⇒ Object
(also: #arguments)
No-op.
- #description ⇒ String private
- #failure_message ⇒ String private
- #failure_message_when_negated ⇒ String private
-
#ignoring_method_signature_failure! ⇒ Object
private
Used by other matchers to suppress a check.
-
#initialize(*names) ⇒ RespondTo
constructor
private
A new instance of RespondTo.
-
#with(n) ⇒ Object
Specifies the number of expected arguments.
-
#with_any_keywords ⇒ Object
(also: #and_any_keywords)
Specifies that the method accepts any keyword, i.e.
-
#with_keywords(*keywords) ⇒ Object
(also: #and_keywords)
Specifies keyword arguments, if any.
-
#with_unlimited_arguments ⇒ Object
(also: #and_unlimited_arguments)
Specifies that the number of arguments has no upper limit, i.e.
Methods inherited from BaseMatcher
#diffable?, #expects_call_stack_jump?, #match_unless_raises, #supports_block_expectations?
Methods included from Composable
#===, #and, #description_of, #or, should_enumerate?, surface_descriptions_in, unreadable_io?, #values_match?
Constructor Details
#initialize(*names) ⇒ RespondTo
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RespondTo.
12 13 14 15 16 17 18 19 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 12 def initialize(*names) @names = names @expected_arity = nil @expected_keywords = [] @ignoring_method_signature_failure = false @unlimited_arguments = nil @arbitrary_keywords = nil end |
Instance Method Details
#argument ⇒ Object Also known as: arguments
No-op. Intended to be used as syntactic sugar when using with
.
73 74 75 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 73 def argument self end |
#description ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
102 103 104 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 102 def description "respond to #{pp_names}#{with_arity}" end |
#failure_message ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
90 91 92 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 90 def "expected #{actual_formatted} to respond to #{@failing_method_names.map { |name| description_of(name) }.join(', ')}#{with_arity}" end |
#failure_message_when_negated ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
96 97 98 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 96 def .sub(/to respond to/, 'not to respond to') end |
#ignoring_method_signature_failure! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Used by other matchers to suppress a check
108 109 110 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 108 def ignoring_method_signature_failure! @ignoring_method_signature_failure = true end |
#with(n) ⇒ Object
Specifies the number of expected arguments.
26 27 28 29 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 26 def with(n) @expected_arity = n self end |
#with_any_keywords ⇒ Object Also known as: and_any_keywords
Specifies that the method accepts any keyword, i.e. the method has a splatted keyword parameter of the form **kw_args.
50 51 52 53 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 50 def with_any_keywords @arbitrary_keywords = true self end |
#with_keywords(*keywords) ⇒ Object Also known as: and_keywords
Specifies keyword arguments, if any.
38 39 40 41 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 38 def with_keywords(*keywords) @expected_keywords = keywords self end |
#with_unlimited_arguments ⇒ Object Also known as: and_unlimited_arguments
Specifies that the number of arguments has no upper limit, i.e. the method has a splatted parameter of the form *args.
62 63 64 65 |
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 62 def with_unlimited_arguments @unlimited_arguments = true self end |