Class: RR::ProbeCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/rr/probe_creator.rb

Overview

RR::ProbeCreator uses RR::ProbeCreator#method_missing to create a Scenario that acts like a probe.

The following example probes method_name with arg1 and arg2 returning return_value.

probe(subject).method_name(arg1, arg2) { return_value }

The ProbeCreator also supports a block sytnax.

probe(subject) do |m|
  m.method_name(arg1, arg2) { return_value }
end

Instance Method Summary collapse

Constructor Details

#initialize(space, subject) {|_self| ... } ⇒ ProbeCreator

Returns a new instance of ProbeCreator.

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
# File 'lib/rr/probe_creator.rb', line 18

def initialize(space, subject)
  @space = space
  @subject = subject
  yield(self) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &returns) ⇒ Object (protected)



25
26
27
28
29
# File 'lib/rr/probe_creator.rb', line 25

def method_missing(method_name, *args, &returns)
  double = @space.create_double(@subject, method_name)
  scenario = @space.create_scenario(double)
  scenario.with(*args).once.implemented_by(double.original_method)
end