Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 0 additions & 14 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,6 @@ Style/DefWithParentheses:
Exclude:
- 'lib/split/helper.rb'

# Offense count: 23
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax:
Exclude:
- 'Rakefile'
- 'lib/split/experiment.rb'
- 'lib/split/experiment_catalog.rb'
- 'lib/split/helper.rb'
- 'lib/split/metric.rb'
- 'lib/split/persistence.rb'
- 'lib/split/persistence/redis_adapter.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new('spec')

task :default => :spec
task default: :spec
2 changes: 1 addition & 1 deletion lib/split/algorithms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ def beta_distribution_rng(a, b)
end
end
end
end
end
1 change: 0 additions & 1 deletion lib/split/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module Split
class Cache

def self.clear
@cache = nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/split/experiment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Experiment
attr_reader :resettable

DEFAULT_OPTIONS = {
:resettable => true
resettable: true
}

def self.find(name)
Expand Down
3 changes: 2 additions & 1 deletion lib/split/experiment_catalog.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Split
class ExperimentCatalog
# Return all experiments
Expand Down Expand Up @@ -26,7 +27,7 @@ def self.find_or_initialize(metric_descriptor, control = nil, *alternatives)
experiment_name_with_version, goals = normalize_experiment(metric_descriptor)
experiment_name = experiment_name_with_version.to_s.split(':')[0]
Split::Experiment.new(experiment_name,
:alternatives => [control].compact + alternatives, :goals => goals)
alternatives: [control].compact + alternatives, goals: goals)
end

def self.find_or_create(metric_descriptor, control = nil, *alternatives)
Expand Down
20 changes: 10 additions & 10 deletions lib/split/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def ab_test(metric_descriptor, control = nil, *alternatives)
alternative = if Split.configuration.enabled && !exclude_visitor?
experiment.save
raise(Split::InvalidExperimentsFormatError) unless (Split.configuration.experiments || {}).fetch(experiment.name.to_sym, {})[:combined_experiments].nil?
trial = Trial.new(:user => ab_user, :experiment => experiment,
:override => override_alternative(experiment.name), :exclude => exclude_visitor?,
:disabled => split_generically_disabled?)
trial = Trial.new(user: ab_user, experiment: experiment,
override: override_alternative(experiment.name), exclude: exclude_visitor?,
disabled: split_generically_disabled?)
alt = trial.choose!(self)
alt ? alt.name : nil
else
Expand Down Expand Up @@ -44,7 +44,7 @@ def reset!(experiment)
ab_user.delete(experiment.key)
end

def finish_experiment(experiment, options = {:reset => true})
def finish_experiment(experiment, options = {reset: true})
return false if active_experiments[experiment.name].nil?
return true if experiment.has_winner?
should_reset = experiment.resettable? && options[:reset]
Expand All @@ -53,10 +53,10 @@ def finish_experiment(experiment, options = {:reset => true})
else
alternative_name = ab_user[experiment.key]
trial = Trial.new(
:user => ab_user,
:experiment => experiment,
:alternative => alternative_name,
:goals => options[:goals],
user: ab_user,
experiment: experiment,
alternative: alternative_name,
goals: options[:goals],
)

trial.complete!(self)
Expand All @@ -69,15 +69,15 @@ def finish_experiment(experiment, options = {:reset => true})
end
end

def ab_finished(metric_descriptor, options = {:reset => true})
def ab_finished(metric_descriptor, options = {reset: true})
return if exclude_visitor? || Split.configuration.disabled?
metric_descriptor, goals = normalize_metric(metric_descriptor)
experiments = Metric.possible_experiments(metric_descriptor)

if experiments.any?
experiments.each do |experiment|
next if override_present?(experiment.key)
finish_experiment(experiment, options.merge(:goals => goals))
finish_experiment(experiment, options.merge(goals: goals))
end
end
rescue => e
Expand Down
4 changes: 2 additions & 2 deletions lib/split/metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def self.load_from_redis(name)
Split::ExperimentCatalog.find(experiment_name)
end

Split::Metric.new(:name => name, :experiments => experiments)
Split::Metric.new(name: name, experiments: experiments)
else
nil
end
Expand All @@ -31,7 +31,7 @@ def self.load_from_redis(name)
def self.load_from_configuration(name)
metrics = Split.configuration.metrics
if metrics && metrics[name]
Split::Metric.new(:experiments => metrics[name], :name => name)
Split::Metric.new(experiments: metrics[name], name: name)
else
nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/split/persistence/redis_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Split
module Persistence
class RedisAdapter
DEFAULT_CONFIG = {:namespace => 'persistence'}.freeze
DEFAULT_CONFIG = {namespace: 'persistence'}.freeze

