scientist 0.0.1 → 0.0.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
  SHA1:
3
- metadata.gz: 7b1ce13f8a2483a8027f3252d79a962dd116733c
4
- data.tar.gz: 54e81bb6123073b95c9bec0b1e751f88519fd498
3
+ metadata.gz: 613a01313617522a1af4515a526d8272c0f6cb77
4
+ data.tar.gz: eedb1a19d72a5833a088df4c971fdda221d03dfa
5
5
  SHA512:
6
- metadata.gz: 5e97d816e8b340701d2a6488799f899ae74480992e223258615c96c6f19042d53a867680aada5cc010c5718fa499d31889056f111b9476b810ac74af2023b4d7
7
- data.tar.gz: c65a04f83ef07d9c770354fc5a1dcfa1a76199f150152c0c39735839eec2cf975f333779418827c201d03b4e9047d9afcb740d1ac735a69004e2a945afafb5de
6
+ metadata.gz: 57f63ef2a49baba246d1b1fa0e7b378ff590a4a5a764aa23754e103c7f73f09ec7cc89f4ffaa07bfebc04da91f0c0215d8bf5d7eef1f8d18e19213a0ccad9078
7
+ data.tar.gz: 8790f2ccee4042604dad41e5dac7d0471629e8013af69458e7898c77628ba73dbcd93b76cd7a15a7ae5203fa02d3561dcab92fec3654c1f9ad3fc9f3766ed9a7
data/CLA.md CHANGED
@@ -7,7 +7,7 @@ We welcome you to follow, fork, and work on, our open source projects. If you wa
7
7
 
8
8
  ## What is this?
9
9
 
10
- This is GitHub Inc.’s Contributor License Agreement. If you’ve worked in the technology space before, contributed or maintained an open source project, there’s a good chance that you’ve run across one or more of these in the past. What CLAs aim to do is make sure the project is able to merge contributions from multiple contributors without getting itself into different types of trouble. This one is no different in that sense.
10
+ This is GitHub Inc.'s Contributor License Agreement. If you've worked in the technology space before, contributed or maintained an open source project, there's a good chance that you've run across one or more of these in the past. What CLAs aim to do is make sure the project is able to merge contributions from multiple contributors without getting itself into different types of trouble. This one is no different in that sense.
11
11
 
12
12
  ## Why is this?
13
13
 
data/README.md CHANGED
@@ -27,7 +27,7 @@ Wrap a `use` block around the code's original behavior, and wrap `try` around th
27
27
  * Randomizes the order in which `use` and `try` blocks are run,
28
28
  * Measures the durations of all behaviors,
29
29
  * Compares the result of `try` to the result of `use`,
30
- * Swallows (but records) any exceptions raise in the `try` block, and
30
+ * Swallows (but records) any exceptions raised in the `try` block, and
31
31
  * Publishes all this information.
32
32
 
33
33
  The `use` block is called the **control**. The `try` block is called the **candidate**.
data/lib/scientist.rb CHANGED
@@ -7,20 +7,22 @@ module Scientist
7
7
  # Define and run a science experiment.
8
8
  #
9
9
  # name - a String name for this experiment.
10
- # run: - optional argument for which named test to run instead of "control".
10
+ # opts - optional hash with the the named test to run instead of "control",
11
+ # :run is the only valid key.
11
12
  #
12
13
  # Yields an object which implements the Scientist::Experiment interface.
13
14
  # See `Scientist::Experiment.new` for how this is defined.
14
15
  #
15
16
  # Returns the calculated value of the control experiment, or raises if an
16
17
  # exception was raised.
17
- def science(name, run: nil)
18
+ def science(name, opts = {})
18
19
  experiment = Experiment.new(name)
19
20
  experiment.context(default_scientist_context)
20
21
 
21
22
  yield experiment
22
23
 
23
- experiment.run(run)
24
+ test = Hash(opts)[:run]
25
+ experiment.run(test)
24
26
  end
25
27
 
26
28
  # Public: the default context data for an experiment created and run via the
@@ -169,9 +169,7 @@ module Scientist::Experiment
169
169
 
170
170
  control = observations.detect { |o| o.name == name }
171
171
 
172
- result = Scientist::Result.new self,
173
- observations: observations,
174
- control: control
172
+ result = Scientist::Result.new self, observations, control
175
173
 
176
174
  begin
177
175
  publish(result)
@@ -25,7 +25,7 @@ class Scientist::Result
25
25
  # observations: - an Array of Observations, in execution order
26
26
  # control: - the control Observation
27
27
  #
28
- def initialize(experiment, observations:, control:)
28
+ def initialize(experiment, observations = [], control = nil)
29
29
  @experiment = experiment
30
30
  @observations = observations
31
31
  @control = control
@@ -47,7 +47,7 @@ class Scientist::Result
47
47
 
48
48
  # Public: was the result a match between all behaviors?
49
49
  def matched?
50
- mismatched.empty?
50
+ mismatched.empty? && !ignored?
51
51
  end
52
52
 
53
53
  # Public: were there mismatches in the behaviors?
@@ -1,3 +1,3 @@
1
1
  module Scientist
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/scientist.gemspec CHANGED
@@ -10,8 +10,6 @@ Gem::Specification.new do |gem|
10
10
  gem.homepage = "https://github.com/github/scientist"
11
11
  gem.license = "MIT"
12
12
 
13
- gem.required_ruby_version = ">= 2.1.0"
14
-
15
13
  gem.files = `git ls-files`.split($/)
