Skip to content

Commit

Permalink
Add some additional exception specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyevans committed Sep 10, 2009
1 parent d180406 commit 2654ea3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion spec/core/database_spec.rb
Expand Up @@ -1251,6 +1251,7 @@ def ds.get(*args, &block)
before do
@db = Sequel::Database.new
end

specify "should raise an InvalidValue when given an invalid value" do
proc{@db.typecast_value(:integer, "13a")}.should raise_error(Sequel::InvalidValue)
proc{@db.typecast_value(:float, "4.e2")}.should raise_error(Sequel::InvalidValue)
Expand All @@ -1260,6 +1261,24 @@ def ds.get(*args, &block)
proc{@db.typecast_value(:time, Date.new)}.should raise_error(Sequel::InvalidValue)
proc{@db.typecast_value(:datetime, 4)}.should raise_error(Sequel::InvalidValue)
end

specify "should have an underlying exception class available at wrapped_exception" do
begin
@db.typecast_value(:date, 'a')
true.should == false
rescue Sequel::InvalidValue => e
e.wrapped_exception.should be_a_kind_of(ArgumentError)
end
end

specify "should include underlying exception class in #inspect" do
begin
@db.typecast_value(:date, 'a')
true.should == false
rescue Sequel::InvalidValue => e
e.inspect.should =~ /\A#<Sequel::InvalidValue: ArgumentError: .*>\z/
end
end
end

context "Database#blank_object?" do
Expand Down Expand Up @@ -1391,4 +1410,4 @@ def ds.get(*args, &block)
p["((12.1))", :float].should == 12.1
p["((-12.1))", :decimal].should == BigDecimal.new('-12.1')
end
end
end

0 comments on commit 2654ea3

Please sign in to comment.