[rspec-users] be_valid (validates_format_of ..., :on => :create)

MAwiniarski MAwiniarski at gmail.com
Sat Feb 28 05:45:16 EST 2009


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

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

Thanks.


More information about the rspec-users mailing list