attr_reader :redis_key

Expand Down
28 changes: 14 additions & 14 deletions spec/alternative_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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.weight).to eq(0.6)
Expand All @@ -41,11 +41,11 @@

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 },
]
}
}
Expand All @@ -61,11 +61,11 @@

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",
],
}
Expand All @@ -87,11 +87,11 @@
#
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 },
],
}
}
Expand Down
8 changes: 4 additions & 4 deletions spec/combined_experiments_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

before do
Split.configuration.experiments = {
:combined_exp_1 => {
:alternatives => [ {"control"=> 0.5}, {"test-alt"=> 0.5} ],
:metric => :my_metric,
:combined_experiments => combined_experiments
combined_exp_1: {
alternatives: [ {"control"=> 0.5}, {"test-alt"=> 0.5} ],
metric: :my_metric,
combined_experiments: combined_experiments
}
}
Split.configuration.enabled = config_enabled
Expand Down
28 changes: 13 additions & 15 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,15 @@
end

it "should load a metric" do
@config.experiments = {:my_experiment=>
{:alternatives=>["control_opt", "other_opt"], :metric=>:my_metric}}
@config.experiments = { my_experiment: {alternatives: ["control_opt", "other_opt"], metric: :my_metric } }

expect(@config.metrics).not_to be_nil
expect(@config.metrics.keys).to eq([:my_metric])
end

it "should allow loading of experiment using experment_for" do
@config.experiments = {:my_experiment=>
{:alternatives=>["control_opt", "other_opt"], :metric=>:my_metric}}
expect(@config.experiment_for(:my_experiment)).to eq({:alternatives=>["control_opt", ["other_opt"]]})
@config.experiments = { my_experiment: { alternatives: ["control_opt", "other_opt"], metric: :my_metric } }
expect(@config.experiment_for(:my_experiment)).to eq({ alternatives: ["control_opt", ["other_opt"]] })
end

context "when experiments are defined via YAML" do
Expand All @@ -87,7 +85,7 @@
end

it 'should normalize experiments' do
expect(@config.normalized_experiments).to eq({:my_experiment=>{:resettable=>false,:alternatives=>["Control Opt", ["Alt One", "Alt Two"]]}})
expect(@config.normalized_experiments).to eq({ my_experiment: { resettable: false, alternatives: ["Control Opt", ["Alt One", "Alt Two"]] } })
end
end

Expand Down Expand Up @@ -143,8 +141,8 @@
end

it "should normalize experiments" do
expect(@config.normalized_experiments).to eq({:my_experiment=>{:resettable=>false,:alternatives=>[{"Control Opt"=>0.67},
[{"Alt One"=>0.1}, {"Alt Two"=>0.23}]]}, :another_experiment=>{:alternatives=>["a", ["b"]]}})
expect(@config.normalized_experiments).to eq({ my_experiment: { resettable: false, alternatives: [{"Control Opt"=>0.67},
[{"Alt One"=>0.1}, {"Alt Two"=>0.23}]]}, another_experiment: { alternatives: ["a", ["b"]]}})
end

it "should recognize metrics" do
Expand All @@ -171,7 +169,7 @@
end

it "should normalize experiments" do
expect(@config.normalized_experiments).to eq({:my_experiment=>{:resettable=>false,:alternatives=>["Control Opt", ["Alt One", "Alt Two"]]}})
expect(@config.normalized_experiments).to eq({my_experiment: { resettable: false, alternatives: ["Control Opt", ["Alt One", "Alt Two"]]}})
end
end

Expand Down Expand Up @@ -200,16 +198,16 @@

it "should normalize experiments" do
@config.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 },
],
}
}

expect(@config.normalized_experiments).to eq({:my_experiment=>{:alternatives=>[{"control_opt"=>0.67}, [{"second_opt"=>0.1}, {"third_opt"=>0.23}]]}})
expect(@config.normalized_experiments).to eq({ my_experiment: { alternatives: [{"control_opt"=>0.67}, [{"second_opt"=>0.1}, {"third_opt"=>0.23}]]}})
end

context "redis configuration" do
Expand Down
2 changes: 1 addition & 1 deletion spec/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def link(color)

it "should mark an alternative as the winner" do
expect(experiment.winner).to be_nil
post "/experiment?experiment=#{experiment.name}", :alternative => 'red'
post "/experiment?experiment=#{experiment.name}", alternative: 'red'

expect(last_response).to be_redirect
expect(experiment.winner.name).to eq('red')
Expand Down
Loading