On 28-feb-2009, at 11:45, MAwiniarski wrote:

Greetings,

How to write Example which will check if model's variable's
format is valid using :on => :create, like this:

class User < ActiveRecord::Base
...
 validates_format_of       :email, :with => /.../, :on => :create
...

Using following code is not right:
it "should ..." do
   @user = users(:example_user)
   @user.email = 'invalid_email_format'
   @user.save
   @user.should_not be_valid
end

Try:

it "should ..." do
user = User.new # create a NEW user, instead of loading an already saved user from a fixtures file
   user.email = 'invalid_email_format'
   user.should_not be_valid
   user.should have(1).errors_on(:email)
end

cheers,
bartz
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to