scientist 1.6.2 → 1.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/ci.yml +33 -0
- data/README.md +4 -4
- data/Rakefile +7 -0
- data/lib/scientist/experiment.rb +23 -16
- data/lib/scientist/observation.rb +1 -1
- data/lib/scientist/version.rb +1 -1
- data/scientist.gemspec +1 -1
- data/script/test +1 -6
- data/test/scientist/experiment_test.rb +31 -0
- data/test/test_helper.rb +4 -0
- metadata +13 -9
- data/.travis.yml +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5553615794cee9e0fbdb4c22b3dd528885b30a75c9c8c2bd1d5d4f8ebd4bc0ba
|
4
|
+
data.tar.gz: ff1c3e2b2f23defc19ad663df792da483926406aa98261d403fa7c008c03be85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffef7682cdd59612ca44b33ba3678467251c2ccabfdecda41022cc95c0d07673abd38ca3a33c357fa40358398691ba0f8ecf8ec04ddff14800a25a915f011f4d
|
7
|
+
data.tar.gz: 06e06b1428967829d9b330eba28bd1bd2ce47eb5b12b6317eb6c6e8ea53e4e6434337803b88fdadbccdcb23a1b8cafe2fbe98a38756ea53d81ed21afe0ec369e
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push, pull_request]
|
3
|
+
permissions:
|
4
|
+
actions: none
|
5
|
+
checks: write
|
6
|
+
contents: read
|
7
|
+
deployments: none
|
8
|
+
issues: none
|
9
|
+
packages: none
|
10
|
+
pull-requests: none
|
11
|
+
repository-projects: none
|
12
|
+
security-events: none
|
13
|
+
statuses: write
|
14
|
+
jobs:
|
15
|
+
build:
|
16
|
+
name: ruby-${{ matrix.ruby_version }}
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
strategy:
|
19
|
+
fail-fast: false
|
20
|
+
matrix:
|
21
|
+
ruby_version:
|
22
|
+
- "2.6"
|
23
|
+
- "2.7"
|
24
|
+
- "3.0"
|
25
|
+
- "3.1"
|
26
|
+
- "3.2"
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v3
|
29
|
+
- uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby_version }}
|
32
|
+
bundler-cache: true
|
33
|
+
- run: bundle exec rake
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Scientist!
|
2
2
|
|
3
|
-
A Ruby library for carefully refactoring critical paths. [![Build Status](https://
|
3
|
+
A Ruby library for carefully refactoring critical paths. [![Build Status](https://github.com/github/scientist/actions/workflows/ci.yml/badge.svg)](https://github.com/github/scientist/actions/workflows/ci.yml)
|
4
4
|
|
5
5
|
## How do I science?
|
6
6
|
|
@@ -109,7 +109,7 @@ class MyWidget
|
|
109
109
|
end
|
110
110
|
```
|
111
111
|
|
112
|
-
If either the control block or candidate block raises an error, Scientist compares the two observations' classes and messages using `==`. To override this behavior, use `
|
112
|
+
If either the control block or candidate block raises an error, Scientist compares the two observations' classes and messages using `==`. To override this behavior, use `compare_errors` to define how to compare observed errors instead:
|
113
113
|
|
114
114
|
```ruby
|
115
115
|
class MyWidget
|
@@ -132,7 +132,7 @@ class MyWidget
|
|
132
132
|
candidate.message.start_with?("Invalid characters in input")
|
133
133
|
end
|
134
134
|
|
135
|
-
e.
|
135
|
+
e.compare_errors do |control, candidate|
|
136
136
|
compare_error_message_and_class.call(control, candidate) ||
|
137
137
|
compare_argument_errors.call(control, candidate)
|
138
138
|
end
|
@@ -260,7 +260,7 @@ def admin?(user)
|
|
260
260
|
end
|
261
261
|
```
|
262
262
|
|
263
|
-
The ignore blocks are only called if the *values* don't match. Unless a `
|
263
|
+
The ignore blocks are only called if the *values* don't match. Unless a `compare_errors` comparator is defined, two cases are considered mismatches: a) one observation raising an exception and the other not, b) observations raising exceptions with different classes or messages.
|
264
264
|
|
265
265
|
### Enabling/disabling experiments
|
266
266
|
|
data/Rakefile
ADDED
data/lib/scientist/experiment.rb
CHANGED
@@ -84,10 +84,19 @@ module Scientist::Experiment
|
|
84
84
|
#
|
85
85
|
# Returns the configured block.
|
86
86
|
def before_run(&block)
|
87
|
-
marshalize(block)
|
88
87
|
@_scientist_before_run = block
|
89
88
|
end
|
90
89
|
|
90
|
+
# Define a block of code to run after an experiment completes, if the experiment
|
91
|
+
# is enabled.
|
92
|
+
#
|
93
|
+
# The block takes one argument, the Scientist::Result containing experiment results.
|
94
|
+
#
|
95
|
+
# Returns the configured block.
|
96
|
+
def after_run(&block)
|
97
|
+
@_scientist_after_run = block
|
98
|
+
end
|
99
|
+
|
91
100
|
# A Hash of behavior blocks, keyed by String name. Register behavior blocks
|
92
101
|
# with the `try` and `use` methods.
|
93
102
|
def behaviors
|
@@ -100,7 +109,6 @@ module Scientist::Experiment
|
|
100
109
|
#
|
101
110
|
# Returns the configured block.
|
102
111
|
def clean(&block)
|
103
|
-
marshalize(block)
|
104
112
|
@_scientist_cleaner = block
|
105
113
|
end
|
106
114
|
|
@@ -133,7 +141,6 @@ module Scientist::Experiment
|
|
133
141
|
#
|
134
142
|
# Returns the block.
|
135
143
|
def compare(*args, &block)
|
136
|
-
marshalize(block)
|
137
144
|
@_scientist_comparator = block
|
138
145
|
end
|
139
146
|
|
@@ -144,7 +151,6 @@ module Scientist::Experiment
|
|
144
151
|
#
|
145
152
|
# Returns the block.
|
146
153
|
def compare_errors(*args, &block)
|
147
|
-
marshalize(block)
|
148
154
|
@_scientist_error_comparator = block
|
149
155
|
end
|
150
156
|
|
@@ -163,7 +169,6 @@ module Scientist::Experiment
|
|
163
169
|
#
|
164
170
|
# This can be called more than once with different blocks to use.
|
165
171
|
def ignore(&block)
|
166
|
-
marshalize(block)
|
167
172
|
@_scientist_ignores ||= []
|
168
173
|
@_scientist_ignores << block
|
169
174
|
end
|
@@ -235,6 +240,10 @@ module Scientist::Experiment
|
|
235
240
|
|
236
241
|
result = generate_result(name)
|
237
242
|
|
243
|
+
if @_scientist_after_run
|
244
|
+
@_scientist_after_run.call(result)
|
245
|
+
end
|
246
|
+
|
238
247
|
begin
|
239
248
|
publish(result)
|
240
249
|
rescue StandardError => ex
|
@@ -256,7 +265,6 @@ module Scientist::Experiment
|
|
256
265
|
|
257
266
|
# Define a block that determines whether or not the experiment should run.
|
258
267
|
def run_if(&block)
|
259
|
-
marshalize(block)
|
260
268
|
@_scientist_run_if_block = block
|
261
269
|
end
|
262
270
|
|
@@ -282,7 +290,6 @@ module Scientist::Experiment
|
|
282
290
|
|
283
291
|
# Register a named behavior for this experiment, default "candidate".
|
284
292
|
def try(name = nil, &block)
|
285
|
-
marshalize(block)
|
286
293
|
name = (name || "candidate").to_s
|
287
294
|
|
288
295
|
if behaviors.include?(name)
|
@@ -294,7 +301,6 @@ module Scientist::Experiment
|
|
294
301
|
|
295
302
|
# Register the control behavior for this experiment.
|
296
303
|
def use(&block)
|
297
|
-
marshalize(block)
|
298
304
|
try "control", &block
|
299
305
|
end
|
300
306
|
|
@@ -332,13 +338,14 @@ module Scientist::Experiment
|
|
332
338
|
# In order to support marshaling, we have to make the procs marshalable. Some
|
333
339
|
# CI providers attempt to marshal Scientist mismatch errors so that they can
|
334
340
|
# be sent out to different places (logs, etc.) The mismatch errors contain
|
335
|
-
# code from the experiment. This code contains
|
336
|
-
# marshaled
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
341
|
+
# code from the experiment. This code contains procs. These procs prevent the
|
342
|
+
# error from being marshaled. To fix this, we simple exclude the procs from
|
343
|
+
# the data that we marshal.
|
344
|
+
def marshal_dump
|
345
|
+
[@name, @result, @raise_on_mismatches]
|
346
|
+
end
|
347
|
+
|
348
|
+
def marshal_load
|
349
|
+
@name, @result, @raise_on_mismatches = array
|
343
350
|
end
|
344
351
|
end
|
@@ -58,7 +58,7 @@ class Scientist::Observation
|
|
58
58
|
# * The values of the observation are equal (using `==`)
|
59
59
|
# * The values of the observations are equal according to a comparison
|
60
60
|
# proc, if given
|
61
|
-
# * The exceptions raised by the
|
61
|
+
# * The exceptions raised by the observations are equal according to the
|
62
62
|
# error comparison proc, if given.
|
63
63
|
# * Both observations raised an exception with the same class and message.
|
64
64
|
#
|
data/lib/scientist/version.rb
CHANGED
data/scientist.gemspec
CHANGED
data/script/test
CHANGED
@@ -4,9 +4,4 @@
|
|
4
4
|
set -e
|
5
5
|
|
6
6
|
cd $(dirname "$0")/..
|
7
|
-
script/bootstrap && bundle exec
|
8
|
-
-e 'require "bundler/setup"' \
|
9
|
-
-e 'require "coveralls"; Coveralls.wear!{ add_filter ".bundle" }' \
|
10
|
-
-e 'require "minitest/autorun"' \
|
11
|
-
-e 'require "scientist"' \
|
12
|
-
-e '(ARGV.empty? ? Dir["test/**/*_test.rb"] : ARGV).each { |f| load f }' -- "$@"
|
7
|
+
script/bootstrap && bundle exec rake test
|
@@ -635,6 +635,37 @@ candidate:
|
|
635
635
|
end
|
636
636
|
end
|
637
637
|
|
638
|
+
describe "after run block" do
|
639
|
+
it "runs when an experiment is enabled" do
|
640
|
+
control_ok = candidate_ok = false
|
641
|
+
after_result = nil
|
642
|
+
@ex.after_run { |result| after_result = result }
|
643
|
+
@ex.use { control_ok = after_result.nil? }
|
644
|
+
@ex.try { candidate_ok = after_result.nil? }
|
645
|
+
|
646
|
+
@ex.run
|
647
|
+
|
648
|
+
assert after_result, "after_run should have run"
|
649
|
+
assert after_result.matched?, "after_run should be called with the result"
|
650
|
+
assert control_ok, "control should have run before after_run"
|
651
|
+
assert candidate_ok, "candidate should have run before after_run"
|
652
|
+
end
|
653
|
+
|
654
|
+
it "does not run when an experiment is disabled" do
|
655
|
+
after_result = nil
|
656
|
+
|
657
|
+
def @ex.enabled?
|
658
|
+
false
|
659
|
+
end
|
660
|
+
@ex.after_run { |result| after_result = result }
|
661
|
+
@ex.use { "value" }
|
662
|
+
@ex.try { "value" }
|
663
|
+
@ex.run
|
664
|
+
|
665
|
+
refute after_result, "after_run should not have run"
|
666
|
+
end
|
667
|
+
end
|
668
|
+
|
638
669
|
describe "testing hooks for extending code" do
|
639
670
|
it "allows a user to provide fabricated durations for testing purposes" do
|
640
671
|
@ex.use { true }
|
data/test/test_helper.rb
ADDED
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.
|
4
|
+
version: 1.6.4
|
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:
|
15
|
+
date: 2023-04-05 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: minitest
|
@@ -29,19 +29,19 @@ dependencies:
|
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: '5.8'
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
|
-
name:
|
32
|
+
name: rake
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
requirements:
|
35
|
-
- - "
|
35
|
+
- - ">="
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '0
|
37
|
+
version: '0'
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
|
-
- - "
|
42
|
+
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: '0
|
44
|
+
version: '0'
|
45
45
|
description: A Ruby library for carefully refactoring critical paths
|
46
46
|
email:
|
47
47
|
- opensource+scientist@github.com
|
@@ -53,12 +53,14 @@ executables: []
|
|
53
53
|
extensions: []
|
54
54
|
extra_rdoc_files: []
|
55
55
|
files:
|
56
|
+
- ".github/dependabot.yml"
|
57
|
+
- ".github/workflows/ci.yml"
|
56
58
|
- ".gitignore"
|
57
|
-
- ".travis.yml"
|
58
59
|
- CONTRIBUTING.md
|
59
60
|
- Gemfile
|
60
61
|
- LICENSE.txt
|
61
62
|
- README.md
|
63
|
+
- Rakefile
|
62
64
|
- doc/changelog.md
|
63
65
|
- lib/scientist.rb
|
64
66
|
- lib/scientist/default.rb
|
@@ -76,6 +78,7 @@ files:
|
|
76
78
|
- test/scientist/observation_test.rb
|
77
79
|
- test/scientist/result_test.rb
|
78
80
|
- test/scientist_test.rb
|
81
|
+
- test/test_helper.rb
|
79
82
|
homepage: https://github.com/github/scientist
|
80
83
|
licenses:
|
81
84
|
- MIT
|
@@ -95,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
98
|
- !ruby/object:Gem::Version
|
96
99
|
version: '0'
|
97
100
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
101
|
+
rubygems_version: 3.3.7
|
99
102
|
signing_key:
|
100
103
|
specification_version: 4
|
101
104
|
summary: Carefully test, measure, and track refactored code.
|
@@ -105,3 +108,4 @@ test_files:
|
|
105
108
|
- test/scientist/observation_test.rb
|
106
109
|
- test/scientist/result_test.rb
|
107
110
|
- test/scientist_test.rb
|
111
|
+
- test/test_helper.rb
|