On Tue, Feb 16, 2010 at 5:42 PM, patrick99e99 <patrick99...@gmail.com> wrote: > I am new to BDD, so am not quite sure how I am supposed to write a > test like this.. I get: > "ActiveRecord::RecordInvalid in 'User should fail when passwords do > not match' > Validation failed: Password doesn't match confirmation" > > If anyone can guide me in the right direction, I'd appreciate it.. > > -patrick > > require 'spec_helper' > > describe User do > > before(:each) do > @valid_attributes = { > :login => 'test_name', > :password => 'password', > :password_confirmation => 'password' > } > > �...@invalid_attributes = @valid_attributes.merge(:password => > 'not_the_same_password') > end > > it "should create a valid user" do > User.create!(@valid_attributes).should be_true > end > > it "should fail when passwords do not match" do > User.create!(@invalid_attributes).should be_false > end
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! or expect do User.create!(@invalid_attributes) end.to raise_exception(ActiveRecord::RecordInvalid) HTH, David > > end > > > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users