Parent

Class Index [+]

Quicksearch

RSpec::Matchers::BuiltIn::RespondTo

Public Class Methods

new(*names) click to toggle source
   # File lib/rspec/matchers/built_in/respond_to.rb, line 5
5:         def initialize(*names)
6:           @names = names
7:           @expected_arity = nil
8:         end

Public Instance Methods

argument() click to toggle source
    # File lib/rspec/matchers/built_in/respond_to.rb, line 35
35:         def argument
36:           self
37:         end
Also aliased as: arguments
arguments() click to toggle source
Alias for: argument
description() click to toggle source
    # File lib/rspec/matchers/built_in/respond_to.rb, line 26
26:         def description
27:           "respond to #{pp_names}#{with_arity}"
28:         end
does_not_match?(actual) click to toggle source
    # File lib/rspec/matchers/built_in/respond_to.rb, line 14
14:         def does_not_match?(actual)
15:           find_failing_method_names(actual, :select).empty?
16:         end
failure_message_for_should() click to toggle source
    # File lib/rspec/matchers/built_in/respond_to.rb, line 18
18:         def failure_message_for_should
19:           "expected #{@actual.inspect} to respond to #{@failing_method_names.collect {|name| name.inspect }.join(', ')}#{with_arity}"
20:         end
failure_message_for_should_not() click to toggle source
    # File lib/rspec/matchers/built_in/respond_to.rb, line 22
22:         def failure_message_for_should_not
23:           failure_message_for_should.sub(/to respond to/, 'not to respond to')
24:         end
matches?(actual) click to toggle source
    # File lib/rspec/matchers/built_in/respond_to.rb, line 10
10:         def matches?(actual)
11:           find_failing_method_names(actual, :reject).empty?
12:         end
with(n) click to toggle source
    # File lib/rspec/matchers/built_in/respond_to.rb, line 30
30:         def with(n)
31:           @expected_arity = n
32:           self
33:         end

Private Instance Methods

find_failing_method_names(actual, filter_method) click to toggle source
    # File lib/rspec/matchers/built_in/respond_to.rb, line 42
42:         def find_failing_method_names(actual, filter_method)
43:           @actual = actual
44:           @failing_method_names = @names.send(filter_method) do |name|
45:             @actual.respond_to?(name) && matches_arity?(actual, name)
46:           end
47:         end
matches_arity?(actual, name) click to toggle source
    # File lib/rspec/matchers/built_in/respond_to.rb, line 49
49:         def matches_arity?(actual, name)
50:           return true unless @expected_arity
51: 
52:           actual_arity = actual.method(name).arity
53:           if actual_arity < 0
54:             # ~ inverts the one's complement and gives us the number of required args
55:             ~actual_arity <= @expected_arity
56:           else
57:             actual_arity == @expected_arity
58:           end
59:         end
pp_names() click to toggle source
    # File lib/rspec/matchers/built_in/respond_to.rb, line 66
66:         def pp_names
67:           # Ruby 1.9 returns the same thing for array.to_s as array.inspect, so just use array.inspect here
68:           @names.length == 1 ? "##{@names.first}" : @names.inspect
69:         end
with_arity() click to toggle source
    # File lib/rspec/matchers/built_in/respond_to.rb, line 61
61:         def with_arity
62:           @expected_arity.nil?? "" :
63:             " with #{@expected_arity} argument#{@expected_arity == 1 ? '' : 's'}"
64:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.