-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Use require_relative
instead of require
with full path
#29417
Use require_relative
instead of require
with full path
#29417
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.
I don't like the redundancy introduced by some of these (ar_tests
, COMPONENT_ROOT
).
I think I also prefer the explicit ./
prefix that you're removing from some lines here, but that's just a minor preference.
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 am fine with the changes.
ar_tests
is the only one where I don't see quite the benefit. Also unsure about
require "cases/helper"
On the other hand COMPONENT_ROOT
is a constant set as
COMPONENT_ROOT = File.expand_path("..", __dir__)
in the bin/test of every Rails component.
Regarding "./", I am totally for removing them because it is redundant. I never write leading dots in relative paths unless needed. For example, I do not write vim ./foo.rb
, I always say vim foo.rb
if foo.rb is in the current directory. When you do not have the cwd in $PATH
then you use a leading dot to run an executable, but that is because it just does not work without it.
Summary, require_relative
takes a path and resolves it relative to __dir__
, the dot is adding no information there.
@@ -10,8 +10,8 @@ def setup | |||
database_config = { "adapter" => "postgresql", "database" => "activerecord_unittest" } | |||
ar_tests = File.expand_path("../../../activerecord/test", __dir__) | |||
if Dir.exist?(ar_tests) | |||
require File.join(ar_tests, "config") | |||
require File.join(ar_tests, "support/config") |
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.
This one is clear to me, so I'd avoid change it
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 agree we should leave as it is.
0fe493a
to
19866ae
Compare
Approved over here. @bogdanvlviv can you rebase please? |
19866ae
to
6673cf7
Compare
@fxn Done. |
@rafaelfranca's feedback and mine are addressed (I saw that loading @matthewd are you cool with the patch? |
Thank you all for the review! ❤️ |
…torage/ Related to rails#29417
@jeremy suggested converting
require
with a full path torequire_relative
. See #29176 (review)After brief discuss with @fxn we decided to do it.
There are four cases i'm not sure about using
require_relative
:rails/activejob/test/support/integration/dummy_app_template.rb
Line 8 in a625292
rails/railties/lib/rails/app_loader.rb
Line 45 in a625292
rails/activerecord/test/cases/migration_test.rb
Lines 11 to 14 in a625292
rails/railties/lib/rails/test_unit/test_requirer.rb
Line 14 in a625292
Related to #29176
r? @fxn, @jeremy