Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More errors

  • Loading branch information...
commit 4570409d5abbe49e4fe2bb7f58f03824ce8309e6 1 parent ed1e582
@bloudermilk authored
Showing with 11 additions and 10 deletions.
  1. +1 −1  lib/hood.rb
  2. +2 −2 lib/hood/dsl.rb
  3. +8 −7 spec/hood/dsl_spec.rb
View
2  lib/hood.rb
@@ -5,7 +5,7 @@ module Hood
class HoodError < StandardError ; end
class DslError < HoodError ; end
- class InvalidOption < DslError ; end
+ class InvalidOptionError < DslError ; end
class DuplicateVariableError < DslError ; end
class << self
View
4 lib/hood/dsl.rb
@@ -26,7 +26,7 @@ def env(name, opts={})
var = Variable.new(name, opts)
if exists? var.name
- message = "You tried to define the variable #{var.name} twice."
+ message = "You tried to define the variable '#{var.name}' twice."
raise DuplicateVariableError, message
end
@@ -74,7 +74,7 @@ def _normalize_options(name, opts)
else
message << "as an option for variable '#{name}', but it is invalid."
end
- raise InvalidOption, message
+ raise InvalidOptionError, message
end
# The :optional option should default to the builder's state
View
15 spec/hood/dsl_spec.rb
@@ -24,14 +24,15 @@
it "should add the variable to @variables on the builder" do
builder.variables.should be_empty
- builder.env "FOO"
+ builder.env("FOO")
builder.should have(1).variables
end
context "when a variable with the same name has already been added" do
- it "should raise an exception" do
- builder.env "FOO"
- lambda { builder.env "FOO" }.should raise_exception
+ it "should raise a DuplicateVariableError with a nicely formatted message" do
+ message = "You tried to define the variable 'FOO' twice."
+ builder.env("FOO")
+ lambda { builder.env("FOO") }.should raise_error(Hood::DuplicateVariableError, message)
end
end
@@ -106,20 +107,20 @@
context "when an unknown option is passed" do
it "should raise an InvalidOption error" do
- lambda { builder.env("FOO", :lol => true) }.should raise_exception(Hood::InvalidOption)
+ lambda { builder.env("FOO", :lol => true) }.should raise_error(Hood::InvalidOptionError)
end
context "when a single unknown option is passed" do
it "should format the string nicely" do
message = "You passed :lol as an option for variable 'FOO', but it is invalid."
- lambda { builder.env("FOO", :lol => true) }.should raise_exception(Hood::InvalidOption, message)
+ lambda { builder.env("FOO", :lol => true) }.should raise_error(Hood::InvalidOptionError, message)
end
end
context "when multiple unknown options are passed" do
it "should format the string nicely" do
message = "You passed :lol, :wtf as options for variable 'FOO', but they are invalid."
- lambda { builder.env("FOO", :lol => true, :wtf => false) }.should raise_exception(Hood::InvalidOption, message)
+ lambda { builder.env("FOO", :lol => true, :wtf => false) }.should raise_exception(Hood::InvalidOptionError, message)
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.