Skip to content

Commit

Permalink
Add NoExperimentError to replace NameError on missing experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Barnwell authored and dougcole committed Mar 1, 2012
1 parent 96a03c6 commit 1a11b7f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/vanity/experiment/base.rb
Expand Up @@ -211,4 +211,8 @@ def connection

end
end

class NoExperimentError < NameError
end

end
3 changes: 2 additions & 1 deletion lib/vanity/playground.rb
Expand Up @@ -95,10 +95,11 @@ def define(name, type, options = {}, &block)
# an exception if it cannot load the experiment's definition.
#
# @see Vanity::Experiment

def experiment(name)
id = name.to_s.downcase.gsub(/\W/, "_").to_sym
warn "Deprecated: pleae call experiment method with experiment identifier (a Ruby symbol)" unless id == name
experiments[id.to_sym] or raise NameError, "No experiment #{id}"
experiments[id.to_sym] or raise NoExperimentError, "No experiment #{id}"
end


Expand Down
2 changes: 1 addition & 1 deletion test/experiment/ab_test.rb
Expand Up @@ -234,7 +234,7 @@ def test_destroy_experiment
# -- A/B helper methods --

def test_fail_if_no_experiment
assert_raise NameError do
assert_raise Vanity::NoExperimentError do
get :test_render
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/experiment/base_test.rb
Expand Up @@ -34,7 +34,7 @@ def test_fail_when_defining_same_experiment_twice
# -- Loading experiments --

def test_fails_if_cannot_load_named_experiment
assert_raises NameError do
assert_raises Vanity::NoExperimentError do
experiment(:ice_cream_flavor)
end
end
Expand Down

0 comments on commit 1a11b7f

Please sign in to comment.