Forum: RSpec Multiple should sentences one lambda

924b7e74bbcb751cded935cd9097782f?d=identicon&s=25 roberto belardo (Guest)
on 2008-03-23 14:58
(Received via mailing list)
Hi all,
i have one problem. I'm just trying to get the
restful_authentication plugin work, but i discovered
that its rspec tests are not working, because of this:

it 'requires password confirmation' do
  lambda do
    u = Factory.create_user(:password_confirmation =>
nil)
    u.errors.on(:password_confirmation).should_not
be_nil
  end.should_not change(User, :count)
end

where in the user model i have a simple:

validates_presence_of     :password_confirmation

Autotest continues to tell me that:

ActiveRecord::RecordInvalid in 'User requires password
confirmation'
Validation failed: Password confirmation can't be
blank

The question is: how can i test both the presence of
error and the change on count?

Thanks in advance,
Roberto.


      Inviato da Yahoo! Mail.
Tanti modi per restare in contatto con chi vuoi.
http://it.docs.yahoo.com/mail/overview/index.html
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2008-03-23 16:43
(Received via mailing list)
On Sun, Mar 23, 2008 at 8:57 AM, roberto belardo <backslash451@yahoo.it>
wrote:
>  be_nil
>  confirmation'
>  Validation failed: Password confirmation can't be
>  blank
>
>  The question is: how can i test both the presence of
>  error and the change on count?

These are two different behaviours and should, IMO, have two separate
examples:

    it 'does not save a user with nil password_confirmation' do
     lambda do
       Factory.create_user(:password_confirmation => nil)
     end.should_not change(User, :count)
    end

    it 'reports an error for nil password_confirmation' do
       u = Factory.create_user(:password_confirmation => nil)
       u.should have(1).error_on(:password_confirmation)
    end
  end

HTH,
David
This topic is locked and can not be replied to.