Class: RSpec::Matchers::BuiltIn::RespondTo Private
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
BaseMatcher
|
|
Instance Chain:
|
|
Inherits: |
RSpec::Matchers::BuiltIn::BaseMatcher
|
Defined in: | rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb |
Overview
Provides the implementation for RSpec::Matchers#respond_to. Not intended to be instantiated directly.
Constant Summary
BaseMatcher
- Inherited
Class Method Summary
- .new(*names) ⇒ RespondTo constructor Internal use only
BaseMatcher
- Inherited
.matcher_name, .new, | |
.underscore | Borrowed from ActiveSupport. |
Instance Attribute Summary
BaseMatcher
- Inherited
#actual, | |
#diffable? |
|
#expected, #expects_call_stack_jump?, #matcher_name, #matcher_name=, #rescued_exception, | |
#supports_block_expectations? | Most matchers are value matchers (i.e. meant to work with ‘expect(value)`) rather than block matchers (i.e. meant to work with `expect { }`), so this defaults to false. |
#supports_value_expectations? |
BaseMatcher::StringEncodingFormatting
- Included
#string_encoding_differs? | :nocov: |
Instance Method Summary
-
#and_any_keywords
Alias for #with_any_keywords.
-
#and_keywords(*keywords)
Alias for #with_keywords.
-
#and_unlimited_arguments
Alias for #with_unlimited_arguments.
-
#argument
(also: #arguments)
No-op.
-
#arguments
Alias for #argument.
- #description ⇒ String Internal use only
- #does_not_match?(actual) ⇒ Boolean Internal use only
- #failure_message ⇒ String Internal use only
- #failure_message_when_negated ⇒ String Internal use only
-
#ignoring_method_signature_failure!
Internal use only
Used by other matchers to suppress a check.
- #matches?(actual) ⇒ Boolean Internal use only
-
#with(n)
Specifies the number of expected arguments.
-
#with_any_keywords
(also: #and_any_keywords)
Specifies that the method accepts any keyword, i.e. the method has.
-
#with_keywords(*keywords)
(also: #and_keywords)
Specifies keyword arguments, if any.
-
#with_unlimited_arguments
(also: #and_unlimited_arguments)
Specifies that the number of arguments has no upper limit, i.e. the.
- #find_failing_method_names(actual, filter_method) private Internal use only
- #matches_arity?(actual, name) ⇒ Boolean private Internal use only
- #pp_names private Internal use only
- #with_arity private Internal use only
- #with_arity_string private Internal use only
- #with_keywords_string private Internal use only
BaseMatcher
- Inherited
#actual_formatted, | |
#description | Generates a description using |
#expected_formatted, | |
#match_unless_raises | Used to wrap a block of code that will indicate failure by raising one of the named exceptions. |
#matches? | Indicates if the match is successful. |
BaseMatcher::DefaultFailureMessages
- Included
#failure_message | Provides a good generic failure message. |
#failure_message_when_negated | Provides a good generic negative failure message. |
BaseMatcher::StringEncodingFormatting
- Included
#format_encoding | Formats a String’s encoding as a human readable string :nocov: |
BaseMatcher::HashFormatting
- Included
#improve_hash_formatting | ‘{ |
::RSpec::Matchers::Composable
- Included
#& | Alias for Composable#and. |
#=== | Delegates to #matches?. |
#and | Creates a compound |
#description_of | Returns the description of the given object in a way that is aware of composed matchers. |
#or | Creates a compound |
#values_match? | This provides a generic way to fuzzy-match an expected value against an actual value. |
#| | Alias for Composable#or. |
#should_enumerate? | We should enumerate arrays as long as they are not recursive. |
#surface_descriptions_in | Transforms the given data structure (typically a hash or array) into a new data structure that, when |
#unreadable_io?, | |
#with_matchers_cloned | Historically, a single matcher instance was only checked against a single value. |
Instance Method Details
#and_any_keywords
Alias for #with_any_keywords.
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 52
alias :and_any_keywords :with_any_keywords
#and_keywords(*keywords)
Alias for #with_keywords.
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 40
alias :and_keywords :with_keywords
#and_unlimited_arguments
Alias for #with_unlimited_arguments.
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 64
alias :and_unlimited_arguments :with_unlimited_arguments
#argument Also known as: #arguments
No-op. Intended to be used as syntactic sugar when using #with.
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 71
def argument self end
#arguments
Alias for #argument.
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 74
alias :arguments :argument
#description ⇒ String
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 100
def description "respond to #{pp_names}#{with_arity}" end
#does_not_match?(actual) ⇒ Boolean
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 82
def does_not_match?(actual) find_failing_method_names(actual, :select).empty? end
#failure_message ⇒ String
# File 'rspec-expectations/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
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 94
def .sub(/to respond to/, 'not to respond to') end
#find_failing_method_names(actual, filter_method) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 112
def find_failing_method_names(actual, filter_method) @actual = actual @failing_method_names = @names.__send__(filter_method) do |name| @actual.respond_to?(name) && matches_arity?(actual, name) end end
#ignoring_method_signature_failure!
Used by other matchers to suppress a check
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 106
def ignoring_method_signature_failure! @ignoring_method_signature_failure = true end
#matches?(actual) ⇒ Boolean
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 77
def matches?(actual) find_failing_method_names(actual, :reject).empty? end
#matches_arity?(actual, name) ⇒ Boolean
(private)
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 119
def matches_arity?(actual, name) ArityCheck.new(@expected_arity, @expected_keywords, @arbitrary_keywords, @unlimited_arguments).matches?(actual, name) rescue NameError return true if @ignoring_method_signature_failure raise ArgumentError, "The #{matcher_name} matcher requires that " \ "the actual object define the method(s) in " \ "order to check arity, but the method " \ "`#{name}` is not defined. Remove the arity " \ "check or define the method to continue." end
#pp_names (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 156
def pp_names @names.length == 1 ? "##{@names.first}" : description_of(@names) end
#with(n)
Specifies the number of expected arguments.
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 24
def with(n) @expected_arity = n self end
#with_any_keywords 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.
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 48
def with_any_keywords @arbitrary_keywords = true self end
#with_arity (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 130
def with_arity str = ''.dup str << " with #{with_arity_string}" if @expected_arity str << " #{str.length == 0 ? 'with' : 'and'} #{with_keywords_string}" if @expected_keywords && @expected_keywords.count > 0 str << " #{str.length == 0 ? 'with' : 'and'} unlimited arguments" if @unlimited_arguments str << " #{str.length == 0 ? 'with' : 'and'} any keywords" if @arbitrary_keywords str end
#with_arity_string (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 139
def with_arity_string "#{@expected_arity} argument#{@expected_arity == 1 ? '' : 's'}" end
#with_keywords(*keywords) Also known as: #and_keywords
Specifies keyword arguments, if any.
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 36
def with_keywords(*keywords) @expected_keywords = keywords self end
#with_keywords_string (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 143
def with_keywords_string kw_str = case @expected_keywords.count when 1 @expected_keywords.first.inspect when 2 @expected_keywords.map(&:inspect).join(' and ') else "#{@expected_keywords[0...-1].map(&:inspect).join(', ')}, and #{@expected_keywords.last.inspect}" end "keyword#{@expected_keywords.count == 1 ? '' : 's'} #{kw_str}" end
#with_unlimited_arguments 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.
# File 'rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb', line 60
def with_unlimited_arguments @unlimited_arguments = true self end