wassupdee / RUNTEQ_portfolio

0 stars 0 forks source link

RSpec モデルテスト(CIエラー解消) #309

Open wassupdee opened 6 days ago

wassupdee commented 6 days ago

結論

RSpecモデルテストを実行すると、

ActiveRecord::StatementInvalid:
       Mysql2::Error: This connection is in use by: #<Fiber:0x00007f735820dbe0 (resumed)>

というエラーになり、詰まっております。

実装の目的

モデルテストを実行するため。

手順

私の行った手順は以下です。 (1)rspec-rails,factory_bot_rails Gemを開発とテスト環境にインストール (2)spec/modelsディレクトリ内にモデルテストのコードを記述 (3)dc exec web bundle exec rspec spec/modelsでローカルでモデルテストを実行

実行環境・ソースコード

期待した結果

RSpecモデルテストが実行される。

実際の結果

実際は、以下のような結果になりました。

[エラーメッセージ]

$ dc exec web bundle exec rspec spec/models

Album
  アソシエーションチェック
    profileとのアソシエーション
      profileと1対多の関係にある
  バリデーションチェック
    無効なデータの場合
      無効なファイル形式はアップロードできない
      5MB以上のファイルはアップロードできない
      画像は4枚以上アップロードできない
    有効なデータの場合
      正常に画像が保存される

Answer
  アソシエーションチェック
    questionとのアソシエーション
      questionと1対多の関係にある
  バリデーションチェック
    valueがユニークであれば登録できる
    valueが重複するとエラーが起きる
  ロジックチェック
    セッションに各問の回答を保存する
    パラメーターから現在の質問番号を取得する
    現在の質問が最後か確認する

Authentication
  アソシエーションチェック
    userとのアソシエーション
      userと1対多の関係にある

Event
  アソシエーションチェック
    profileとのアソシエーション
      profileと1対多の関係にある
  ロジックチェック
    通知の条件を満たしているか確認する
    日付をUTCからJSTへ変換する(9時間先に進める)
    特定の日付の「年」を今年に変更する
    通知日は今日か確認する
  バリデーションチェック
    1profileあたりの登録できるイベント数を2つまでに制限する
  enumチェック
    boolean型のnotification_enabledが、off/onに対応している

Profile
  アソシエーションチェック
    userとのアソシエーション
      userと1対多の関係にある
    albumsとのアソシエーション
      albumsと1対多の関係にある
      関連するalbumsがあっても、profileを削除でき、albumsも削除される
    eventsとのアソシエーション
      eventsと1対多の関係にある
      関連するeventsがあっても、profileを削除でき、eventsも削除される
  accepts_nested_attributes_for
    profileモデルが更新される際、ネストされたeventsの属性も保存する
  ロジックチェック
    誕生日のチェック
      誕生日の月が今月か判定する(同月の場合)
      誕生日の月が今月か判定する(違う月の場合)
    大切な日のチェック
      大切な日の月が今月か判定する(同月の場合)
      大切な日の月が今月か判定する(同月の場合)
    ransack
      検索のための属性を定義する
  enumチェック
    last_contactedにenumが付いている
  バリデーションチェック
    無効なデータの場合
      無効なファイル形式はアップロードできない
      1MB以上のファイルはアップロードできない
    有効なデータの場合
      正常に画像が保存される

Question
  アソシエーションチェック
    answersと1対多の関係にある (FAILED - 1)
    関連するanswersがあっても、questionを削除でき、answersも削除される

User
  バリデーション
    名前、メール、パスワード、確認用パスワード、notification_enabledがある場合、有効である
    名前がない場合、無効である
    名前が255文字以上場合、無効である
    メールアドレスがない場合、無効である
    重複したメールアドレスの場合、無効である
    パスワードが2文字以下の場合、無効である
    パスワード(確認用)がない場合、無効である
    パスワード(確認用)がパスワードと一致しない場合、無効である
    notificaiton_enabledない場合、無効である
    line_user_idがblankの場合、重複していても有効である
    notification_enabledがenumで定義されている
  アソシエーションチェック
    profilesとのアソシエーション
      profilesと1対多の関係にある
      関連するprofilesがあっても、userを削除でき、profilesも削除される
    groupsとのアソシエーション
      groupsと1対多の関係にある
      関連するgroupsがあっても、userを削除でき、groupsも削除される
    authenticationsとのアソシエーション
      authenticationsと1対多の関係にある
      関連するauthenticationsがあっても、userを削除でき、authenticationsも削除される
    eventsとのアソシエーション
      eventsと1対多の関係にある
      関連するeventsがあっても、userを削除でき、eventsも削除される
  accepts_nested_attributes_for
    userモデルが更新される際、ネストされたauthenticationsの属性も保存する
  メソッドのテスト
    LINE通知の対象ユーザーを取得する

Failures:

  1) Question アソシエーションチェック answersと1対多の関係にある
     Failure/Error: _query(sql, @query_options.merge(options))

     ActiveRecord::StatementInvalid:
       Mysql2::Error: This connection is in use by: #<Fiber:0x00007f735820dbe0 (resumed)>
     # /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:151:in `_query'
     # /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:151:in `block in query'
     # /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:150:in `handle_interrupt'
     # /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:150:in `query'
     # ------------------
     # --- Caused by: ---
     # Mysql2::Error:
     #   This connection is in use by: #<Fiber:0x00007f735820dbe0 (resumed)>
     #   /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:151:in `_query'

Finished in 3.24 seconds (files took 3.78 seconds to load)
57 examples, 1 failure

Failed examples:

rspec ./spec/models/question_spec.rb:6 # Question アソシエーションチェック answersと1対多の関係にある

なお、question_spec.rb は下記の通りに実装しています。

require "rails_helper"

RSpec.describe Question, type: :model do
  let(:question) { create(:question) }
  describe "アソシエーションチェック" do
    it "answersと1対多の関係にある" do
      answer1 = create(:answer, question:)
      answer2 = create(:answer, question:)

      expect(question.answers).to include(answer1, answer2)
    end

    it "関連するanswersがあっても、questionを削除でき、answersも削除される" do
      answer1 = create(:answer, question:)
      answer2 = create(:answer, question:)

      expect { question.destroy }.to change { Question.count }.by(-1)
      expect(Answer.where(id: [answer1.id, answer2.id])).to be_empty
    end
  end
end

考えられる原因(仮説)

考えられる原因は

原因(仮説)の理由

This connection is in use by : #<Fiber:0x00007f735820dbe0 (resumed)>というエラーメッセージより、接続が他のタスクと被ってしまっていると判断しました

試したこと

以下を試しました。 (1)config/database.yml ファイルの、pool数を、5 --> 100へ変更

# MySQL. Versions 5.5.8 and up are supported.
#
# Install the MySQL driver
#   gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
#   gem "mysql2"
#
# And be sure to use new-style password hashing:
#   https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
#
default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 100 } %>
  username: root
  password: password
  host: db

development:
  <<: *default
  database: myapp_development

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: myapp_test

# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password or a full connection URL as an environment
# variable when you boot the app. For example:
#
#   DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable, Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively, you can specify a connection
# URL environment variable explicitly:
#
#   production:
#     url: <%= ENV["MY_APP_DATABASE_URL"] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
#
production:
  <<: *default
  database: myapp_production
  username: myapp
  password: <%= ENV["MYAPP_DATABASE_PASSWORD"] %>

