[rspec-users] rspec causing validates_presence_of to validate twice?

Steve vertebrate at gmail.com
Wed Oct 17 21:34:57 EDT 2007

On Wed, 17 Oct 2007 19:30:57 -0500, David Chelimsky wrote:

>> Removing --reverse makes "rake spec" fail like the other two methods
>> now.
> That's what I suspected would happen.
> The reason they were failing differently was that rake was running them
> in the opposite order. Removing --reverse made it so they run in the
> same order.
> So now, the problem is that your specs are leaking state. I'd need to
> see the entire file to help you figure out why. If you feel like posting
> it, please pastie it and write back.

I take that back, "rake spec" causes similar failure, in that those double
validation messages appear, but it also adds two failures that weren't
there before.

'User should have a case-insensitive unique username' FAILED expected
valid? to return false, got true ./spec/helpers/../spec_helper.rb:49:in
`check_unique' ./spec/models/user_spec.rb:101:in `check_user_unique'

'User should have a case-insensitive unique email address' FAILED expected
valid? to return false, got true ./spec/helpers/../spec_helper.rb:49:in
`check_unique' ./spec/models/user_spec.rb:101:in `check_user_unique'

If I run "script/spec spec" those don't appear, and I just have the double
validation message errors.

Also I really don't think I'm leaking state. I have before(:each) statements in my "describes" that
basically create new instances of the object as required for that
behavior. So they are fresh each time, correct? Further, even though rails
clears the errors collection when valid? is called, I called
@user.errors.clear before attempting the validations that are failing with
the double message just to be sure, and it's still happening. Again, these
problems don't happen in script/console at all, but it is validating

More information about the rspec-users mailing list