Multiple should sentences one lambda

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.

On Sun, Mar 23, 2008 at 8:57 AM, roberto belardo [email protected]
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