(2)RSpecテストで並列処理が行われるように設定されていないか確認

試したことの結果

試した結果このようになりました。 (1)同様のエラーが発生しました (2)-1. parallel_tests Gemがインストールされていないか確認 → されていませんでした。 Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    actioncable (7.1.3.4)
      actionpack (= 7.1.3.4)
      activesupport (= 7.1.3.4)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
      zeitwerk (~> 2.6)
    actionmailbox (7.1.3.4)
      actionpack (= 7.1.3.4)
      activejob (= 7.1.3.4)
      activerecord (= 7.1.3.4)
      activestorage (= 7.1.3.4)
      activesupport (= 7.1.3.4)
      mail (>= 2.7.1)
      net-imap
      net-pop
      net-smtp
    actionmailer (7.1.3.4)
      actionpack (= 7.1.3.4)
      actionview (= 7.1.3.4)
      activejob (= 7.1.3.4)
      activesupport (= 7.1.3.4)
      mail (~> 2.5, >= 2.5.4)
      net-imap
      net-pop
      net-smtp
      rails-dom-testing (~> 2.2)
    actionpack (7.1.3.4)
      actionview (= 7.1.3.4)
      activesupport (= 7.1.3.4)
      nokogiri (>= 1.8.5)
      racc
      rack (>= 2.2.4)
      rack-session (>= 1.0.1)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.2)
      rails-html-sanitizer (~> 1.6)
    actiontext (7.1.3.4)
      actionpack (= 7.1.3.4)
      activerecord (= 7.1.3.4)
      activestorage (= 7.1.3.4)
      activesupport (= 7.1.3.4)
      globalid (>= 0.6.0)
      nokogiri (>= 1.8.5)
    actionview (7.1.3.4)
      activesupport (= 7.1.3.4)
      builder (~> 3.1)
      erubi (~> 1.11)
      rails-dom-testing (~> 2.2)
      rails-html-sanitizer (~> 1.6)
    active_storage_validations (1.1.4)
      activejob (>= 5.2.0)
      activemodel (>= 5.2.0)
      activestorage (>= 5.2.0)
      activesupport (>= 5.2.0)
    activejob (7.1.3.4)
      activesupport (= 7.1.3.4)
      globalid (>= 0.3.6)
    activemodel (7.1.3.4)
      activesupport (= 7.1.3.4)
    activerecord (7.1.3.4)
      activemodel (= 7.1.3.4)
      activesupport (= 7.1.3.4)
      timeout (>= 0.4.0)
    activestorage (7.1.3.4)
      actionpack (= 7.1.3.4)
      activejob (= 7.1.3.4)
      activerecord (= 7.1.3.4)
      activesupport (= 7.1.3.4)
      marcel (~> 1.0)
    activesupport (7.1.3.4)
      base64
      bigdecimal
      concurrent-ruby (~> 1.0, >= 1.0.2)
      connection_pool (>= 2.2.5)
      drb
      i18n (>= 1.6, < 2)
      minitest (>= 5.1)
      mutex_m
      tzinfo (~> 2.0)
    addressable (2.8.7)
      public_suffix (>= 2.0.2, < 7.0)
    ast (2.4.2)
    aws-eventstream (1.3.0)
    aws-partitions (1.967.0)
    aws-sdk-core (3.201.5)
      aws-eventstream (~> 1, >= 1.3.0)
      aws-partitions (~> 1, >= 1.651.0)
      aws-sigv4 (~> 1.9)
      jmespath (~> 1, >= 1.6.1)
    aws-sdk-kms (1.88.0)
      aws-sdk-core (~> 3, >= 3.201.0)
      aws-sigv4 (~> 1.5)
    aws-sdk-s3 (1.159.0)
      aws-sdk-core (~> 3, >= 3.201.0)
      aws-sdk-kms (~> 1)
      aws-sigv4 (~> 1.5)
    aws-sigv4 (1.9.1)
      aws-eventstream (~> 1, >= 1.0.2)
    base64 (0.2.0)
    bcrypt (3.1.20)
    bigdecimal (3.1.8)
    bindex (0.8.1)
    bootsnap (1.18.3)
      msgpack (~> 1.2)
    builder (3.3.0)
    byebug (11.1.3)
    capybara (3.40.0)
      addressable
      matrix
      mini_mime (>= 0.1.3)
      nokogiri (~> 1.11)
      rack (>= 1.6.0)
      rack-test (>= 0.6.3)
      regexp_parser (>= 1.5, < 3.0)
      xpath (~> 3.2)
    childprocess (5.1.0)
      logger (~> 1.5)
    coderay (1.1.3)
    concurrent-ruby (1.3.3)
    config (5.5.1)
      deep_merge (~> 1.2, >= 1.2.1)
    connection_pool (2.4.1)
    crass (1.0.6)
    cssbundling-rails (1.4.0)
      railties (>= 6.0.0)
    date (3.3.4)
    debug (1.9.2)
      irb (~> 1.10)
      reline (>= 0.3.8)
    deep_merge (1.2.2)
    diff-lcs (1.5.1)
    dotenv (3.1.2)
    drb (2.2.1)
    enum_help (0.0.19)
      activesupport (>= 3.0.0)
    erubi (1.13.0)
    event_stream_parser (1.0.0)
    factory_bot (6.4.6)
      activesupport (>= 5.0.0)
    factory_bot_rails (6.4.3)
      factory_bot (~> 6.4)
      railties (>= 5.0.0)
    faker (3.4.2)
      i18n (>= 1.8.11, < 2)
    faraday (2.10.0)
      faraday-net_http (>= 2.0, < 3.2)
      logger
    faraday-multipart (1.0.4)
      multipart-post (~> 2)
    faraday-net_http (3.1.0)
      net-http
    ffi (1.17.0-aarch64-linux-gnu)
    ffi (1.17.0-arm-linux-gnu)
    ffi (1.17.0-arm64-darwin)
    ffi (1.17.0-x86-linux-gnu)
    ffi (1.17.0-x86_64-darwin)
    ffi (1.17.0-x86_64-linux-gnu)
    globalid (1.2.1)
      activesupport (>= 6.1)
    gretel (5.0.1)
      actionview (>= 6.1)
      railties (>= 6.1)
    hashie (5.0.0)
    i18n (1.14.5)
      concurrent-ruby (~> 1.0)
    image_processing (1.13.0)
      mini_magick (>= 4.9.5, < 5)
      ruby-vips (>= 2.0.17, < 3)
    io-console (0.7.2)
    irb (1.14.0)
      rdoc (>= 4.0.0)
      reline (>= 0.4.2)
    jbuilder (2.12.0)
      actionview (>= 5.0.0)
      activesupport (>= 5.0.0)
    jmespath (1.6.2)
    jsbundling-rails (1.3.0)
      railties (>= 6.0.0)
    json (2.7.2)
    jwt (2.8.2)
      base64
    language_server-protocol (3.17.0.3)
    launchy (3.0.1)
      addressable (~> 2.8)
      childprocess (~> 5.0)
    letter_opener (1.10.0)
      launchy (>= 2.2, < 4)
    letter_opener_web (3.0.0)
      actionmailer (>= 6.1)
      letter_opener (~> 1.9)
      railties (>= 6.1)
      rexml
    line-bot-api (1.29.0)
    logger (1.6.0)
    loofah (2.22.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.12.0)
    mail (2.8.1)
      mini_mime (>= 0.1.1)
      net-imap
      net-pop
      net-smtp
    marcel (1.0.4)
    matrix (0.4.2)
    method_source (1.1.0)
    mini_magick (4.13.2)
    mini_mime (1.1.5)
    minitest (5.24.1)
    msgpack (1.7.2)
    multi_xml (0.7.1)
      bigdecimal (~> 3.1)
    multipart-post (2.4.1)
    mutex_m (0.2.0)
    mysql2 (0.5.6)
    net-http (0.4.1)
      uri
    net-imap (0.4.14)
      date
      net-protocol
    net-pop (0.1.2)
      net-protocol
    net-protocol (0.2.2)
      timeout
    net-smtp (0.5.0)
      net-protocol
    nio4r (2.7.3)
    nokogiri (1.16.6-aarch64-linux)
      racc (~> 1.4)
    nokogiri (1.16.6-arm-linux)
      racc (~> 1.4)
    nokogiri (1.16.6-arm64-darwin)
      racc (~> 1.4)
    nokogiri (1.16.6-x86-linux)
      racc (~> 1.4)
    nokogiri (1.16.6-x86_64-darwin)
      racc (~> 1.4)
    nokogiri (1.16.6-x86_64-linux)
      racc (~> 1.4)
    oauth (1.1.0)
      oauth-tty (~> 1.0, >= 1.0.1)
      snaky_hash (~> 2.0)
      version_gem (~> 1.1)
    oauth-tty (1.0.5)
      version_gem (~> 1.1, >= 1.1.1)
    oauth2 (2.0.9)
      faraday (>= 0.17.3, < 3.0)
      jwt (>= 1.0, < 3.0)
      multi_xml (~> 0.5)
      rack (>= 1.2, < 4)
      snaky_hash (~> 2.0)
      version_gem (~> 1.1)
    parallel (1.25.1)
    parser (3.3.4.0)
      ast (~> 2.4.1)
      racc
    pry (0.14.2)
      coderay (~> 1.1)
      method_source (~> 1.0)
    pry-byebug (3.10.1)
      byebug (~> 11.0)
      pry (>= 0.13, < 0.15)
    pry-rails (0.3.11)
      pry (>= 0.13.0)
    psych (5.1.2)
      stringio
    public_suffix (6.0.0)
    puma (6.4.2)
      nio4r (~> 2.0)
    racc (1.8.0)
    rack (3.1.6)
    rack-session (2.0.0)
      rack (>= 3.0.0)
    rack-test (2.1.0)
      rack (>= 1.3)
    rackup (2.1.0)
      rack (>= 3)
      webrick (~> 1.8)
    rails (7.1.3.4)
      actioncable (= 7.1.3.4)
      actionmailbox (= 7.1.3.4)
      actionmailer (= 7.1.3.4)
      actionpack (= 7.1.3.4)
      actiontext (= 7.1.3.4)
      actionview (= 7.1.3.4)
      activejob (= 7.1.3.4)
      activemodel (= 7.1.3.4)
      activerecord (= 7.1.3.4)
      activestorage (= 7.1.3.4)
      activesupport (= 7.1.3.4)
      bundler (>= 1.15.0)
      railties (= 7.1.3.4)
    rails-dom-testing (2.2.0)
      activesupport (>= 5.0.0)
      minitest
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.6.0)
      loofah (~> 2.21)
      nokogiri (~> 1.14)
    railties (7.1.3.4)
      actionpack (= 7.1.3.4)
      activesupport (= 7.1.3.4)
      irb
      rackup (>= 1.0.0)
      rake (>= 12.2)
      thor (~> 1.0, >= 1.2.2)
      zeitwerk (~> 2.6)
    rainbow (3.1.1)
    rake (13.2.1)
    ransack (4.2.1)
      activerecord (>= 6.1.5)
      activesupport (>= 6.1.5)
      i18n
    rdoc (6.7.0)
      psych (>= 4.0.0)
    regexp_parser (2.9.2)
    reline (0.5.9)
      io-console (~> 0.5)
    rexml (3.3.1)
      strscan
    rspec-core (3.13.0)
      rspec-support (~> 3.13.0)
    rspec-expectations (3.13.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.13.0)
    rspec-mocks (3.13.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.13.0)
    rspec-rails (6.1.3)
      actionpack (>= 6.1)
      activesupport (>= 6.1)
      railties (>= 6.1)
      rspec-core (~> 3.13)
      rspec-expectations (~> 3.13)
      rspec-mocks (~> 3.13)
      rspec-support (~> 3.13)
    rspec-support (3.13.1)
    rubocop (1.65.1)
      json (~> 2.3)
      language_server-protocol (>= 3.17.0)
      parallel (~> 1.10)
      parser (>= 3.3.0.2)
      rainbow (>= 2.2.2, < 4.0)
      regexp_parser (>= 2.4, < 3.0)
      rexml (>= 3.2.5, < 4.0)
      rubocop-ast (>= 1.31.1, < 2.0)
      ruby-progressbar (~> 1.7)
      unicode-display_width (>= 2.4.0, < 3.0)
    rubocop-ast (1.31.3)
      parser (>= 3.3.1.0)
    rubocop-rails (2.25.1)
      activesupport (>= 4.2.0)
      rack (>= 1.1)
      rubocop (>= 1.33.0, < 2.0)
      rubocop-ast (>= 1.31.1, < 2.0)
    ruby-openai (7.1.0)
      event_stream_parser (>= 0.3.0, < 2.0.0)
      faraday (>= 1)
      faraday-multipart (>= 1)
    ruby-progressbar (1.13.0)
    ruby-vips (2.2.2)
      ffi (~> 1.12)
      logger
    rubyzip (2.3.2)
    selenium-webdriver (4.22.0)
      base64 (~> 0.2)
      logger (~> 1.4)
      rexml (~> 3.2, >= 3.2.5)
      rubyzip (>= 1.2.2, < 3.0)
      websocket (~> 1.0)
    simple_calendar (3.0.4)
      rails (>= 6.1)
    snaky_hash (2.0.1)
      hashie
      version_gem (~> 1.1, >= 1.1.1)
    sorcery (0.17.0)
      bcrypt (~> 3.1)
      oauth (>= 0.6)
      oauth2 (~> 2.0)
    sprockets (4.2.1)
      concurrent-ruby (~> 1.0)
      rack (>= 2.2.4, < 4)
    sprockets-rails (3.5.1)
      actionpack (>= 6.1)
      activesupport (>= 6.1)
      sprockets (>= 3.0.0)
    stimulus-rails (1.3.3)
      railties (>= 6.0.0)
    stringio (3.1.1)
    strscan (3.1.0)
    thor (1.3.1)
    timeout (0.4.1)
    turbo-rails (2.0.5)
      actionpack (>= 6.0.0)
      activejob (>= 6.0.0)
      railties (>= 6.0.0)
    tzinfo (2.0.6)
      concurrent-ruby (~> 1.0)
    unicode-display_width (2.5.0)
    uri (0.13.0)
    version_gem (1.1.4)
    web-console (4.2.1)
      actionview (>= 6.0.0)
      activemodel (>= 6.0.0)
      bindex (>= 0.4.0)
      railties (>= 6.0.0)
    webdrivers (5.2.0)
      nokogiri (~> 1.6)
      rubyzip (>= 1.3.0)
      selenium-webdriver (~> 4.0)
    webrick (1.8.1)
    websocket (1.2.11)
    websocket-driver (0.7.6)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)
    xpath (3.2.0)
      nokogiri (~> 1.8)
    zeitwerk (2.6.16)

