Class: Spec::Distributed::Recorder
- Inherits:
-
Object
- Object
- Spec::Distributed::Recorder
- Defined in:
- lib/spec/distributed/slave_runner.rb
Overview
This is used as a reporter and just records method invocations. It is then sent back to the master and all the invocations are replayed there on the master’s real reporter. Nifty, eh?
Instance Method Summary collapse
-
#initialize(watermark) ⇒ Recorder
constructor
A new instance of Recorder.
- #marshallable_dup(o) ⇒ Object
- #method_missing(method, *args) ⇒ Object
- #replay(target) ⇒ Object
Constructor Details
#initialize(watermark) ⇒ Recorder
Returns a new instance of Recorder.
100 101 102 103 |
# File 'lib/spec/distributed/slave_runner.rb', line 100 def initialize(watermark) @watermark = watermark @invocations = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/spec/distributed/slave_runner.rb', line 105 def method_missing(method, *args) marshallable_args = args.map {|arg| marshallable_dup(arg)} if method.to_s == 'add_behaviour' # Watermark each behaviour description so the final report says where it ran marshallable_args[0].description << " (#{@watermark})" end @invocations << [method, *marshallable_args] end |
Instance Method Details
#marshallable_dup(o) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/spec/distributed/slave_runner.rb', line 115 def marshallable_dup(o) begin dupe = o.dup dupe.instance_variables.each do |ivar| if Proc === dupe.instance_variable_get(ivar) dupe.__send__(:remove_instance_variable, ivar) end end dupe rescue TypeError # Some objects like nil and false cannot be duped, and there is no easy way to check for all cases o end end |
#replay(target) ⇒ Object
129 130 131 132 133 |
# File 'lib/spec/distributed/slave_runner.rb', line 129 def replay(target) @invocations.each do |method, *args| target.__send__(method, *args) end end |