I've very green to this TDD business, so any help would be fantastic!
So, I've got a factory with the following:
FactoryGirl.define do
factory :account do
email "[email protected]"
url "teststore"
end
end
And an Rspec test with:
it "fails validation without unique email" do
account1 = FactoryGirl.create(:account)
account2 = FactoryGirl.create(:account)
account2.should have(1).error_on(:email)
end
I get a failure with the following message:
1) Account fails validation without unique email
Failure/Error: account2 = FactoryGirl.create(:account)
ActiveRecord::RecordInvalid:
Validation failed: Email taken, please choose another, Url taken, please choose another
# ./spec/models/account_spec.rb:11:in `block (2 levels) in <top (required)>'
Is this the correct way to create new factories? Any ideas what I'm doing wrong here (I have no doubt I'm doing something totally incorrect!)
EDIT: I'm thinking of instead of using 'create' on the second account, I may want to use .build and then .save instead?