PLATFORMS
  aarch64-linux
  arm-linux
  arm64-darwin
  x86-linux
  x86_64-darwin
  x86_64-linux

DEPENDENCIES
  active_storage_validations
  aws-sdk-s3
  bootsnap
  capybara
  config
  cssbundling-rails
  debug
  dotenv
  enum_help
  factory_bot_rails
  faker
  gretel
  image_processing (~> 1.2)
  jbuilder
  jsbundling-rails
  letter_opener_web (~> 3.0)
  line-bot-api
  mysql2 (~> 0.5)
  pry-byebug
  pry-rails
  puma (>= 5.0)
  rails (~> 7.1.3, >= 7.1.3.4)
  ransack
  rspec-rails
  rubocop
  rubocop-rails
  ruby-openai
  selenium-webdriver
  simple_calendar
  sorcery
  sprockets-rails
  stimulus-rails
  turbo-rails
  tzinfo-data
  web-console
  webdrivers

RUBY VERSION
   ruby 3.2.3p157

BUNDLED WITH
   2.5.9

(2)-2. spec/rails_helper.rb, spec/spec_helper.rb設定ファイルを確認 → 並列処理の記述は見つかりませんでした spec/rails_helper.rb

# This file is copied to spec/ when you run "rails generate rspec:install"
require "spec_helper"
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require "rspec/rails"
# Add additional requires below this line. Rails is not loaded until this point!

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.