16
14
  gem.executables = []
17
15
  gem.test_files = gem.files.grep(/^test/)
@@ -7,9 +7,7 @@ describe Scientist::Result do
7
7
  control = Scientist::Observation.new("control", @experiment)
8
8
  candidate = Scientist::Observation.new("candidate", @experiment)
9
9
 
10
- result = Scientist::Result.new @experiment,
11
- observations: [control, candidate], control: control
12
-
10
+ result = Scientist::Result.new @experiment, [control, candidate], control
13
11
  assert result.frozen?
14
12
  end
15
13
 
@@ -19,7 +17,7 @@ describe Scientist::Result do
19
17
 
20
18
  assert a.equivalent_to?(b)
21
19
 
22
- result = Scientist::Result.new @experiment, observations: [a, b], control: a
20
+ result = Scientist::Result.new @experiment, [a, b], a
23
21
  assert result.matched?
24
22
  refute result.mismatched?
25
23
  assert_equal [], result.mismatched
@@ -28,7 +26,7 @@ describe Scientist::Result do
28
26
  y = Scientist::Observation.new("y", @experiment) { 2 }
29
27
  z = Scientist::Observation.new("z", @experiment) { 3 }
30
28
 
31
- result = Scientist::Result.new @experiment, observations: [x, y, z], control: x
29
+ result = Scientist::Result.new @experiment, [x, y, z], x
32
30
  refute result.matched?
33
31
  assert result.mismatched?
34
32
  assert_equal [y, z], result.mismatched
@@ -36,7 +34,7 @@ describe Scientist::Result do
36
34
 
37
35
  it "has no mismatches if there is only a control observation" do
38
36
  a = Scientist::Observation.new("a", @experiment) { 1 }
39
- result = Scientist::Result.new @experiment, observations: [a], control: a
37
+ result = Scientist::Result.new @experiment, [a], a
40
38
  assert result.matched?
41
39
  end
42
40
 
@@ -46,7 +44,7 @@ describe Scientist::Result do
46
44
 
47
45
  @experiment.compare { |x, y| x == y.to_s }
48
46
 
49
- result = Scientist::Result.new @experiment, observations: [a, b], control: a
47
+ result = Scientist::Result.new @experiment, [a, b], a
50
48
 
51
49
  assert result.matched?, result.mismatched
52
50
  end
@@ -55,7 +53,7 @@ describe Scientist::Result do
55
53
  x = Scientist::Observation.new("x", @experiment) { 1 }
56
54
  y = Scientist::Observation.new("y", @experiment) { 2 }
57
55
 
58
- result = Scientist::Result.new @experiment, observations: [x, y], control: x
56
+ result = Scientist::Result.new @experiment, [x, y], x
59
57
 
60
58
  assert result.mismatched?
61
59
  refute result.ignored?
@@ -67,9 +65,10 @@ describe Scientist::Result do
67
65
  called = false
68
66
  @experiment.ignore { called = true }
69
67
 
70
- result = Scientist::Result.new @experiment, observations: [x, y], control: x
68
+ result = Scientist::Result.new @experiment, [x, y], x
71
69
 
72
70
  refute result.mismatched?
71
+ refute result.matched?
73
72
  assert result.ignored?
74
73
  assert_equal [], result.mismatched
75
74
  assert_equal [y], result.ignored
@@ -83,7 +82,7 @@ describe Scientist::Result do
83
82
 
84
83
  @experiment.ignore { |control, candidate| candidate == :y }
85
84
 
86
- result = Scientist::Result.new @experiment, observations: [x, y, z], control: x
85
+ result = Scientist::Result.new @experiment, [x, y, z], x
87
86
 
88
87
  assert result.mismatched?
89
88
  assert result.ignored?
@@ -94,7 +93,7 @@ describe Scientist::Result do
94
93
  it "knows the experiment's name" do
95
94
  a = Scientist::Observation.new("a", @experiment) { 1 }
96
95
  b = Scientist::Observation.new("b", @experiment) { 1 }
97
- result = Scientist::Result.new @experiment, observations: [a, b], control: a
96
+ result = Scientist::Result.new @experiment, [a, b], a
98
97
 
99
98
  assert_equal @experiment.name, result.experiment_name
100
99
  end
@@ -103,7 +102,7 @@ describe Scientist::Result do
103
102
  @experiment.context :foo => :bar
104
103
  a = Scientist::Observation.new("a", @experiment) { 1 }
105
104
  b = Scientist::Observation.new("b", @experiment) { 1 }
106
- result = Scientist::Result.new @experiment, observations: [a, b], control: a
105
+ result = Scientist::Result.new @experiment, [a, b], a
107
106
 
108
107
  assert_equal({:foo => :bar}, result.context)
109
108
  end
@@ -42,4 +42,18 @@ describe Scientist do
42
42
  assert_equal true, experiment.context[:default]
43
43
  assert_equal true, experiment.context[:inline]
44
44
  end
45
+
46
+ it "runs the named test instead of the control" do
47
+ obj = Object.new
48
+ obj.extend(Scientist)
49
+
50
+ result = obj.science "test", run: "first-way" do |e|
51
+ experiment = e
52
+
53
+ e.try("first-way") { true }
54
+ e.try("second-way") { true }
55
+ end
56
+
57
+ assert_equal true, result
58
+ end
45
59
  end
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: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Barnette
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-18 00:00:00.000000000 Z
12
+ date: 2014-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -67,7 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
- version: 2.1.0
70
+ version: '0'
71
71
  required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="