Class: RSpec::Mocks::Proxy
Class Method Summary collapse
- .allow_message_expectations_on_nil ⇒ Object
 - .allow_message_expectations_on_nil? ⇒ Boolean
 - .warn_about_expectations_on_nil ⇒ Object
 - .warn_about_expectations_on_nil=(new_value) ⇒ Object
 
Instance Method Summary collapse
- #add_message_expectation(location, method_name, opts = {}, &block) ⇒ Object
 - #add_negative_message_expectation(location, method_name, &implementation) ⇒ Object
 - #add_stub(location, method_name, opts = {}, &implementation) ⇒ Object
 - 
  
    
      #already_proxied_respond_to  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
:nodoc:.
 - 
  
    
      #already_proxied_respond_to?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
:nodoc:.
 - 
  
    
      #as_null_object  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Tells the object to ignore any messages that aren’t explicitly set as stubs or message expectations.
 - #has_negative_expectation?(method_name) ⇒ Boolean
 - 
  
    
      #initialize(object, name = nil, options = {})  ⇒ Proxy 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Proxy.
 - #message_received(method_name, *args, &block) ⇒ Object
 - #null_object? ⇒ Boolean
 - #raise_unexpected_message_args_error(expectation, *args) ⇒ Object
 - #raise_unexpected_message_error(method_name, *args) ⇒ Object
 - #received_message?(method_name, *args, &block) ⇒ Boolean
 - #record_message_received(method_name, *args, &block) ⇒ Object
 - #remove_stub(method_name) ⇒ Object
 - #reset ⇒ Object
 - 
  
    
      #verify  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
:nodoc:.
 
Constructor Details
#initialize(object, name = nil, options = {}) ⇒ Proxy
Returns a new instance of Proxy.
      26 27 28 29 30 31 32 33 34 35  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 26 def initialize(object, name=nil, ={}) @object = object @name = name @error_generator = ErrorGenerator.new object, name, @expectation_ordering = OrderGroup.new @error_generator @messages_received = [] @options = @already_proxied_respond_to = false @null_object = false end  | 
  
Class Method Details
.allow_message_expectations_on_nil ⇒ Object
      13 14 15 16 17 18 19  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 13 def @warn_about_expectations_on_nil = false # ensure nil.rspec_verify is called even if an expectation is not set in the example # otherwise the allowance would effect subsequent examples RSpec::Mocks::space.add(nil) unless RSpec::Mocks::space.nil? end  | 
  
.allow_message_expectations_on_nil? ⇒ Boolean
      21 22 23  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 21 def !warn_about_expectations_on_nil end  | 
  
.warn_about_expectations_on_nil ⇒ Object
      5 6 7  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 5 def warn_about_expectations_on_nil defined?(@warn_about_expectations_on_nil) ? @warn_about_expectations_on_nil : true end  | 
  
.warn_about_expectations_on_nil=(new_value) ⇒ Object
      9 10 11  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 9 def warn_about_expectations_on_nil=(new_value) @warn_about_expectations_on_nil = new_value end  | 
  
Instance Method Details
#add_message_expectation(location, method_name, opts = {}, &block) ⇒ Object
      56 57 58  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 56 def (location, method_name, opts={}, &block) method_double[method_name].add_expectation @error_generator, @expectation_ordering, location, opts, &block end  | 
  
#add_negative_message_expectation(location, method_name, &implementation) ⇒ Object
      60 61 62  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 60 def (location, method_name, &implementation) method_double[method_name].add_negative_expectation @error_generator, @expectation_ordering, location, &implementation end  | 
  
#add_stub(location, method_name, opts = {}, &implementation) ⇒ Object
      64 65 66  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 64 def add_stub(location, method_name, opts={}, &implementation) method_double[method_name].add_stub @error_generator, @expectation_ordering, location, opts, &implementation end  | 
  
#already_proxied_respond_to ⇒ Object
:nodoc:
      48 49 50  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 48 def already_proxied_respond_to # :nodoc: @already_proxied_respond_to = true end  | 
  
#already_proxied_respond_to? ⇒ Boolean
:nodoc:
      52 53 54  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 52 def already_proxied_respond_to? # :nodoc: @already_proxied_respond_to end  | 
  
#as_null_object ⇒ Object
Tells the object to ignore any messages that aren’t explicitly set as stubs or message expectations.
      43 44 45 46  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 43 def as_null_object @null_object = true @object end  | 
  
#has_negative_expectation?(method_name) ⇒ Boolean
      86 87 88  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 86 def has_negative_expectation?(method_name) method_double[method_name].expectations.detect {|expectation| expectation.negative_expectation_for?(method_name)} end  | 
  
#message_received(method_name, *args, &block) ⇒ Object
      94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 94 def (method_name, *args, &block) expectation = find_matching_expectation(method_name, *args) stub = find_matching_method_stub(method_name, *args) if (stub && expectation && expectation.called_max_times?) || (stub && !expectation) if expectation = find_almost_matching_expectation(method_name, *args) expectation.advise(*args) unless expectation. end stub.invoke(*args, &block) elsif expectation expectation.invoke(*args, &block) elsif expectation = find_almost_matching_expectation(method_name, *args) expectation.advise(*args) if null_object? unless expectation. (expectation, *args) unless (has_negative_expectation?(method_name) or null_object?) elsif stub = find_almost_matching_stub(method_name, *args) stub.advise(*args) (stub, *args) elsif @object.is_a?(Class) @object.superclass.send(method_name, *args, &block) else @object.__send__(:method_missing, method_name, *args, &block) end end  | 
  
#null_object? ⇒ Boolean
      37 38 39  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 37 def null_object? @null_object end  | 
  
#raise_unexpected_message_args_error(expectation, *args) ⇒ Object
      118 119 120  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 118 def (expectation, *args) @error_generator.(expectation, *args) end  | 
  
#raise_unexpected_message_error(method_name, *args) ⇒ Object
      122 123 124  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 122 def (method_name, *args) @error_generator. method_name, *args end  | 
  
#received_message?(method_name, *args, &block) ⇒ Boolean
      82 83 84  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 82 def (method_name, *args, &block) @messages_received.any? {|array| array == [method_name, args, block]} end  | 
  
#record_message_received(method_name, *args, &block) ⇒ Object
      90 91 92  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 90 def (method_name, *args, &block) @messages_received << [method_name, args, block] end  | 
  
#remove_stub(method_name) ⇒ Object
      68 69 70  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 68 def remove_stub(method_name) method_double[method_name].remove_stub end  | 
  
#reset ⇒ Object
      78 79 80  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 78 def reset method_doubles.each {|d| d.reset} end  | 
  
#verify ⇒ Object
:nodoc:
      72 73 74 75 76  | 
    
      # File 'lib/rspec/mocks/proxy.rb', line 72 def verify #:nodoc: method_doubles.each {|d| d.verify} ensure reset end  |