Dir[Rails.root.join("spec", "support", "**", "*.rb")].each { |f| require f }

# Rails.root.glob("spec/support/**/*.rb").sort.each { |f| require f }

# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
begin
  ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
  abort e.to_s.strip
end
RSpec.configure do |config|
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_paths = [
    Rails.root.join("spec/fixtures")
  ]

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true

  # You can uncomment this line to turn off ActiveRecord support entirely.
  # config.use_active_record = false

  # RSpec Rails can automatically mix in different behaviours to your tests
  # based on their file location, for example enabling you to call `get` and
  # `post` in specs under `spec/controllers`.
  #
  # You can disable this behaviour by removing the line below, and instead
  # explicitly tag your specs with their type, e.g.:
  #
  #     RSpec.describe UsersController, type: :controller do
  #       # ...
  #     end
  #
  # The different available types are documented in the features, such as in
  # https://rspec.info/features/6-0/rspec-rails
  config.infer_spec_type_from_file_location!

  # Filter lines from Rails gems in backtraces.
  config.filter_rails_from_backtrace!
  # arbitrary gems may also be filtered via:
  # config.filter_gems_from_backtrace("gem name")

  config.include FactoryBot::Syntax::Methods

  config.before(:each, type: :system) do
    driven_by :selenium_chrome_headless
  end
end

spec/spec_helper.rb

# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
# files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, consider making
# a separate helper file that requires the additional dependencies and performs
# the additional setup, and require it from the spec files that actually need
# it.
#
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
  # rspec-expectations config goes here. You can use an alternate
  # assertion/expectation library such as wrong or the stdlib/minitest
  # assertions if you prefer.
  config.expect_with :rspec do |expectations|
    # This option will default to `true` in RSpec 4. It makes the `description`
    # and `failure_message` of custom matchers include text for helper methods
    # defined using `chain`, e.g.:
    #     be_bigger_than(2).and_smaller_than(4).description
    #     # => "be bigger than 2 and smaller than 4"
    # ...rather than:
    #     # => "be bigger than 2"
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  # rspec-mocks config goes here. You can use an alternate test double
  # library (such as bogus or mocha) by changing the `mock_with` option here.
  config.mock_with :rspec do |mocks|
    # Prevents you from mocking or stubbing a method that does not exist on
    # a real object. This is generally recommended, and will default to
    # `true` in RSpec 4.
    mocks.verify_partial_doubles = true
  end

  # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
  # have no way to turn it off -- the option exists only for backwards
  # compatibility in RSpec 3). It causes shared context metadata to be
  # inherited by the metadata hash of host groups and examples, rather than
  # triggering implicit auto-inclusion in groups with matching metadata.
  config.shared_context_metadata_behavior = :apply_to_host_groups

# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
  # This allows you to limit a spec run to individual examples or groups
  # you care about by tagging them with `:focus` metadata. When nothing
  # is tagged with `:focus`, all examples get run. RSpec also provides
  # aliases for `it`, `describe`, and `context` that include `:focus`
  # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
  config.filter_run_when_matching :focus

  # Allows RSpec to persist some state between runs in order to support
  # the `--only-failures` and `--next-failure` CLI options. We recommend
  # you configure your source control system to ignore this file.
  config.example_status_persistence_file_path = "spec/examples.txt"

  # Limits the available syntax to the non-monkey patched syntax that is
  # recommended. For more details, see:
  # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
  config.disable_monkey_patching!

  # Many RSpec users commonly either run the entire suite or an individual
  # file, and it's useful to allow more verbose output when running an
  # individual spec file.
  if config.files_to_run.one?
    # Use the documentation formatter for detailed output,
    # unless a formatter has already been configured
    # (e.g. via a command-line flag).
    config.default_formatter = "doc"
  end

  # Print the 10 slowest examples and example groups at the
  # end of the spec run, to help surface which specs are running
  # particularly slow.
  config.profile_examples = 10

  # Run specs in random order to surface order dependencies. If you find an
  # order dependency and want to debug it, you can fix the order by providing
  # the seed, which is printed after each run.
  #     --seed 1234
  config.order = :random

  # Seed global randomization in this process using the `--seed` CLI option.
  # Setting this allows you to use `--seed` to deterministically reproduce
  # test failures related to randomization by passing the same `--seed` value
  # as the one that triggered the failure.
  Kernel.srand config.seed
=end
end

お伺いしたいこと

原因の仮説は合っておりますでしょうか? 合っていれば、さらに深掘りするデバックの方法はありますでしょうか? また、見落としているファイルはございますでしょうか?

Tsuchiya2 commented 4 days ago

以下に箇条書きで記載しました🙇 letではなくlet!を使っても同様のエラーが出てしまうかを試してみてください。

- 仮説は正しいですが、より具体的な原因はletの遅延評価やトランザクションフィクスチャとFiberの競合である可能性が高いです。
- letの遅延評価による問題
  - letは遅延評価されるため、テスト内でのデータベース接続のタイミングがFiberと競合する可能性があります。
  - 対策案:letではなくlet!を使用して、事前にデータを作成します。
wassupdee commented 4 days ago

どうもありがとうございます!

実行したこと

question_spec.rb含め、spec/modelディレクトリ内のすべてのlet --> let!に変更しました。

spec/models/question_spec.rb

require "rails_helper"

