@@ -84,6 +84,7 @@ def raise_on_mismatches?
8484 #
8585 # Returns the configured block.
8686 def before_run ( &block )
87+ marshalize ( block )
8788 @_scientist_before_run = block
8889 end
8990
@@ -99,6 +100,7 @@ def behaviors
99100 #
100101 # Returns the configured block.
101102 def clean ( &block )
103+ marshalize ( block )
102104 @_scientist_cleaner = block
103105 end
104106
@@ -131,6 +133,7 @@ def clean_value(value)
131133 #
132134 # Returns the block.
133135 def compare ( *args , &block )
136+ marshalize ( block )
134137 @_scientist_comparator = block
135138 end
136139
@@ -141,6 +144,7 @@ def compare(*args, &block)
141144 #
142145 # Returns the block.
143146 def compare_errors ( *args , &block )
147+ marshalize ( block )
144148 @_scientist_error_comparator = block
145149 end
146150
@@ -159,6 +163,7 @@ def context(context = nil)
159163 #
160164 # This can be called more than once with different blocks to use.
161165 def ignore ( &block )
166+ marshalize ( block )
162167 @_scientist_ignores ||= [ ]
163168 @_scientist_ignores << block
164169 end
@@ -251,6 +256,7 @@ def run(name = nil)
251256
252257 # Define a block that determines whether or not the experiment should run.
253258 def run_if ( &block )
259+ marshalize ( block )
254260 @_scientist_run_if_block = block
255261 end
256262
@@ -276,6 +282,7 @@ def should_experiment_run?
276282
277283 # Register a named behavior for this experiment, default "candidate".
278284 def try ( name = nil , &block )
285+ marshalize ( block )
279286 name = ( name || "candidate" ) . to_s
280287
281288 if behaviors . include? ( name )
@@ -287,6 +294,7 @@ def try(name = nil, &block)
287294
288295 # Register the control behavior for this experiment.
289296 def use ( &block )
297+ marshalize ( block )
290298 try "control" , &block
291299 end
292300
@@ -318,4 +326,19 @@ def generate_result(name)
318326 control = observations . detect { |o | o . name == name }
319327 Scientist ::Result . new ( self , observations , control )
320328 end
329+
330+ private
331+
332+ # In order to support marshaling, we have to make the procs marshalable. Some
333+ # CI providers attempt to marshal Scientist mismatch errors so that they can
334+ # be sent out to different places (logs, etc.) The mismatch errors contain
335+ # code from the experiment. This code contains Procs - which can't be
336+ # marshaled until we run the following code.
337+ def marshalize ( block )
338+ unless block . respond_to? ( :_dump ) || block . respond_to? ( :_dump_data )
339+ def block . _dump ( _ )
340+ to_s
341+ end
342+ end
343+ end
321344end
0 commit comments