LoginSignup
0
0

More than 3 years have passed since last update.

テストコード(単体テスト)エラー

Posted at

テストコードのコマンドを入力すると、今まで見た事のないエラー文が。

ActiveRecord::StatementInvalid:
Mysql2::Error::ConnectionError: Lost connection to MySQL server during query

上記をコピペしてググることに。いっぱい出てきました。

何やらテストコードを精製してるspec.rbに以下の一文を加えたら良いらしい。

before do
@user = FactoryBot.create(:user)
@item = FactoryBot.create(:item)
@order_address = FactoryBot.build(:order_address,user_id: @user.id, item_id: @item.id)
sleep 0.1      ⬅️こちらです!
end

上記は生成するのに0.1秒待機させて処理する仕組みのようです。

結果、全て通るようになりました!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0