diff --git a/lib/split/experiment.rb b/lib/split/experiment.rb index d166c2c7..447cde18 100644 --- a/lib/split/experiment.rb +++ b/lib/split/experiment.rb @@ -157,6 +157,7 @@ def self.load_alternatives_for(name) def self.load_alternatives_from_configuration_for(name) alts = Split.configuration.experiment_for(name)[:variants] + raise ArgumentError, "Experiment configuration is missing :variants array" if alts.nil? if alts.is_a?(Hash) alts.keys else diff --git a/spec/helper_spec.rb b/spec/helper_spec.rb index 8c0d8165..8093dc1e 100755 --- a/spec/helper_spec.rb +++ b/spec/helper_spec.rb @@ -649,6 +649,21 @@ def should_finish_experiment(experiment_name, should_finish=true) names_and_weights.should == [['control_opt', 0.18], ['second_opt', 0.18], ['third_opt', 0.64]] names_and_weights.inject(0){|sum, nw| sum + nw[1]}.should == 1.0 end + + it "fails gracefully if config is missing experiment" do + Split.configuration.experiments = { :other_experiment => { :foo => "Bar" } } + lambda { ab_test :my_experiment }.should raise_error(/not found/i) + end + + it "fails gracefully if config is missing" do + Split.configuration.experiments = nil + lambda { ab_test :my_experiment }.should raise_error(/not found/i) + end + + it "fails gracefully if config is missing variants" do + Split.configuration.experiments[:my_experiment] = { :foo => "Bar" } + lambda { ab_test :my_experiment }.should raise_error(/variants/i) + end end it 'should handle multiple experiments correctly' do