module RSpecProxies::Proxies

Public Instance Methods

and_after_calling_original() { |result| ... } click to toggle source

Will call the given block with it's result every time the method returns

# File lib/rspecproxies/proxies.rb, line 16
def and_after_calling_original
  self.and_wrap_original do |m, *args, &block|
    result = m.call(*args, &block)
    yield result
    result
  end
end
and_before_calling_original() { |*args| ... } click to toggle source

Will call the given block with all the actual arguments every time the method is called

# File lib/rspecproxies/proxies.rb, line 7
def and_before_calling_original
  self.and_wrap_original do |m, *args, &block|
    yield *args
    m.call(*args, &block)
  end
end
and_capture_result_into(target, instance_variable_name) click to toggle source

Will capture (or override) result from the target's method in the specified instance variable of target

# File lib/rspecproxies/proxies.rb, line 32
def and_capture_result_into(target, instance_variable_name)
  self.and_after_calling_original do |result|
    target.instance_variable_set("@#{instance_variable_name}", result)
  end
end
and_collect_results_into(collector) click to toggle source

Will capture all the results of the method into the given array

# File lib/rspecproxies/proxies.rb, line 26
def and_collect_results_into(collector)
  self.and_after_calling_original { |result| collector << result }
end