LoginSignup
7
3

More than 3 years have passed since last update.

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

Posted at

背景

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
7
3
0

Register as a new user and use Qiita more conveniently

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