@api private Provides the implementation for `respond_to`. Not intended to be instantiated directly.
@api public No-op. Intended to be used as syntactic sugar when using `with`.
@example
expect(obj).to respond_to(:message).with(3).arguments
# File lib/rspec/matchers/built_in/respond_to.rb, line 70 def argument self end
@api private @return [String]
# File lib/rspec/matchers/built_in/respond_to.rb, line 99 def description "respond to #{pp_names}#{with_arity}" end
@private
# File lib/rspec/matchers/built_in/respond_to.rb, line 81 def does_not_match?(actual) find_failing_method_names(actual, :select).empty? end
@api private @return [String]
# File lib/rspec/matchers/built_in/respond_to.rb, line 87 def failure_message "expected #{actual_formatted} to respond to #{@failing_method_names.map { |name| description_of(name) }.join(', ')}#{with_arity}" end
@api private @return [String]
# File lib/rspec/matchers/built_in/respond_to.rb, line 93 def failure_message_when_negated failure_message.sub(/to respond to/, 'not to respond to') end
@private
# File lib/rspec/matchers/built_in/respond_to.rb, line 76 def matches?(actual) find_failing_method_names(actual, :reject).empty? end
@api public Specifies the number of expected arguments.
@example
expect(obj).to respond_to(:message).with(3).arguments
# File lib/rspec/matchers/built_in/respond_to.rb, line 23 def with(n) @expected_arity = n self end
@api public Specifies that the method accepts any keyword, i.e. the method has
a splatted keyword parameter of the form **kw_args.
@example
expect(obj).to respond_to(:message).with_any_keywords
# File lib/rspec/matchers/built_in/respond_to.rb, line 47 def with_any_keywords @arbitrary_keywords = true self end
@api public Specifies keyword arguments, if any.
@example
expect(obj).to respond_to(:message).with_keywords(:color, :shape)
@example with an expected number of arguments
expect(obj).to respond_to(:message).with(3).arguments.and_keywords(:color, :shape)
# File lib/rspec/matchers/built_in/respond_to.rb, line 35 def with_keywords(*keywords) @expected_keywords = keywords self end
@api public Specifies that the number of arguments has no upper limit, i.e. the
method has a splatted parameter of the form *args.
@example
expect(obj).to respond_to(:message).with_unlimited_arguments
# File lib/rspec/matchers/built_in/respond_to.rb, line 59 def with_unlimited_arguments @unlimited_arguments = true self end
# File lib/rspec/matchers/built_in/respond_to.rb, line 10 def initialize(*names) @names = names @expected_arity = nil @expected_keywords = [] @unlimited_arguments = nil @arbitrary_keywords = nil end