Expand file_fixture_path against Rails.root#2902
Open
hammadxcm wants to merge 1 commit into
Open
Conversation
The configured `file_fixture_path` default is the relative string `spec/fixtures/files`. When this is assigned to example groups it stays relative, but `ActiveSupport::TestCase` and downstream consumers (e.g. ActionMailer's `read_fixture`) expect an absolute path. Expand the configured value against `Rails.root` in `FileFixtureSupport` before assigning it to example groups and `ActiveStorage::FixtureSet`. `File.expand_path` is a no-op on already-absolute paths, so user-supplied absolute overrides pass through unchanged. Fixes rspec#2682.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2682.
Problem
The configured default
file_fixture_pathis the relative string'spec/fixtures/files'(lib/rspec/rails/configuration.rb:84). When applied to example groups viaFileFixtureSupport, it stays relative. ButActiveSupport::TestCase(and downstream consumers such as ActionMailer'sread_fixture) treatfile_fixture_pathas absolute — they hand it directly toPathname.new/File.joinexpecting a rooted path.Issue reporter @jasonkarns hit this while fixing
read_fixtureand noted that all Rails-side defaults forfile_fixture_pathare absolute (either viaFile.expand_path(__dir__)orRails.root.join(...)).Fix
Expand the configured value against
Rails.rootinFileFixtureSupport.includedbefore assigning it to the example group and toActiveStorage::FixtureSet.File.expand_pathis a no-op on already-absolute paths, so users who override the config with an absolute path see no behavioural change.The user-facing config default (
config.file_fixture_path = 'spec/fixtures/files') is intentionally left as the relative form — that's the conventional value people write inRSpec.configureand matches what documentation references. Only the value that gets exposed to example groups becomes absolute.Tests
New spec
spec/rspec/rails/file_fixture_support_spec.rbcovers three cases:Rails.root.ActiveStorage::FixtureSet.file_fixture_pathreceives the expanded value.Test plan
bundle exec rspec spec/rspec/rails/file_fixture_support_spec.rb— 3/3 passbundle exec rspec spec/rspec/rails/configuration_spec.rb spec/rspec/rails/fixture_support_spec.rb— 67/67 passbundle exec rubocopon changed files — clean