私が原因RspecとFactoryGirlを使用してリストを作成しようとすると、検証に失敗しますか?
Secret#last_five returns the last 5 secrets when last_five is called
Failure/Error: let!(:secrets){create_list(:secret, 5)}
ActiveRecord::RecordInvalid:
Validation failed: Email has already been taken
エラーに失敗しているテストを持っていると私はそれを修正するかどうかはわからないと思います。ここで
はsecret_spec.rbでのテストである:ここで
describe Secret do
describe "#last_five" do
let!(:secrets){create_list(:secret, 5)}
it "returns the last 5 secrets when last_five is called" do
expect(Secret.last_five.count).to eq(5)
end
end
end
はsecret_factory.rbです:ここでは
FactoryGirl.define do
factory :secret do
title "Title"
body "this is the body"
author
end
end
はuser_factory.rbです:
FactoryGirl.define do
factory :user, aliases: [:author] do
name "Foobar"
email Faker::Internet.safe_email
password "password"
password_confirmation "password"
end
end
私はランダムな電子メールアドレスを生成し、ユーザファクトリは私がEメールを使用している唯一の場所なので、どのようにEを取得しているのか混乱しています既に取られたメール。
ありがとうございました。
投稿した内容からはっきりとわかりません。デバッグが必要です。テストデータベースを再構築して、違いがあるかどうかを確認します。問題を引き起こす秘密/ユーザーの最小数を探します。ユーザーに不具合のある電子メールとデータベース内の電子メールを印刷する手動検証を追加します。 –