What is the RSpec way to handle database exceptions. I have a DB
constraint of unique names and have the following spec:

  it "should have unique names" do
    target1 = Target.new
    target1.name = "ssv"
    target1.save
    target1.created.should be_a(Time)
    target2 = Target.new
    target2.name = "ssv"
    target2.save.should raise_error(Sequel::DatabaseError)
  end

This fails with the following:
     Failure/Error: target2.save.should
raise_error(Sequel::DatabaseError)
     Sequel::DatabaseError:
       SQLite3::ConstraintException: column name is not unique
     # ./spec/models/target_spec.rb:16:in `block (2 levels) in <top
(required)>'

I can't seem to catch this in RSpec.

Jason

On Jan 12, 12:22 pm, John Firebaugh <[email protected]> wrote:
> On Wed, Jan 12, 2011 at 11:14 AM, Jason Thomas
> <[email protected]>wrote:
>
>
>
> > RSpec.configure do |config|
> >  config.around(:each) do |example|
> >    Sequel::DATABASES.first.transaction do
> >      example.run
> >      raise Sequel::Error::Rollback
> >    end
> >  end
> >  # other configuration ...
> > end
>
> Yes, this is what I do.

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to