You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This may be in consideration of platforms that do not use /, such as Windows, but since Rails.root.join is joined with File::SEPARATOR (/), both writing styles return the same result separated by slashes.
The Windows path separator can also be interpreted, so it will work as intended but will not be significant. Wouldn't it be preferable to adopt the rubocop-rails default and write Rails.root.join('foo/bar/baz') for the same behavior? (Otherwise rubocop will still warn)
Examples
Environment
rails (7.0.4)
rspec-core (3.12.0)
rspec-rails (6.0.1)
rubocop-rspec (2.15.0)
rubocop-rails (2.17.3)
Behavior of Rails.root.join under Windows
C:\Users\test\sample>systeminfo
...
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.19044 N/A Build 19044
...
C:\Users\test\sample>ruby -v
ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x64-mingw-ucrt]
C:\Users\test\sample>rails c
Loading development environment (Rails 7.0.4)
irb(main):001:0> p Rails.root
#<Pathname:C:/Users/test/sample>
=> #<Pathname:C:/Users/test/sample>
irb(main):002:0> p Rails.root.join('foo/bar')
#<Pathname:C:/Users/test/sample/foo/bar>
=> #<Pathname:C:/Users/test/sample/foo/bar>
irb(main):003:0> p Rails.root.join('foo', 'bar')
#<Pathname:C:/Users/test/sample/foo/bar>
=> #<Pathname:C:/Users/test/sample/foo/bar>
Windows path separators can be mixed (and still work fine)
irb(main):004:0> p Pathname.new(ENV['TMP']).join('foo', 'bar')
#<Pathname:C:\Users\test\AppData\Local\Temp/foo/bar>
=> #<Pathname:C:\Users\test\AppData\Local\Temp/foo/bar>
In Pull Request #2640, it was commented to use multiple strings instead of slashes for
Rails.root.join
, but rubocop-rails defaults to using slashes.This may be in consideration of platforms that do not use
/
, such as Windows, but sinceRails.root.join
is joined withFile::SEPARATOR (/)
, both writing styles return the same result separated by slashes.The Windows path separator can also be interpreted, so it will work as intended but will not be significant. Wouldn't it be preferable to adopt the rubocop-rails default and write
Rails.root.join('foo/bar/baz')
for the same behavior? (Otherwise rubocop will still warn)Examples
Environment
Behavior of Rails.root.join under Windows
Windows path separators can be mixed (and still work fine)
Result for rubocop
The text was updated successfully, but these errors were encountered: