[rspec-users] Trying to write a failing test-- but am failing!

patrick99e99 patrick99e99 at gmail.com
Tue Feb 16 21:15:40 EST 2010


> The create! method is designed to raise an error if validation fails.
> You can get this to work in one of two ways:
> User.create(@invalid_attributes).should be_false # using create
> instead of create!

Hmm, when I try that-- It still doesn't work...

  it "should fail when passwords do not match" do
    User.create(@invalid_attributes).should be_false

'User should fail when passwords do not match' FAILED
expected #<User id: nil, login: "test_name", crypted_password:
password_salt: "UITwJqOSRNzvajFmKpxL", persistence_token:
single_access_token: "ZISHX20gtD4gCowZ2NLo", perishable_token: nil,
login_count: 0, failed_login_count: 0, last_request_at: nil,
current_login_at: nil, last_login_at: nil, current_login_ip: nil,
last_login_ip: nil, contact_id: nil, access_level_id: nil, active:
false, created_at: nil, updated_at: nil> to be false

> expect do
>   User.create!(@invalid_attributes)
> end.to raise_exception(ActiveRecord::RecordInvalid)

And when I tried that way, I got the same error I was getting

  it "should fail when passwords do not match" do
    end.to raise_exception(ActiveRecord::RecordInvalid)

ActiveRecord::RecordInvalid in 'User should create a valid user'
Validation failed: Password doesn't match confirmation


More information about the rspec-users mailing list