Class: RSpec::Mocks::VerifyingProxy

Inherits:
TestDoubleProxy show all
Includes:
VerifyingProxyMethods
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/verifying_proxy.rb

Overview

A verifying proxy mostly acts like a normal proxy, except that it contains extra logic to try and determine the validity of any expectation set on it. This includes whether or not methods have been defined and the validity of arguments on method calls.

In all other ways this behaves like a normal proxy. It only adds the verification behaviour to specific methods then delegates to the parent implementation.

These checks are only activated if the doubled class has already been loaded, otherwise they are disabled. This allows for testing in isolation.

Constant Summary

Constants inherited from Proxy

Proxy::DEFAULT_MESSAGE_EXPECTATION_OPTS

Instance Attribute Summary

Attributes inherited from Proxy

#object

Instance Method Summary collapse

Methods included from VerifyingProxyMethods

#add_message_expectation, #add_simple_stub, #add_stub, #ensure_implemented, #ensure_publicly_implemented

Methods inherited from TestDoubleProxy

#reset

Methods inherited from Proxy

#add_message_expectation, #add_simple_expectation, #add_simple_stub, #add_stub, #as_null_object, #build_expectation, #check_for_unexpected_arguments, #ensure_can_be_proxied!, #ensure_implemented, #has_negative_expectation?, #message_received, #messages_arg_list, #method_double_if_exists_for_message, #null_object?, #original_method_handle_for, prepended_modules_of, #prepended_modules_of_singleton_class, #raise_missing_default_stub_error, #raise_unexpected_message_error, #received_message?, #record_message_received, #remove_stub, #remove_stub_if_present, #replay_received_message_on, #reset, #verify

Constructor Details

#initialize(object, order_group, doubled_module, method_reference_class) ⇒ VerifyingProxy

Returns a new instance of VerifyingProxy.



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/verifying_proxy.rb', line 74

def initialize(object, order_group, doubled_module, method_reference_class)
  super(object, order_group)
  @object                 = object
  @doubled_module         = doubled_module
  @method_reference_class = method_reference_class

  # A custom method double is required to pass through a way to lookup
  # methods to determine their parameters. This is only relevant if the doubled
  # class is loaded.
  @method_doubles = Hash.new do |h, k|
    h[k] = VerifyingMethodDouble.new(@object, k, self, method_reference[k])
  end
end

Instance Method Details

#method_referenceObject



88
89
90
91
92
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/verifying_proxy.rb', line 88

def method_reference
  @method_reference ||= Hash.new do |h, k|
    h[k] = @method_reference_class.for(@doubled_module, k)
  end
end

#validate_arguments!(method_name, args) ⇒ Object



98
99
100
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/verifying_proxy.rb', line 98

def validate_arguments!(method_name, args)
  @method_doubles[method_name].validate_arguments!(args)
end

#visibility_for(method_name) ⇒ Object



94
95
96
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/verifying_proxy.rb', line 94

def visibility_for(method_name)
  method_reference[method_name].visibility
end