RSpec.describe Question, type: :model do
  let!(:question) { create(:question) }
  let!(:answer1) { create(:answer, question:) }
  let!(:answer2) { create(:answer, question:) }

  describe "アソシエーションチェック" do
    it "answersと1対多の関係にある" do
      expect(question.answers).to include(answer1, answer2)
    end

    it "関連するanswersがあっても、questionを削除でき、answersも削除される" do
      expect { question.destroy }.to change { Question.count }.by(-1)
      expect(Answer.where(id: [answer1.id, answer2.id])).to be_empty
    end
  end
end

結果

エラーの解消には至りませんでした。同じエラーが発生してしまいます。

 Question アソシエーションチェック answersと1対多の関係にある
     Failure/Error: _query(sql, @query_options.merge(options))

     ActiveRecord::StatementInvalid:
       Mysql2::Error: This connection is in use by: #<Fiber:0x00007ff1dc4018b8 (resumed)>
     # /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:151:in `_query'
     # /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:151:in `block in query'
     # /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:150:in `handle_interrupt'
     # /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:150:in `query'
     # ------------------
     # --- Caused by: ---
     # Mysql2::Error:
     #   This connection is in use by: #<Fiber:0x00007ff1dc4018b8 (resumed)>
     #   /usr/local/bundle/gems/mysql2-0.5.6/lib/mysql2/client.rb:151:in `_query'

新たに試したこと

トランズアクションフィックスチャの影響かと考え、spec/rails_helper.rbにて、 config.use_transactional_fixtures = true --> config.use_transactional_fixtures = falseに変更してみました。

# This file is copied to spec/ when you run "rails generate rspec:install"
require "spec_helper"
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require "rspec/rails"
# Add additional requires below this line. Rails is not loaded until this point!

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.

Dir[Rails.root.join("spec", "support", "**", "*.rb")].each { |f| require f }

# Rails.root.glob("spec/support/**/*.rb").sort.each { |f| require f }

# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
begin
  ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
  abort e.to_s.strip
end
RSpec.configure do |config|
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_paths = [
    Rails.root.join("spec/fixtures")
  ]

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = false

  # You can uncomment this line to turn off ActiveRecord support entirely.
  # config.use_active_record = false

  # RSpec Rails can automatically mix in different behaviours to your tests
  # based on their file location, for example enabling you to call `get` and
  # `post` in specs under `spec/controllers`.
  #
  # You can disable this behaviour by removing the line below, and instead
  # explicitly tag your specs with their type, e.g.:
  #
  #     RSpec.describe UsersController, type: :controller do
  #       # ...
  #     end
  #
  # The different available types are documented in the features, such as in
  # https://rspec.info/features/6-0/rspec-rails
  config.infer_spec_type_from_file_location!

  # Filter lines from Rails gems in backtraces.
  config.filter_rails_from_backtrace!
  # arbitrary gems may also be filtered via:
  # config.filter_gems_from_backtrace("gem name")

  config.include FactoryBot::Syntax::Methods

  config.before(:each, type: :system) do
    driven_by :selenium_chrome_headless
  end
end

結果

Fiberとの競合エラーはなくなりましたが、 テストDBのRollbackが行われないため、 テスト用のレコードがDBに残り重複エラーが発生しました。

$ dc exec web bundle exec rspec spec/models

Album
  アソシエーションチェック
    profileとのアソシエーション
      profileと1対多の関係にある (FAILED - 1)
  バリデーションチェック
    無効なデータの場合
      無効なファイル形式はアップロードできない (FAILED - 2)
      5MB以上のファイルはアップロードできない (FAILED - 3)
      画像は4枚以上アップロードできない (FAILED - 4)
    有効なデータの場合
      正常に画像が保存される (FAILED - 5)

Answer
  アソシエーションチェック
    questionとのアソシエーション
      questionと1対多の関係にある (FAILED - 6)
  バリデーションチェック
    valueがユニークであれば登録できる (FAILED - 7)
    valueが重複するとエラーが起きる (FAILED - 8)
  ロジックチェック
    セッションに各問の回答を保存する (FAILED - 9)
    パラメーターから現在の質問番号を取得する (FAILED - 10)
    現在の質問が最後か確認する (FAILED - 11)

Authentication
  アソシエーションチェック
    userとのアソシエーション
      userと1対多の関係にある (FAILED - 12)

Event
  アソシエーションチェック
    profileとのアソシエーション
      profileと1対多の関係にある (FAILED - 13)
  ロジックチェック
    通知の条件を満たしているか確認する (FAILED - 14)
    日付をUTCからJSTへ変換する(9時間先に進める) (FAILED - 15)
    特定の日付の「年」を今年に変更する (FAILED - 16)
    通知日は今日か確認する (FAILED - 17)
  バリデーションチェック
    1profileあたりの登録できるイベント数を2つまでに制限する (FAILED - 18)
  enumチェック
    boolean型のnotification_enabledが、off/onに対応している (FAILED - 19)

Profile
  アソシエーションチェック
    userとのアソシエーション
      userと1対多の関係にある (FAILED - 20)
    albumsとのアソシエーション
      albumsと1対多の関係にある (FAILED - 21)
      関連するalbumsがあっても、profileを削除でき、albumsも削除される (FAILED - 22)
    eventsとのアソシエーション
      eventsと1対多の関係にある (FAILED - 23)
      関連するeventsがあっても、profileを削除でき、eventsも削除される (FAILED - 24)
  accepts_nested_attributes_for
    profileモデルが更新される際、ネストされたeventsの属性も保存する (FAILED - 25)
  ロジックチェック
    誕生日のチェック
      誕生日の月が今月か判定する(同月の場合) (FAILED - 26)
      誕生日の月が今月か判定する(違う月の場合) (FAILED - 27)
    大切な日のチェック
      大切な日の月が今月か判定する(同月の場合) (FAILED - 28)
      大切な日の月が今月か判定する(同月の場合) (FAILED - 29)
    ransack
      検索のための属性を定義する (FAILED - 30)
  enumチェック
    last_contactedにenumが付いている (FAILED - 31)
  バリデーションチェック
    無効なデータの場合
      無効なファイル形式はアップロードできない (FAILED - 32)
      1MB以上のファイルはアップロードできない (FAILED - 33)
    有効なデータの場合
      正常に画像が保存される (FAILED - 34)

Question
  アソシエーションチェック
    answersと1対多の関係にある (FAILED - 35)
    関連するanswersがあっても、questionを削除でき、answersも削除される (FAILED - 36)

User
  バリデーション
    名前、メール、パスワード、確認用パスワード、notification_enabledがある場合、有効である
    名前がない場合、無効である (FAILED - 37)
    名前が255文字以上場合、無効である (FAILED - 38)
    メールアドレスがない場合、無効である (FAILED - 39)
    重複したメールアドレスの場合、無効である (FAILED - 40)
    パスワードが2文字以下の場合、無効である (FAILED - 41)
    パスワード(確認用)がない場合、無効である (FAILED - 42)
    パスワード(確認用)がパスワードと一致しない場合、無効である (FAILED - 43)
    notificaiton_enabledない場合、無効である (FAILED - 44)
    line_user_idがblankの場合、重複していても有効である (FAILED - 45)
    notification_enabledがenumで定義されている (FAILED - 46)
  アソシエーションチェック
    profilesとのアソシエーション
      profilesと1対多の関係にある (FAILED - 47)
      関連するprofilesがあっても、userを削除でき、profilesも削除される (FAILED - 48)
    groupsとのアソシエーション
      groupsと1対多の関係にある (FAILED - 49)
      関連するgroupsがあっても、userを削除でき、groupsも削除される (FAILED - 50)
    authenticationsとのアソシエーション
      authenticationsと1対多の関係にある (FAILED - 51)
      関連するauthenticationsがあっても、userを削除でき、authenticationsも削除される (FAILED - 52)
    eventsとのアソシエーション
      eventsと1対多の関係にある (FAILED - 53)
      関連するeventsがあっても、userを削除でき、eventsも削除される (FAILED - 54)
  accepts_nested_attributes_for
    userモデルが更新される際、ネストされたauthenticationsの属性も保存する (FAILED - 55)
  メソッドのテスト
    LINE通知の対象ユーザーを取得する (FAILED - 56)

