Module: RSpecProxies::Proxies

Defined in:
lib/rspecproxies/proxies.rb

Instance Method Summary collapse

Instance Method Details

#and_after_calling_originalObject

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


17
18
19
20
21
22
23
# File 'lib/rspecproxies/proxies.rb', line 17

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_originalObject

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


8
9
10
11
12
13
# File 'lib/rspecproxies/proxies.rb', line 8

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) ⇒ Object

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


33
34
35
36
37
# File 'lib/rspecproxies/proxies.rb', line 33

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) ⇒ Object

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


27
28
29
# File 'lib/rspecproxies/proxies.rb', line 27

def and_collect_results_into(collector)
  self.and_after_calling_original { |result| collector << result }
end