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

Inherits:
Object
  • Object
show all
Includes:
MatchAliases
Defined in:
lib/rspec/matchers/built_in/respond_to.rb

Instance Method Summary (collapse)

Methods included from MatchAliases

#==, #===

Constructor Details

- (RespondTo) initialize(*names)

A new instance of RespondTo



7
8
9
10
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 7

def initialize(*names)
  @names = names
  @expected_arity = nil
end

Instance Method Details

- (Object) argument Also known as: arguments



37
38
39
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 37

def argument
  self
end

- (Object) description



28
29
30
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 28

def description
  "respond to #{pp_names}#{with_arity}"
end

- (Boolean) does_not_match?(actual)

Returns:

  • (Boolean)


16
17
18
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 16

def does_not_match?(actual)
  find_failing_method_names(actual, :select).empty?
end

- (Object) failure_message_for_should



20
21
22
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 20

def failure_message_for_should
  "expected #{@actual.inspect} to respond to #{@failing_method_names.collect {|name| name.inspect }.join(', ')}#{with_arity}"
end

- (Object) failure_message_for_should_not



24
25
26
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 24

def failure_message_for_should_not
  failure_message_for_should.sub(/to respond to/, 'not to respond to')
end

- (Boolean) matches?(actual)

Returns:

  • (Boolean)


12
13
14
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 12

def matches?(actual)
  find_failing_method_names(actual, :reject).empty?
end

- (Object) with(n)



32
33
34
35
# File 'lib/rspec/matchers/built_in/respond_to.rb', line 32

def with(n)
  @expected_arity = n
  self
end