Skip to content

Commit 281a4d7

Browse files
committed
Make default experiment not run all try paths
It is quite possible to follow the directions in the README.md, create a localized experiment class with a real `enabled?` method `publish` methods, etc., and expect folks to require your library and use it. But, it's also possible that someone will define an experiment, neglectd to include your local experiment override library, still have scientist in the require path, and when they `include Scientist` in their experiment-running class, they will get the "default" scientist experiment. The default experiment runs every `try` branch. In production environments pushing a new experiment and having it run the `try` branch unconditionally is less than ideal. This flips the default `enabled?` to 'false`. At least folks will dig a bit to realize they could include their local library by default and dodge this problem.
1 parent 2046359 commit 281a4d7

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

lib/scientist/default.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ def initialize(name)
1010
@name = name
1111
end
1212

13-
# Run everything every time.
13+
# Don't run experiments.
1414
def enabled?
15-
true
15+
false
1616
end
1717

1818
# Don't publish anything.

test/scientist/default_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
@ex = Scientist::Default.new "default"
44
end
55

6-
it "is always enabled" do
7-
assert @ex.enabled?
6+
it "is always disabled" do
7+
refute @ex.enabled?
88
end
99

1010
it "noops publish" do

test/scientist/experiment_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ def publish(result)
123123
it "re-raises exceptions raised during publish by default" do
124124
ex = Scientist::Experiment.new("hello")
125125
assert_kind_of Scientist::Default, ex
126+
127+
def ex.enabled?
128+
true
129+
end
130+
126131
def ex.publish(result)
127132
raise "boomtown"
128133
end

0 commit comments

Comments
 (0)