Failures:

  1) Album アソシエーションチェック profileとのアソシエーション profileと1対多の関係にある
     Failure/Error: let!(:user) { create(:user) }

     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
     # ./spec/models/album_spec.rb:4:in `block (2 levels) in <top (required)>'

  2) Album バリデーションチェック 無効なデータの場合 無効なファイル形式はアップロードできない
     Failure/Error: let!(:user) { create(:user) }

     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
     # ./spec/models/album_spec.rb:4:in `block (2 levels) in <top (required)>'

  3) Album バリデーションチェック 無効なデータの場合 5MB以上のファイルはアップロードできない
     Failure/Error: let!(:user) { create(:user) }

     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
     # ./spec/models/album_spec.rb:4:in `block (2 levels) in <top (required)>'

  4) Album バリデーションチェック 無効なデータの場合 画像は4枚以上アップロードできない
     Failure/Error: let!(:user) { create(:user) }

     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
     # ./spec/models/album_spec.rb:4:in `block (2 levels) in <top (required)>'

  5) Album バリデーションチェック 有効なデータの場合 正常に画像が保存される
     Failure/Error: let!(:user) { create(:user) }

     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
     # ./spec/models/album_spec.rb:4:in `block (2 levels) in <top (required)>'

  6) Answer アソシエーションチェック questionとのアソシエーション questionと1対多の関係にある
     Failure/Error: let!(:user) { create(:user) }

     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
     # ./spec/models/answer_spec.rb:4:in `block (2 levels) in <main>'

  7) Answer バリデーションチェック valueがユニークであれば登録できる
     Failure/Error: let!(:user) { create(:user) }

     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
     # ./spec/models/answer_spec.rb:4:in `block (2 levels) in <main>'

  8) Answer バリデーションチェック valueが重複するとエラーが起きる
     Failure/Error: let!(:user) { create(:user) }

     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
     # ./spec/models/answer_spec.rb:4:in `block (2 levels) in <main>'

  9) Answer ロジックチェック セッションに各問の回答を保存する
     Failure/Error: let!(:user) { create(:user) }

     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
     # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
     # ./spec/models/answer_spec.rb:4:in `block (2 levels) in <main>'

  10) Answer ロジックチェック パラメーターから現在の質問番号を取得する
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/answer_spec.rb:4:in `block (2 levels) in <main>'

  11) Answer ロジックチェック 現在の質問が最後か確認する
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/answer_spec.rb:4:in `block (2 levels) in <main>'

  12) Authentication アソシエーションチェック userとのアソシエーション userと1対多の関係にある
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/authentication_spec.rb:4:in `block (2 levels) in <main>'

  13) Event アソシエーションチェック profileとのアソシエーション profileと1対多の関係にある
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/event_spec.rb:4:in `block (2 levels) in <main>'

  14) Event ロジックチェック 通知の条件を満たしているか確認する
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/event_spec.rb:4:in `block (2 levels) in <main>'

  15) Event ロジックチェック 日付をUTCからJSTへ変換する(9時間先に進める)
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/event_spec.rb:4:in `block (2 levels) in <main>'

  16) Event ロジックチェック 特定の日付の「年」を今年に変更する
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/event_spec.rb:4:in `block (2 levels) in <main>'

  17) Event ロジックチェック 通知日は今日か確認する
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/event_spec.rb:4:in `block (2 levels) in <main>'

  18) Event バリデーションチェック 1profileあたりの登録できるイベント数を2つまでに制限する
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/event_spec.rb:4:in `block (2 levels) in <main>'

  19) Event enumチェック boolean型のnotification_enabledが、off/onに対応している
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/event_spec.rb:4:in `block (2 levels) in <main>'

  20) Profile アソシエーションチェック userとのアソシエーション userと1対多の関係にある
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  21) Profile アソシエーションチェック albumsとのアソシエーション albumsと1対多の関係にある
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  22) Profile アソシエーションチェック albumsとのアソシエーション 関連するalbumsがあっても、profileを削除でき、albumsも削除される
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  23) Profile アソシエーションチェック eventsとのアソシエーション eventsと1対多の関係にある
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  24) Profile アソシエーションチェック eventsとのアソシエーション 関連するeventsがあっても、profileを削除でき、eventsも削除される
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  25) Profile accepts_nested_attributes_for profileモデルが更新される際、ネストされたeventsの属性も保存する
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  26) Profile ロジックチェック 誕生日のチェック 誕生日の月が今月か判定する(同月の場合)
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  27) Profile ロジックチェック 誕生日のチェック 誕生日の月が今月か判定する(違う月の場合)
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  28) Profile ロジックチェック 大切な日のチェック 大切な日の月が今月か判定する(同月の場合)
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  29) Profile ロジックチェック 大切な日のチェック 大切な日の月が今月か判定する(同月の場合)
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  30) Profile ロジックチェック ransack 検索のための属性を定義する
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  31) Profile enumチェック last_contactedにenumが付いている
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  32) Profile バリデーションチェック 無効なデータの場合 無効なファイル形式はアップロードできない
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  33) Profile バリデーションチェック 無効なデータの場合 1MB以上のファイルはアップロードできない
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  34) Profile バリデーションチェック 有効なデータの場合 正常に画像が保存される
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/profile_spec.rb:4:in `block (2 levels) in <main>'

  35) Question アソシエーションチェック answersと1対多の関係にある
      Failure/Error: let!(:answer1) { create(:answer, question:) }

      ActiveRecord::RecordInvalid:
        Validation failed: Value has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/question_spec.rb:5:in `block (2 levels) in <main>'

  36) Question アソシエーションチェック 関連するanswersがあっても、questionを削除でき、answersも削除される
      Failure/Error: let!(:answer1) { create(:answer, question:) }

      ActiveRecord::RecordInvalid:
        Validation failed: Value has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/question_spec.rb:5:in `block (2 levels) in <main>'

  37) User バリデーション 名前がない場合、無効である
      Failure/Error: expect(user.errors[:name]).to include("名前を入力してください")
        expected ["can't be blank"] to include "名前を入力してください"
      # ./spec/models/user_spec.rb:13:in `block (3 levels) in <main>'

  38) User バリデーション 名前が255文字以上場合、無効である
      Failure/Error: expect(user.errors[:name]).to include("255文字以内で入力してください")
        expected ["is too long (maximum is 255 characters)"] to include "255文字以内で入力してください"
      # ./spec/models/user_spec.rb:19:in `block (3 levels) in <main>'

  39) User バリデーション メールアドレスがない場合、無効である
      Failure/Error: expect(user.errors[:email]).to include("メールアドレスを入力してください")
        expected ["can't be blank"] to include "メールアドレスを入力してください"
      # ./spec/models/user_spec.rb:25:in `block (3 levels) in <main>'

  40) User バリデーション 重複したメールアドレスの場合、無効である
      Failure/Error: other_user = create(:user)

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/user_spec.rb:29:in `block (3 levels) in <main>'

  41) User バリデーション パスワードが2文字以下の場合、無効である
      Failure/Error: expect(user.errors[:password]).to include("パスワードは3文字以上で設定してください")
        expected ["is too short (minimum is 3 characters)"] to include "パスワードは3文字以上で設定してください"
      # ./spec/models/user_spec.rb:38:in `block (3 levels) in <main>'

  42) User バリデーション パスワード(確認用)がない場合、無効である
      Failure/Error: expect(user.errors[:password_confirmation]).to include("確認用のパスワードを入力してください")
        expected ["doesn't match Password", "can't be blank"] to include "確認用のパスワードを入力してください"
      # ./spec/models/user_spec.rb:44:in `block (3 levels) in <main>'

  43) User バリデーション パスワード(確認用)がパスワードと一致しない場合、無効である
      Failure/Error: expect(user.errors[:password_confirmation]).to include("パスワードと一致しません")
        expected ["doesn't match Password"] to include "パスワードと一致しません"
      # ./spec/models/user_spec.rb:50:in `block (3 levels) in <main>'

  44) User バリデーション notificaiton_enabledない場合、無効である
      Failure/Error: expect(user.errors[:notification_enabled]).to include("通知を設定してください")
        expected ["can't be blank"] to include "通知を設定してください"
      # ./spec/models/user_spec.rb:56:in `block (3 levels) in <main>'

  45) User バリデーション line_user_idがblankの場合、重複していても有効である
      Failure/Error: create(:user, line_user_id: "")

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/user_spec.rb:60:in `block (3 levels) in <main>'

  46) User バリデーション notification_enabledがenumで定義されている
      Failure/Error: user1 = create(:user, notification_enabled: true)

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/user_spec.rb:67:in `block (3 levels) in <main>'

  47) User アソシエーションチェック profilesとのアソシエーション profilesと1対多の関係にある
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/user_spec.rb:75:in `block (3 levels) in <main>'

  48) User アソシエーションチェック profilesとのアソシエーション 関連するprofilesがあっても、userを削除でき、profilesも削除される
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/user_spec.rb:75:in `block (3 levels) in <main>'

  49) User アソシエーションチェック groupsとのアソシエーション groupsと1対多の関係にある
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/user_spec.rb:75:in `block (3 levels) in <main>'

  50) User アソシエーションチェック groupsとのアソシエーション 関連するgroupsがあっても、userを削除でき、groupsも削除される
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/user_spec.rb:75:in `block (3 levels) in <main>'

  51) User アソシエーションチェック authenticationsとのアソシエーション authenticationsと1対多の関係にある
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/user_spec.rb:75:in `block (3 levels) in <main>'

  52) User アソシエーションチェック authenticationsとのアソシエーション 関連するauthenticationsがあっても、userを削除でき、authenticationsも削除される
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/user_spec.rb:75:in `block (3 levels) in <main>'

  53) User アソシエーションチェック eventsとのアソシエーション eventsと1対多の関係にある
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/user_spec.rb:75:in `block (3 levels) in <main>'

  54) User アソシエーションチェック eventsとのアソシエーション 関連するeventsがあっても、userを削除でき、eventsも削除される
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/user_spec.rb:75:in `block (3 levels) in <main>'

  55) User accepts_nested_attributes_for userモデルが更新される際、ネストされたauthenticationsの属性も保存する
      Failure/Error: let!(:user) { create(:user) }

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/user_spec.rb:136:in `block (3 levels) in <main>'

  56) User メソッドのテスト LINE通知の対象ユーザーを取得する
      Failure/Error: user_to_notify = create(:user, line_user_id: "aaa", notification_enabled: true)

      ActiveRecord::RecordInvalid:
        Validation failed: Email has already been taken
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/evaluation.rb:15:in `create'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:12:in `block in result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy/create.rb:9:in `result'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory.rb:43:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:29:in `block in run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/factory_runner.rb:28:in `run'
      # /usr/local/bundle/gems/factory_bot-6.4.6/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
      # ./spec/models/user_spec.rb:155:in `block (3 levels) in <main>'

