Class: RSpec::Matchers::BuiltIn::RespondTo Private

Inherits:
BaseMatcher
  • Object
show all
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

Constant Summary

Constants inherited from BaseMatcher

BaseMatcher::UNDEFINED

Instance Method Summary (collapse)

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, #values_match?

Constructor Details

- (RespondTo) initialize(*names)

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

10
11
12
13
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 10
def initialize(*names)
  @names = names
  @expected_arity = nil
end

Instance Method Details

- (Object) argument Also known as: arguments

No-op. Intended to be used as syntactic sugar when using with.

Examples:

expect(obj).to respond_to(:message).with(3).arguments
30
31
32
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 30
def argument
  self
end

- (String) description

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:

  • (String)
59
60
61
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 59
def description
  "respond to #{pp_names}#{with_arity}"
end

- (String) failure_message

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:

  • (String)
47
48
49
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 47
def failure_message
  "expected #{actual_formatted} to respond to #{@failing_method_names.map { |name| description_of(name) }.join(', ')}#{with_arity}"
end

- (String) failure_message_when_negated

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:

  • (String)
53
54
55
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 53
def failure_message_when_negated
  failure_message.sub(/to respond to/, 'not to respond to')
end

- (Object) with(n)

Specifies the number of expected arguments.

Examples:

expect(obj).to respond_to(:message).with(3).arguments
20
21
22
23
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 20
def with(n)
  @expected_arity = n
  self
end