8
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

rails7.2から`TestFixtures#fixture_path`が廃止されるためrails 7.1では`DEPRECATION WARNING: TestFixtures#fixture_path is deprecated`が発生する

Posted at

発生する理由

rspec_helper.rbの中で以下のようにfixture_pathを指定してテストケースで参照している場合にDEPRECATION WARNINGが発生します。

rspec_helper.rb
config.fixture_path = Rails.root.join('spec/fixtures')
spec/sample_spec.rb
Rack::Test::UploadedFile.new("#{fixture_path}/test.txt")

DEPRECATION WARNING

DEPRECATION WARNING: TestFixtures#fixture_path is deprecated and will be removed in Rails 7.2. Use #fixture_paths instead.  If multiple fixture paths have been configured with #fixture_paths, then #fixture_path will just return the first path.

rails 7.2からTestFixtures#fixture_pathが廃止されるため代わりに#fixture_pathsを使用する必要があるとのことです。

対応

rspec-rails

bundleされているrailsのバージョンが7.1以上の場合はfixture_pathsがconfigに設定可能になる様なので以下のコミットが含まれたバージョンがリリースされたらrspec-railsを更新します。

前述したテストファイルを以下の様に修正します。

rspec_helper.rb
- config.fixture_path = Rails.root.join('spec/fixtures')
+ config.fixture_paths = [
+   Rails.root.join('spec/fixtures')
+ ]
- Rack::Test::UploadedFile.new("#{fixture_path}/test.txt")
+ Rack::Test::UploadedFile.new("#{fixture_paths.first}/test.txt")
8
1
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
8
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?