[rspec-users] Count error on lambda should change

Pat Maddox patmaddox at me.com
Sat Dec 18 06:21:17 EST 2010

Sounds like a validation failure. My guess is that you're re-using the factory-created record's attributes, and your example fails because of a uniqueness validation. This would explain the rollback if you're using the create! or save! method.


On Dec 13, 2010, at 3:08 PM, djangst <djangst at gmail.com> wrote:

> Hi, any idea what could cause the following error in a controller
> test?
>    "count should have been changed by 1, but was changed by 0"
> I'm posting to a create route using a lambda, similar to Hartl's
> example in his Rails tutorial:
> it "should create a user" do
> lambda do
>   post :create, :user => @attr
> end.should change(User, :count).by(1)
> end
> The only difference is I'm using a factory instead of an attribute
> hash. I know the action works because I can perform it manually and my
> model specs pass.
> More importantly, I can see the inserts (two rows, parent and child)
> in my Postgres logs. And I see a rollback before the count is
> selected. Could that be the cause? [I searched for a while and didn't
> see much discussion about this, so probably not.]
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list