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

Inherits:
Object
  • Object
show all
Includes:
Composable
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.

Instance Method Summary (collapse)

Methods included from Composable

#===, #and, #description_of, enumerable?, #or, 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

12
13
14
15
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 12
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
32
33
34
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 32
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)
61
62
63
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 61
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)
49
50
51
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 49
def failure_message
  "expected #{@actual.inspect} to respond to #{@failing_method_names.map { |name| name.inspect }.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)
55
56
57
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 55
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
22
23
24
25
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 22
def with(n)
  @expected_arity = n
  self
end