1
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

Rails 6.1にあげたらundefined method `file_fixture_path' for FactoryBot::SyntaxRunner:Classになりましたとさ

背景

Rails のバージョンを 6.0 系から 6.1 系にあげた時にspecが大量にfailした

       Failure/Error: sample_image { fixture_file_upload("fixtures/sample.png") }

       NoMethodError:
         undefined method `file_fixture_path' for FactoryBot::SyntaxRunner:Class
       # ./spec/factories/**.rb:**:in `block (3 levels) in <main>'

確認

Railsのリリースノートを確認すると以下の記述を発見。
どうやらfixture_file_uploadedの利用する*_pathが変更されたらしい
https://github.com/rails/rails/releases/tag/v6.1.0
スクリーンショット 2021-02-03 16.08.35.png

ファイルが見つかりませんではなく NoMethodError が出ていた背景を見るとFactoryBot内部でfile_fixture_pathが解決できていない
↓RailsのPRはこちら
https://github.com/rails/rails/pull/39086

対処

rails_helper.rbActiveSupport::Testing::FileFixtures を includeすることで解決できました。

FactoryBot::SyntaxRunner.class_eval do
  include ActionDispatch::TestProcess
  include ActiveSupport::Testing::FileFixtures
end
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
1
Help us understand the problem. What are the problem?