And I just figured out that I should've written my spec like this:
lambda { @client = Client.create( :name => "The Glue
Factory" ) }.should raise_error(DataMapper::SaveFailureError)
Still, an explanation for the behavior for my own edification would be
appreciated.
Thanks.
On Dec 28, 1:33 am, Neil Chaudhuri <[email protected]> wrote:
> I have an RSpec test of my model as follows:
>
> describe Client do
> before(:all) do
> @client = Client.create( :name => "The Glue Factory", :phone =>
> "(555) 555-5555" )
> end
>
> it "should not save a new client with the same name" do
> begin
> @client = Client.create( :name => "The Glue Factory" )
> rescue DataMapper::SaveFailureError
> @client.should_not be_saved
> end
> end
> end
>
> Client is an entity with :name set to :unique, and I have configured
> DataMapper to raise DataMapper::SaveFailureError rather than return
> false on failure. Hence, my attempt to call create with a duplicate
> name should fail. And it does!
>
> But I am also finding that my test fails because #saved on the @client
> instance is returning true. That is weird to me.
>
> Am I missing something here? Any insight is appreciated.
>
> Thanks.
--
You received this message because you are subscribed to the Google Groups
"DataMapper" 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/datamapper?hl=en.