Permalink
Browse files

finished method accept goals that are not passed as arrays

  • Loading branch information...
phoet committed Mar 19, 2013
1 parent 0ce952d commit cbd0354e5d6d130f5d0a49c312d38e0717a1eb71
Showing with 15 additions and 18 deletions.
  1. +1 −1 README.mdown
  2. +11 −14 lib/split/helper.rb
  3. +3 −3 spec/helper_spec.rb
View
@@ -396,7 +396,7 @@ end
To complete a goal conversion, you do it like:
```ruby
-finished("link_color" => ["purchase"])
+finished("link_color" => "purchase")
```
### DB failover solution
View
@@ -1,13 +1,13 @@
module Split
module Helper
- def ab_test(experiment_label, control=nil, *alternatives)
+ def ab_test(metric_descriptor, control=nil, *alternatives)
if RUBY_VERSION.match(/1\.8/) && alternatives.length.zero? && ! control.nil?
puts 'WARNING: You should always pass the control alternative through as the second argument with any other alternatives as the third because the order of the hash is not preserved in ruby 1.8'
end
begin
- experiment_name_with_version, goals = normalize_experiment(experiment_label)
+ experiment_name_with_version, goals = normalize_experiment(metric_descriptor)
experiment_name = experiment_name_with_version.to_s.split(':')[0]
experiment = Split::Experiment.new(experiment_name, :alternatives => [control].compact + alternatives, :goals => goals)
control ||= experiment.control && experiment.control.name
@@ -67,10 +67,10 @@ def finish_experiment(experiment, options = {:reset => true})
end
- def finished(metric_name, options = {:reset => true})
+ def finished(metric_descriptor, options = {:reset => true})
return if exclude_visitor? || Split.configuration.disabled?
- metric_name, goals = normalize_experiment(metric_name)
- experiments = Metric.possible_experiments(metric_name)
+ metric_descriptor, goals = normalize_experiment(metric_descriptor)
+ experiments = Metric.possible_experiments(metric_descriptor)
if experiments.any?
experiments.each do |experiment|
@@ -141,12 +141,13 @@ def is_ignored_ip_address?
end
protected
- def normalize_experiment(experiment_label)
- if Hash === experiment_label
- experiment_name = experiment_label.keys.first
- goals = experiment_label.values.first
+
+ def normalize_experiment(metric_descriptor)
+ if Hash === metric_descriptor
+ experiment_name = metric_descriptor.keys.first
+ goals = Array(metric_descriptor.values.first)
else
- experiment_name = experiment_label
+ experiment_name = metric_descriptor
goals = []
end
return experiment_name, goals
@@ -156,10 +157,6 @@ def control_variable(control)
Hash === control ? control.keys.first : control
end
- def load_and_start_trial(experiment_label, control, alternatives)
- experiment_name, goals = normalize_experiment(experiment_label)
- end
-
def start_trial(trial)
experiment = trial.experiment
if override_present?(experiment.name)
View
@@ -27,8 +27,8 @@
lambda { ab_test({'link_color' => ["purchase", "refund"]}, 'blue', 'red') }.should_not raise_error
end
- it "should raise the appropriate error when passed string for goals" do
- lambda { ab_test({'link_color' => "purchase"}, 'blue', 'red') }.should raise_error(ArgumentError)
+ it "should not raise error when passed just one goal" do
+ lambda { ab_test({'link_color' => "purchase"}, 'blue', 'red') }.should_not raise_error
end
it "should assign a random alternative to a new user when there are an equal number of alternatives assigned" do
@@ -852,7 +852,7 @@ def should_finish_experiment(experiment_name, should_finish=true)
it "should increment the counter for the specified-goal completed alternative" do
@previous_completion_count_for_goal1 = Split::Alternative.new(@alternative_name, @experiment_name).completed_count(@goal1)
@previous_completion_count_for_goal2 = Split::Alternative.new(@alternative_name, @experiment_name).completed_count(@goal2)
- finished({"link_color" => ["purchase"]})
+ finished({"link_color" => "purchase"})
new_completion_count_for_goal1 = Split::Alternative.new(@alternative_name, @experiment_name).completed_count(@goal1)
new_completion_count_for_goal1.should eql(@previous_completion_count_for_goal1 + 1)
new_completion_count_for_goal2 = Split::Alternative.new(@alternative_name, @experiment_name).completed_count(@goal2)

0 comments on commit cbd0354

Please sign in to comment.