1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
describe Scientist do
it "has a version or whatever" do
assert Scientist::VERSION
end
it "provides a helper to instantiate and run experiments" do
obj = Object.new
obj.extend(Scientist)
r = obj.science "test" do |e|
e.use { :control }
e.try { :candidate }
end
assert_equal :control, r
end
it "provides a module method to instantiate and run experiments" do
r = Scientist.run "test" do |e|
e.use { :control }
e.try { :candidate }
end
assert_equal :control, r
end
it "provides an empty default_scientist_context" do
obj = Object.new
obj.extend(Scientist)
assert_equal Hash.new, obj.default_scientist_context
end
it "respects default_scientist_context" do
obj = Object.new
obj.extend(Scientist)
def obj.default_scientist_context
{ :default => true }
end
experiment = nil
obj.science "test" do |e|
experiment = e
e.context :inline => true
e.use { }
end
refute_nil experiment
assert_equal true, experiment.context[:default]
assert_equal true, experiment.context[:inline]
end
it "runs the named test instead of the control" do
obj = Object.new
obj.extend(Scientist)
behaviors_executed = []
result = obj.science "test", run: "first-way" do |e|
e.try("first-way") { behaviors_executed << "first-way" ; true }
e.try("second-way") { behaviors_executed << "second-way" ; true }
end
assert_equal true, result
assert_equal [ "first-way" ], behaviors_executed
end
it "runs control when there is a nil named test" do
obj = Object.new
obj.extend(Scientist)
behaviors_executed = []
result = obj.science "test", nil do |e|
e.use { behaviors_executed << "control" ; true }
e.try("second-way") { behaviors_executed << "second-way" ; true }
end
assert_equal true, result
assert_equal [ "control" ], behaviors_executed
end
end
|