scientist 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eee7969d8abea0f0fa0a53dea180d2f786d67a589b8694b2ccf6c70bdcedcbb4
4
- data.tar.gz: 87bb457307fb452731efed8413770abed9f3d687e9718dd54edce106d745d389
3
+ metadata.gz: 1e623b9acbede185a6ee8ca0ae2227a52707499c28bdf04e4fe8a2afcbd0f051
4
+ data.tar.gz: 560b1d3353829f6be217229546297fcd4102e6c47dc87fc12ffa963c5e2fa3f7
5
5
  SHA512:
6
- metadata.gz: 882c44d39b595fe4c660abd619b5889552fe5d48c8bf2a2ff57e8b62fa221853a3af8727d04318068da888b6a8dd59e23f78c0eda71237261e409cb4038a5524
7
- data.tar.gz: a6397a830792dda87404c7775d804d19a8b229a488180bba633501ff80ca889b9e61d44cf06287e48059664f8d6dd5097bf82e2ac6c4d33e478e02ea5e88c78f
6
+ metadata.gz: 593c2807ff16f1381a0189e4babdad3ab366ad66057e4af1b083611fb204d55ae9434bf989550f8371de7586be55fe4f8a760f84f2424323a9189803583e9243
7
+ data.tar.gz: 1239bb86dfad9fcee2b0dc4dc2fc8458306e877afd2aa1e722b9e4db7072b71658469bf48b425959c52111fac2cc8bb5dbbb11435263a199f036ad2ee4697228
data/CONTRIBUTING.md CHANGED
@@ -10,9 +10,9 @@ Contributions to this project are [released](https://help.github.com/articles/gi
10
10
  ## Submitting a pull request
11
11
 
12
12
  0. [Fork][fork] and clone the repository
13
- 0. Create a new branch: `git checkout -b my-branch-name`
14
- 0. Make your change, push to your fork and [submit a pull request][pr]
15
- 0. Pat your self on the back and wait for your pull request to be reviewed and merged.
13
+ 1. Create a new branch: `git checkout -b my-branch-name`
14
+ 2. Make your change, push to your fork and [submit a pull request][pr]
15
+ 3. Pat your self on the back and wait for your pull request to be reviewed and merged.
16
16
 
17
17
  Here are a few things you can do that will increase the likelihood of your pull request being accepted:
18
18
 
data/README.md CHANGED
@@ -84,7 +84,7 @@ class MyExperiment
84
84
  end
85
85
  ```
86
86
 
87
- When `Scientist::Experiment` is included in a class, it automatically sets it as the default implementation via `Scientist::Experiment.set_default`. This `set_default` call is is skipped if you include `Scientist::Experiment` in a module.
87
+ When `Scientist::Experiment` is included in a class, it automatically sets it as the default implementation via `Scientist::Experiment.set_default`. This `set_default` call is skipped if you include `Scientist::Experiment` in a module.
88
88
 
89
89
  Now calls to the `science` helper will load instances of `MyExperiment`.
90
90
 
@@ -129,7 +129,7 @@ class MyWidget
129
129
  control.class == ArgumentError &&
130
130
  candidate.class == ArgumentError &&
131
131
  control.message.start_with?("Input has invalid characters") &&
132
- candidate.message.star_with?("Invalid characters in input")
132
+ candidate.message.start_with?("Invalid characters in input")
133
133
  end
134
134
 
135
135
  e.compare_error do |control, candidate|
@@ -84,6 +84,7 @@ module Scientist::Experiment
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 @@ module Scientist::Experiment
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 @@ module Scientist::Experiment
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 @@ module Scientist::Experiment
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 @@ module Scientist::Experiment
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 @@ module Scientist::Experiment
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 @@ module Scientist::Experiment
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 @@ module Scientist::Experiment
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 @@ module Scientist::Experiment
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
@@ -1,3 +1,3 @@
1
1
  module Scientist
2
- VERSION = "1.6.1"
2
+ VERSION = "1.6.2"
3
3
  end
data/script/release CHANGED
@@ -12,10 +12,10 @@ cd $(dirname "$0")/..
12
12
  rm -rf scientist-*.gem
13
13
  gem build -q scientist.gemspec
14
14
 
15
- # Make sure we're on the master branch.
15
+ # Make sure we're on the main branch.
16
16
 
17
- (git branch --no-color | grep -q '* master') || {
18
- echo "Only release from the master branch."
17
+ (git branch --no-color | grep -q '* main') || {
18
+ echo "Only release from the main branch."
19
19
  exit 1
20
20
  }
21
21
 
@@ -35,4 +35,4 @@ git fetch -t origin
35
35
  # Tag it and bag it.
36
36
 
37
37
  gem push scientist-*.gem && git tag "$tag" &&
38
- git push origin master && git push origin "$tag"
38
+ git push origin main && git push origin "$tag"
@@ -491,6 +491,27 @@ describe Scientist::Experiment do
491
491
  assert_raises(Scientist::Experiment::MismatchError) { runner.call }
492
492
  end
493
493
 
494
+ it "can be marshaled" do
495
+ Fake.raise_on_mismatches = true
496
+ @ex.before_run { "some block" }
497
+ @ex.clean { "some block" }
498
+ @ex.compare_errors { "some block" }
499
+ @ex.ignore { false }
500
+ @ex.run_if { "some block" }
501
+ @ex.try { "candidate" }
502
+ @ex.use { "control" }
503
+ @ex.compare { |control, candidate| control == candidate }
504
+
505
+ mismatch = nil
506
+ begin
507
+ @ex.run
508
+ rescue Scientist::Experiment::MismatchError => e
509
+ mismatch = e
510
+ end
511
+
512
+ assert_kind_of(String, Marshal.dump(mismatch))
513
+ end
514
+
494
515
  describe "#raise_on_mismatches?" do
495
516
  it "raises when there is a mismatch if the experiment instance's raise on mismatches is enabled" do
496
517
  Fake.raise_on_mismatches = false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scientist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2021-10-22 00:00:00.000000000 Z
15
+ date: 2021-11-04 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: minitest