scientist 1.1.1 → 1.1.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: 2ad0ca94921ed85fa82b13057d4c68c842d42ea256df543b32196e665c75519c
4
- data.tar.gz: 02f8948568c02e57d003b42a7ca4964e78e1ca14df57b6f204c2db31be5098a9
3
+ metadata.gz: 7a444eefb69bf453db50912ba9a629edd0845f1b2591c36809f4329862188b82
4
+ data.tar.gz: 28895c2df468c46c10d4b474ee9aa58b448514bb856c6f059112ad48d09bb97b
5
5
  SHA512:
6
- metadata.gz: 671d170da1739b46f102a898a32b522438f45323cc1d2b788865566bfc2c16d16c6b364c4610a97ee30e4da597642bb4ad9d2c422384eddbab278ae170469f9f
7
- data.tar.gz: 5334f5ae2d735cdc3b230bfefd469bd51c9e9363ec5cec83d45e99cbb2b3b55fa14f057dc59dc7909828dc0182c9168c9a86d47efe5529971206b9ff5c14a52a
6
+ metadata.gz: 40c3e14294c377e70c86e03b50ac121da94b8e79e0b5f14a6844343a4f5b56b6fa340f66caa4671498e303978eea9ebd331ad7633aebd6b5901d970321f71342
7
+ data.tar.gz: '092d3a37710ea538580205e284b31314eb298b5d10d910d2a36cff0b334ecbbd01c2b9311b35769eec7f308549f954c1a27084306f60232cd18bae24fd59e96d'
@@ -0,0 +1,26 @@
1
+ ## Contributing
2
+
3
+ [fork]: https://github.com/github/scientist/fork
4
+ [pr]: https://github.com/github/scientist/compare
5
+
6
+ Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
7
+
8
+ Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE.txt).
9
+
10
+ ## Submitting a pull request
11
+
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.
16
+
17
+ Here are a few things you can do that will increase the likelihood of your pull request being accepted:
18
+
19
+ - Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
20
+ - Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
21
+
22
+ ## Resources
23
+
24
+ - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
25
+ - [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
26
+ - [GitHub Help](https://help.github.com)
data/README.md CHANGED
@@ -52,7 +52,7 @@ If you don't declare any `try` blocks, none of the Scientist machinery is invoke
52
52
 
53
53
  ## Making science useful
54
54
 
55
- The examples above will run, but they're not really *doing* anything. The `try` blocks run every time and none of the results get published. Replace the default experiment implementation to control execution and reporting:
55
+ The examples above will run, but they're not really *doing* anything. The `try` blocks don't run yet and none of the results get published. Replace the default experiment implementation to control execution and reporting:
56
56
 
57
57
  ```ruby
58
58
  require "scientist/experiment"
@@ -352,6 +352,35 @@ MyExperiment.raise_on_mismatches = true
352
352
 
353
353
  Scientist will raise a `Scientist::Experiment::MismatchError` exception if any observations don't match.
354
354
 
355
+ #### Custom mismatch errors
356
+
357
+ To instruct Scientist to raise a custom error instead of the default `Scientist::Experiment::MismatchError`:
358
+
359
+ ```ruby
360
+ class CustomMismatchError < Scientist::Experiment::MismatchError
361
+ def to_s
362
+ message = "There was a mismatch! Here's the diff:"
363
+
364
+ diffs = result.candidates.map do |candidate|
365
+ Diff.new(result.control, candidate)
366
+ end.join("\n")
367
+
368
+ "#{message}\n#{diffs}"
369
+ end
370
+ end
371
+ ```
372
+
373
+ ```ruby
374
+ science "widget-permissions" do |e|
375
+ e.use { Report.find(id) }
376
+ e.try { ReportService.new.fetch(id) }
377
+
378
+ e.raise_with CustomMismatchError
379
+ end
380
+ ```
381
+
382
+ This allows for pre-processing on mismatch error exception messages.
383
+
355
384
  ### Handling errors
356
385
 
357
386
  #### In candidate code
@@ -44,7 +44,7 @@ module Scientist::Experiment
44
44
  observation.exception.inspect.prepend(" ") + "\n" +
45
45
  observation.exception.backtrace.map { |line| line.prepend(" ") }.join("\n")
46
46
  else
47
- observation.value.inspect.prepend(" ")
47
+ observation.cleaned_value.inspect.prepend(" ")
48
48
  end
49
49
  end
50
50
  end
@@ -176,6 +176,10 @@ module Scientist::Experiment
176
176
  false
177
177
  end
178
178
 
179
+ def raise_with(exception)
180
+ @_scientist_custom_mismatch_error = exception
181
+ end
182
+
179
183
  # Called when an exception is raised while running an internal operation,
180
184
  # like :publish. Override this method to track these exceptions. The
181
185
  # default implementation re-raises the exception.
@@ -223,7 +227,11 @@ module Scientist::Experiment
223
227
  end
224
228
 
225
229
  if raise_on_mismatches? && result.mismatched?
226
- raise MismatchError.new(self.name, result)
230
+ if @_scientist_custom_mismatch_error
231
+ raise @_scientist_custom_mismatch_error.new(self.name, result)
232
+ else
233
+ raise MismatchError.new(self.name, result)
234
+ end
227
235
  end
228
236
 
229
237
  if control.raised?
@@ -1,3 +1,3 @@
1
1
  module Scientist
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -262,6 +262,19 @@ describe Scientist::Experiment do
262
262
  assert_equal "kaboom", exception.message
263
263
  end
264
264
 
265
+ describe "#raise_with" do
266
+ it "raises custom error if provided" do
267
+ CustomError = Class.new(Scientist::Experiment::MismatchError)
268
+
269
+ @ex.use { 1 }
270
+ @ex.try { 2 }
271
+ @ex.raise_with(CustomError)
272
+ @ex.raise_on_mismatches = true
273
+
274
+ assert_raises(CustomError) { @ex.run }
275
+ end
276
+ end
277
+
265
278
  describe "#run_if" do
266
279
  it "does not run the experiment if the given block returns false" do
267
280
  candidate_ran = false
@@ -392,6 +405,16 @@ describe Scientist::Experiment do
392
405
  assert_raises(Scientist::Experiment::MismatchError) { @ex.run }
393
406
  end
394
407
 
408
+ it "cleans values when raising on observation mismatch" do
409
+ Fake.raise_on_mismatches = true
410
+ @ex.use { "fine" }
411
+ @ex.try { "not fine" }
412
+ @ex.clean { "So Clean" }
413
+
414
+ err = assert_raises(Scientist::Experiment::MismatchError) { @ex.run }
415
+ assert_match /So Clean/, err.message
416
+ end
417
+
395
418
  it "doesn't raise when there is a mismatch if raise on mismatches is disabled" do
396
419
  Fake.raise_on_mismatches = false
397
420
  @ex.use { "fine" }
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.1.1
4
+ version: 1.1.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: 2018-02-06 00:00:00.000000000 Z
15
+ date: 2018-05-09 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: minitest
@@ -55,6 +55,7 @@ extra_rdoc_files: []
55
55
  files:
56
56
  - ".gitignore"
57
57
  - ".travis.yml"
58
+ - CONTRIBUTING.md
58
59
  - Gemfile
59
60
  - LICENSE.txt
60
61
  - README.md