class Shoegaze::Proxy::Template
Provides the basic 'template' for our anonymous proxy classes whose *only purpose* is to delegate implementation method calls to the class and instance doubles.
Attributes
class_double[RW]
instance_double[RW]
Public Class Methods
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/shoegaze/proxy/template.rb, line 10 def method_missing(method, *args, &block) # yeah, we are abusing re-use of rspec doubles class_double.instance_variable_set(:@__expired, false) default_scenario = class_double.default_scenario(method) if class_double.respond_to?(method) return class_double.send(method, *args, &block) end return default_scenario.call(*args, &block) if default_scenario begin super rescue NoMethodError raise_no_implementation_error(method, class_double) end end
new(*args)
click to toggle source
# File lib/shoegaze/proxy/template.rb, line 36 def initialize(*args) # no-op to allow newifying instances # NOTE: due to complexity, mocking of :initialize is not actually supported. drive # your behaviors via other methods end
Private Class Methods
raise_no_implementation_error(method, double)
click to toggle source
# File lib/shoegaze/proxy/template.rb, line 31 def raise_no_implementation_error(method, double) raise Shoegaze::Scenario::Orchestrator::NoImplementationError.new("#{self.name} either has no Shoegaze mock implementation or no scenario has been orchestrated for method :#{method}") end
Public Instance Methods
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/shoegaze/proxy/template.rb, line 42 def method_missing(method, *args, &block) double = self.class.instance_double # yeah, we are abusing re-use of rspec doubles double.instance_variable_set(:@__expired, false) default_scenario = double.default_scenario(method) return double.send(method, *args, &block) if double.respond_to?(method) return default_scenario.call(*args, &block) if default_scenario begin super rescue NoMethodError self.class.raise_no_implementation_error(method, double) end end