spec/alternative_spec.rb in split-4.0.1 vs spec/alternative_spec.rb in split-4.0.2
- old
+ new
@@ -1,73 +1,73 @@
# frozen_string_literal: true
-require 'spec_helper'
-require 'split/alternative'
-describe Split::Alternative do
+require "spec_helper"
+require "split/alternative"
+describe Split::Alternative do
let(:alternative) {
- Split::Alternative.new('Basket', 'basket_text')
+ Split::Alternative.new("Basket", "basket_text")
}
let(:alternative2) {
- Split::Alternative.new('Cart', 'basket_text')
+ Split::Alternative.new("Cart", "basket_text")
}
let!(:experiment) {
- Split::ExperimentCatalog.find_or_create({"basket_text" => ["purchase", "refund"]}, "Basket", "Cart")
+ Split::ExperimentCatalog.find_or_create({ "basket_text" => ["purchase", "refund"] }, "Basket", "Cart")
}
let(:goal1) { "purchase" }
let(:goal2) { "refund" }
it "should have goals" do
expect(alternative.goals).to eq(["purchase", "refund"])
end
it "should have and only return the name" do
- expect(alternative.name).to eq('Basket')
+ expect(alternative.name).to eq("Basket")
end
- describe 'weights' do
+ describe "weights" do
it "should set the weights" do
- experiment = Split::Experiment.new('basket_text', :alternatives => [{'Basket' => 0.6}, {"Cart" => 0.4}])
+ experiment = Split::Experiment.new("basket_text", alternatives: [{ "Basket" => 0.6 }, { "Cart" => 0.4 }])
first = experiment.alternatives[0]
- expect(first.name).to eq('Basket')
+ expect(first.name).to eq("Basket")
expect(first.weight).to eq(0.6)
second = experiment.alternatives[1]
- expect(second.name).to eq('Cart')
+ expect(second.name).to eq("Cart")
expect(second.weight).to eq(0.4)
end
it "accepts probability on alternatives" do
Split.configuration.experiments = {
- :my_experiment => {
- :alternatives => [
- { :name => "control_opt", :percent => 67 },
- { :name => "second_opt", :percent => 10 },
- { :name => "third_opt", :percent => 23 },
+ my_experiment: {
+ alternatives: [
+ { name: "control_opt", percent: 67 },
+ { name: "second_opt", percent: 10 },
+ { name: "third_opt", percent: 23 },
]
}
}
experiment = Split::Experiment.new(:my_experiment)
first = experiment.alternatives[0]
- expect(first.name).to eq('control_opt')
+ expect(first.name).to eq("control_opt")
expect(first.weight).to eq(0.67)
second = experiment.alternatives[1]
- expect(second.name).to eq('second_opt')
+ expect(second.name).to eq("second_opt")
expect(second.weight).to eq(0.1)
end
it "accepts probability on some alternatives" do
Split.configuration.experiments = {
- :my_experiment => {
- :alternatives => [
- { :name => "control_opt", :percent => 34 },
+ my_experiment: {
+ alternatives: [
+ { name: "control_opt", percent: 34 },
"second_opt",
- { :name => "third_opt", :percent => 23 },
+ { name: "third_opt", percent: 23 },
"fourth_opt",
],
}
}
experiment = Split::Experiment.new(:my_experiment)
@@ -85,15 +85,15 @@
end
end
#
it "allows name param without probability" do
Split.configuration.experiments = {
- :my_experiment => {
- :alternatives => [
- { :name => "control_opt" },
+ my_experiment: {
+ alternatives: [
+ { name: "control_opt" },
"second_opt",
- { :name => "third_opt", :percent => 64 },
+ { name: "third_opt", percent: 64 },
],
}
}
experiment = Split::Experiment.new(:my_experiment)
alts = experiment.alternatives
@@ -124,11 +124,11 @@
expect(alternative.experiment.name).to eq(experiment.name)
end
it "should save to redis" do
alternative.save
- expect(Split.redis.exists?('basket_text:Basket')).to be true
+ expect(Split.redis.exists?("basket_text:Basket")).to be true
end
it "should increment participation count" do
old_participant_count = alternative.participant_count
alternative.increment_participation
@@ -164,11 +164,11 @@
it "should know if it is the control of an experiment" do
expect(alternative.control?).to be_truthy
expect(alternative2.control?).to be_falsey
end
- describe 'unfinished_count' do
+ describe "unfinished_count" do
it "should be difference between participant and completed counts" do
alternative.increment_participation
expect(alternative.unfinished_count).to eq(alternative.participant_count)
end
@@ -180,11 +180,11 @@
expect(alternative.unfinished_count).to eq(1)
end
end
- describe 'conversion rate' do
+ describe "conversion rate" do
it "should be 0 if there are no conversions" do
expect(alternative.completed_count).to eq(0)
expect(alternative.conversion_rate).to eq(0)
end
@@ -223,12 +223,11 @@
alternative.set_p_winner(0.5, goal1)
expect(alternative.p_winner(goal1)).to eq(0.5)
end
end
- describe 'z score' do
-
+ describe "z score" do
it "should return an error string when the control has 0 people" do
expect(alternative2.z_score).to eq("Needs 30+ participants.")
expect(alternative2.z_score(goal1)).to eq("Needs 30+ participants.")
expect(alternative2.z_score(goal2)).to eq("Needs 30+ participants.")
end
@@ -267,13 +266,13 @@
expect(alternative2.z_score.round(2)).to eq(2.58)
end
it "should be N/A for the control" do
control = experiment.control
- expect(control.z_score).to eq('N/A')
- expect(control.z_score(goal1)).to eq('N/A')
- expect(control.z_score(goal2)).to eq('N/A')
+ expect(control.z_score).to eq("N/A")
+ expect(control.z_score(goal1)).to eq("N/A")
+ expect(control.z_score(goal2)).to eq("N/A")
end
it "should not blow up for Conversion Rates > 1" do
control = experiment.control
control.participant_count = 3474
@@ -287,11 +286,11 @@
end
end
describe "extra_info" do
it "reads saved value of recorded_info in redis" do
- saved_recorded_info = {"key_1" => 1, "key_2" => "2"}
- Split.redis.hset "#{alternative.experiment_name}:#{alternative.name}", 'recorded_info', saved_recorded_info.to_json
+ saved_recorded_info = { "key_1" => 1, "key_2" => "2" }
+ Split.redis.hset "#{alternative.experiment_name}:#{alternative.name}", "recorded_info", saved_recorded_info.to_json
extra_info = alternative.extra_info
expect(extra_info).to eql(saved_recorded_info)
end
end