Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/scientist/experiment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ module Scientist::Experiment
attr_accessor :raise_on_mismatches

def self.included(base)
self.set_default(base) if base.instance_of?(Class)
set_default(base) if base.instance_of?(Class)
base.extend RaiseOnMismatch
end

# Set this class as default scientist experiment when included.
def self.set_as_default_scientist_experiment(set_default_class)
set_default(Scientist::Default) unless set_default_class
end

# Instantiate a new experiment (using the class given to the .set_default method).
def self.new(name)
(@experiment_klass || Scientist::Default).new(name)
Expand Down
13 changes: 13 additions & 0 deletions test/scientist/experiment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ def publish(result)
@ex = Fake.new
end

it "does not set as default when default_scientist_experiment is passed as false" do
klass = Class.new do
include Scientist::Experiment

Scientist::Experiment.set_as_default_scientist_experiment(false)

def initialize(name)
end
end

assert_kind_of Scientist::Default, Scientist::Experiment.new("hello")
end

it "sets the default on inclusion" do
klass = Class.new do
include Scientist::Experiment
Expand Down