@@ -84,6 +84,7 @@ def raise_on_mismatches?
84
84
#
85
85
# Returns the configured block.
86
86
def before_run ( &block )
87
+ marshalize ( block )
87
88
@_scientist_before_run = block
88
89
end
89
90
@@ -99,6 +100,7 @@ def behaviors
99
100
#
100
101
# Returns the configured block.
101
102
def clean ( &block )
103
+ marshalize ( block )
102
104
@_scientist_cleaner = block
103
105
end
104
106
@@ -131,6 +133,7 @@ def clean_value(value)
131
133
#
132
134
# Returns the block.
133
135
def compare ( *args , &block )
136
+ marshalize ( block )
134
137
@_scientist_comparator = block
135
138
end
136
139
@@ -141,6 +144,7 @@ def compare(*args, &block)
141
144
#
142
145
# Returns the block.
143
146
def compare_errors ( *args , &block )
147
+ marshalize ( block )
144
148
@_scientist_error_comparator = block
145
149
end
146
150
@@ -159,6 +163,7 @@ def context(context = nil)
159
163
#
160
164
# This can be called more than once with different blocks to use.
161
165
def ignore ( &block )
166
+ marshalize ( block )
162
167
@_scientist_ignores ||= [ ]
163
168
@_scientist_ignores << block
164
169
end
@@ -251,6 +256,7 @@ def run(name = nil)
251
256
252
257
# Define a block that determines whether or not the experiment should run.
253
258
def run_if ( &block )
259
+ marshalize ( block )
254
260
@_scientist_run_if_block = block
255
261
end
256
262
@@ -276,6 +282,7 @@ def should_experiment_run?
276
282
277
283
# Register a named behavior for this experiment, default "candidate".
278
284
def try ( name = nil , &block )
285
+ marshalize ( block )
279
286
name = ( name || "candidate" ) . to_s
280
287
281
288
if behaviors . include? ( name )
@@ -287,6 +294,7 @@ def try(name = nil, &block)
287
294
288
295
# Register the control behavior for this experiment.
289
296
def use ( &block )
297
+ marshalize ( block )
290
298
try "control" , &block
291
299
end
292
300
@@ -318,4 +326,19 @@ def generate_result(name)
318
326
control = observations . detect { |o | o . name == name }
319
327
Scientist ::Result . new ( self , observations , control )
320
328
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
321
344
end
0 commit comments