On May 20, 2008, at 6:59 PM, T K wrote:

Hi,

I have a spec

it "should have a unique username "

I have a code:

 validates_uniqueness_of :user_name


Now, I don't know how to test this code. In order to test this, do I
need to run `save`?

For example,

@user = User.create(:username => "mike")
@another = User.create(:username => "mike")
@another.save.should be_false

This messes up test database. Is there any better way?

Are you running with transactional_fixtures = true? If not, I'd strongly recommend that you do. Even if you're not using fixtures, that setting causes all of your examples to be run in transactions that get rolled back after each example. That way, your examples can make db changes, expect the right thing, and then the db is restored to its previous state.

HTH,
David



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

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

Reply via email to