-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add fixture_paths configuration setting #2673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this, I'd like to see the config conditionally defined, and the old option should use the new one and issue a deprecation via our mechanism (this is configurable as to errors and silencing) this would also then simplify the usage.
afaf749
to
f1afa0c
Compare
Thanks for the suggestions @JonRowe! I wasn't aware of the deprecation mechanism. Some tests are failing in EDIT: It failed in the CI as well, not sure why it's green: https://github.com/rspec/rspec-rails/actions/runs/4763638250/jobs/8468212157?pr=2673 |
Fixed the failing spec and added new checks here: b64a9a4 I tried removing the module RSpec
module Rails
# @private
module FixtureFileUploadSupport
include ActionDispatch::TestProcess if defined?(ActionDispatch::TestProcess)
end
end
end My understanding is that For reference, Rails sets the default file fixture path here: https://github.com/rails/rails/blob/6f6a04f8781d03261b5cbc1d8b65ebb43311f2a4/railties/lib/rails/test_help.rb#L28 |
elsif respond_to?(:fixture_paths) | ||
(RSpec.configuration.fixture_paths&.first || '').to_s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that respond_to?(:file_fixture_path)
is false
in Rails 7.1+?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. This module is included in TestCase
: https://github.com/rails/rails/blob/b72b7c35dd9506b08ed040594bbd4536139e6d3f/activesupport/lib/active_support/testing/file_fixtures.rb#L16
But it could be set to nil
explicitly if somebody decides to do Rspec.configure { |config| config.file_fixture_path = nil }
or self.file_fixture_path = nil
in a test case. But in that case, I'm not sure why the wrapper should return a default value. Maybe I'm missing something here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Rails not support multiple paths here? Seems odd they would allow multiple paths for fixtures but not for files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is weird indeed, but I could not find any reference to a plural method in their codebase. Here the author of the change mentions that it is something that they might wanna do in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Rails solely configure this with file_fixture_path directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so: https://github.com/search?q=repo%3Arails%2Frails%20file_fixture_path&type=code
It defaults to "#{Rails.root}/test/fixtures/files"
most of the time and you can overwrite that config. Rails does not use any of the configured fixture_paths
to build the file_fixture_path
. Althought the first of the fixture paths is "#{Rails.root}/test/fixtures"
by default, I think that relation is not enforced.
Co-authored-by: Phil Pirozhkov <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
@pirj @JonRowe made the last couple of fixes. I believe this is ready to merge. Would you consider a PR to simplify |
It looks sleek. WDYT of doing this in a separate PR? |
I believe that change is not completely related to the Rails deprecation addressed here so better to keep it separately and merge this one as it is. But I can add an extra commit here as well. I'll follow your advice on this. |
Thanks for the work on this and apologies for the delay, I've merged this manually 🎉 |
Released in 6.1.0 |
Hello I noticed a side effect with that. I you still have config.fixture_path = ["#{::Rails.root}/spec/fixtures"] or config.fixture_path = "#{::Rails.root}/spec/fixtures" In my case I add duplicated rspec output. At the beginning
At the end
I had not this in 6.0.4. I think the deprecation should mention that we should use |
ActiveRecord::TestFixtures#fixture_path
was deprecated by Rails in 7.1 and will be removed from version 7.2.#2664 fixed the deprecation message. Here a new setting is added to the config to allow multiple paths.