[rspec-users] before_save model callback rspec testing

David Chelimsky dchelimsky at gmail.com
Fri Jun 20 12:04:24 EDT 2008


On Jun 20, 2008, at 11:01 AM, Csongor Bartus wrote:
> I'm trying "your" way:
>
> u = User.create(:login => "test", :email => "test at test.com", :password
> => "test123", :password_confirmation => "test123")
> u.crypted_password.should_not be_nil
>
> the error message is:
> NoMethodError in 'User ActiveRecord Callbacks before save encrypts
> password'
> You have a nil object when you didn't expect it!
> You might have expected an instance of Array.
> The error occurred while evaluating nil.each
> ./spec/models/user_spec.rb:82:
>
> [line 82 ia User.create(...)
>
>
> and "my" way:
>
> @user = User.new
>        @user.login = "test"
>        @user.email = "test at test.com"
>        @user.password = "test123"
>        @user.password_confirmation = "test123"
>        @user.save
> @user.crypted_password.should_not be_nil
>
> the error message is:
> 'User Acts As Authenticated encrypts password' FAILED
> expected not nil, got nil

Try using create! or save! - I'll bet the record is not being saved  
correctly and you're not seeing the error.


More information about the rspec-users mailing list