Module: RSpec::Mocks::VerifyingDouble

Included in:
InstanceVerifyingDouble, ObjectVerifyingDoubleMethods
Defined in:
lib/rspec/mocks/verifying_double.rb

Instance Method Summary (collapse)

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(message, *args, &block)



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rspec/mocks/verifying_double.rb', line 22

def method_missing(message, *args, &block)
  # Null object conditional is an optimization. If not a null object,
  # validity of method expectations will have been checked at definition
  # time.
  if null_object?
    if @__sending_message == message
      __mock_proxy.ensure_implemented(message)
    else
      __mock_proxy.ensure_publicly_implemented(message, self)
    end
  end

  super
end

Instance Method Details

- (Object) __send__(name, *args, &block)



39
40
41
42
43
44
# File 'lib/rspec/mocks/verifying_double.rb', line 39

def __send__(name, *args, &block)
  @__sending_message = name
  super
ensure
  @__sending_message = nil
end

- (Object) initialize(*args)



51
52
53
54
# File 'lib/rspec/mocks/verifying_double.rb', line 51

def initialize(*args)
  super
  @__sending_message = nil
end

- (Boolean) respond_to?(message, include_private = false)

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rspec/mocks/verifying_double.rb', line 9

def respond_to?(message, include_private=false)
  return super unless null_object?

  method_ref = __mock_proxy.method_reference[message]

  return case method_ref.visibility
    when :public    then true
    when :private   then include_private
    when :protected then include_private || RUBY_VERSION.to_f < 2.0
    else !method_ref.unimplemented?
  end
end

- (Object) send(name, *args, &block)



47
48
49
# File 'lib/rspec/mocks/verifying_double.rb', line 47

def send(name, *args, &block)
  __send__(name, *args, &block)
end