Finished in 1.03 seconds (files took 3.96 seconds to load)
57 examples, 56 failures

Failed examples:

rspec ./spec/models/album_spec.rb:13 # Album アソシエーションチェック profileとのアソシエーション profileと1対多の関係にある
rspec ./spec/models/album_spec.rb:21 # Album バリデーションチェック 無効なデータの場合 無効なファイル形式はアップロードできない
rspec ./spec/models/album_spec.rb:25 # Album バリデーションチェック 無効なデータの場合 5MB以上のファイルはアップロードできない
rspec ./spec/models/album_spec.rb:29 # Album バリデーションチェック 無効なデータの場合 画像は4枚以上アップロードできない
rspec ./spec/models/album_spec.rb:36 # Album バリデーションチェック 有効なデータの場合 正常に画像が保存される
rspec ./spec/models/answer_spec.rb:10 # Answer アソシエーションチェック questionとのアソシエーション questionと1対多の関係にある
rspec ./spec/models/answer_spec.rb:17 # Answer バリデーションチェック valueがユニークであれば登録できる
rspec ./spec/models/answer_spec.rb:24 # Answer バリデーションチェック valueが重複するとエラーが起きる
rspec ./spec/models/answer_spec.rb:33 # Answer ロジックチェック セッションに各問の回答を保存する
rspec ./spec/models/answer_spec.rb:41 # Answer ロジックチェック パラメーターから現在の質問番号を取得する
rspec ./spec/models/answer_spec.rb:48 # Answer ロジックチェック 現在の質問が最後か確認する
rspec ./spec/models/authentication_spec.rb:9 # Authentication アソシエーションチェック userとのアソシエーション userと1対多の関係にある
rspec ./spec/models/event_spec.rb:10 # Event アソシエーションチェック profileとのアソシエーション profileと1対多の関係にある
rspec ./spec/models/event_spec.rb:17 # Event ロジックチェック 通知の条件を満たしているか確認する
rspec ./spec/models/event_spec.rb:21 # Event ロジックチェック 日付をUTCからJSTへ変換する(9時間先に進める)
rspec ./spec/models/event_spec.rb:29 # Event ロジックチェック 特定の日付の「年」を今年に変更する
rspec ./spec/models/event_spec.rb:37 # Event ロジックチェック 通知日は今日か確認する
rspec ./spec/models/event_spec.rb:57 # Event バリデーションチェック 1profileあたりの登録できるイベント数を2つまでに制限する
rspec ./spec/models/event_spec.rb:69 # Event enumチェック boolean型のnotification_enabledが、off/onに対応している
rspec ./spec/models/profile_spec.rb:12 # Profile アソシエーションチェック userとのアソシエーション userと1対多の関係にある
rspec ./spec/models/profile_spec.rb:21 # Profile アソシエーションチェック albumsとのアソシエーション albumsと1対多の関係にある
rspec ./spec/models/profile_spec.rb:25 # Profile アソシエーションチェック albumsとのアソシエーション 関連するalbumsがあっても、profileを削除でき、albumsも削除される
rspec ./spec/models/profile_spec.rb:35 # Profile アソシエーションチェック eventsとのアソシエーション eventsと1対多の関係にある
rspec ./spec/models/profile_spec.rb:39 # Profile アソシエーションチェック eventsとのアソシエーション 関連するeventsがあっても、profileを削除でき、eventsも削除される
rspec ./spec/models/profile_spec.rb:74 # Profile accepts_nested_attributes_for profileモデルが更新される際、ネストされたeventsの属性も保存する
rspec ./spec/models/profile_spec.rb:95 # Profile ロジックチェック 誕生日のチェック 誕生日の月が今月か判定する(同月の場合)
rspec ./spec/models/profile_spec.rb:100 # Profile ロジックチェック 誕生日のチェック 誕生日の月が今月か判定する(違う月の場合)
rspec ./spec/models/profile_spec.rb:107 # Profile ロジックチェック 大切な日のチェック 大切な日の月が今月か判定する(同月の場合)
rspec ./spec/models/profile_spec.rb:114 # Profile ロジックチェック 大切な日のチェック 大切な日の月が今月か判定する(同月の場合)
rspec ./spec/models/profile_spec.rb:123 # Profile ロジックチェック ransack 検索のための属性を定義する
rspec ./spec/models/profile_spec.rb:130 # Profile enumチェック last_contactedにenumが付いている
rspec ./spec/models/profile_spec.rb:137 # Profile バリデーションチェック 無効なデータの場合 無効なファイル形式はアップロードできない
rspec ./spec/models/profile_spec.rb:141 # Profile バリデーションチェック 無効なデータの場合 1MB以上のファイルはアップロードできない
rspec ./spec/models/profile_spec.rb:148 # Profile バリデーションチェック 有効なデータの場合 正常に画像が保存される
rspec ./spec/models/question_spec.rb:9 # Question アソシエーションチェック answersと1対多の関係にある
rspec ./spec/models/question_spec.rb:13 # Question アソシエーションチェック 関連するanswersがあっても、questionを削除でき、answersも削除される
rspec ./spec/models/user_spec.rb:10 # User バリデーション 名前がない場合、無効である
rspec ./spec/models/user_spec.rb:16 # User バリデーション 名前が255文字以上場合、無効である
rspec ./spec/models/user_spec.rb:22 # User バリデーション メールアドレスがない場合、無効である
rspec ./spec/models/user_spec.rb:28 # User バリデーション 重複したメールアドレスの場合、無効である
rspec ./spec/models/user_spec.rb:35 # User バリデーション パスワードが2文字以下の場合、無効である
rspec ./spec/models/user_spec.rb:41 # User バリデーション パスワード(確認用)がない場合、無効である
rspec ./spec/models/user_spec.rb:47 # User バリデーション パスワード(確認用)がパスワードと一致しない場合、無効である
rspec ./spec/models/user_spec.rb:53 # User バリデーション notificaiton_enabledない場合、無効である
rspec ./spec/models/user_spec.rb:59 # User バリデーション line_user_idがblankの場合、重複していても有効である
rspec ./spec/models/user_spec.rb:66 # User バリデーション notification_enabledがenumで定義されている
rspec ./spec/models/user_spec.rb:81 # User アソシエーションチェック profilesとのアソシエーション profilesと1対多の関係にある
rspec ./spec/models/user_spec.rb:85 # User アソシエーションチェック profilesとのアソシエーション 関連するprofilesがあっても、userを削除でき、profilesも削除される
rspec ./spec/models/user_spec.rb:95 # User アソシエーションチェック groupsとのアソシエーション groupsと1対多の関係にある
rspec ./spec/models/user_spec.rb:99 # User アソシエーションチェック groupsとのアソシエーション 関連するgroupsがあっても、userを削除でき、groupsも削除される
rspec ./spec/models/user_spec.rb:109 # User アソシエーションチェック authenticationsとのアソシエーション authenticationsと1対多の関係にある
rspec ./spec/models/user_spec.rb:113 # User アソシエーションチェック authenticationsとのアソシエーション 関連するauthenticationsがあっても、userを削除でき、authenticationsも削除される
rspec ./spec/models/user_spec.rb:124 # User アソシエーションチェック eventsとのアソシエーション eventsと1対多の関係にある
rspec ./spec/models/user_spec.rb:128 # User アソシエーションチェック eventsとのアソシエーション 関連するeventsがあっても、userを削除でき、eventsも削除される
rspec ./spec/models/user_spec.rb:138 # User accepts_nested_attributes_for userモデルが更新される際、ネストされたauthenticationsの属性も保存する
rspec ./spec/models/user_spec.rb:154 # User メソッドのテスト LINE通知の対象ユーザーを取得する

お伺いしたいこと

config.use_transactional_fixtures = falseにする考え方は合っておりますでしょうか。 その場合、database_cleanerを使って各テスト前後にDBをクリーンにする必要があると考えております。

しかし、実装が複雑になる為、できれば原因をさらに絞り込み、他の手段で解決したいと思っております。 見るポイント、実行するコマンドなどありましたら、アドバイスいただけますと幸いです。

Tsuchiya2 commented 1 minute ago

config.use_transactional_fixtures = falseにする考え方は合っておりますでしょうか。 その場合、database_cleanerを使って各テスト前後にDBをクリーンにする必要があると考えております。 しかし、実装が複雑になる為、できれば原因をさらに絞り込み、他の手段で解決したいと思っております。 見るポイント、実行するコマンドなどありましたら、アドバイスいただけますと幸いです。

一旦、期待している挙動(テストが通る状況)にするためなら、false&database_clanerを使う方法も良いかと思います。

また、上記はlet!で行ったのか、letで行ったのか、両方でも変化が無いのかなどを確認が必要かと思いました。


以下はChatGPTが返してきたテキストの概要の共有になります。

  1. use_transactional_fixtures を false に設定する

    # spec/rails_helper.rb
    RSpec.configure do |config|
    config.use_transactional_fixtures = false
    # その他の設定
    end
  2. テストごとにデータベースをクリーンアップする設定を追加する

    # spec/rails_helper.rb
    RSpec.configure do |config|
    # 上記の設定に加えて
    
    config.before(:suite) do
    # テストスイートの実行前にデータベースをクリーンアップ
    DatabaseCleaner.clean_with(:truncation)
    end
    
    config.before(:each) do
    DatabaseCleaner.strategy = :transaction
    end
    
    config.before(:each, type: :system) do
    DatabaseCleaner.strategy = :truncation
    end
    
    config.before(:each) do
    DatabaseCleaner.start
    end
    
    config.after(:each) do
    DatabaseCleaner.clean
    end
    end
  3. database_cleaner のインストール

    # Gemfile
    group :test do
    gem 'database_cleaner-active_record'
    end
  4. database_cleaner を使わずにデータベースをリセットする方法

    # spec/rails_helper.rb
    RSpec.configure do |config|
    config.use_transactional_fixtures = false
    
    config.before(:each) do
    ActiveRecord::Base.subclasses.each(&:delete_all)
    end
    end