Last active
July 18, 2019 00:32
-
-
Save masa-nakano/e4a65eb0ddd9d4d22a5e1576757cf4f2 to your computer and use it in GitHub Desktop.
rubocopのConventionからexpand_path、__FILE__、__dir__を理解する ref: https://qiita.com/msy-naka/items/43c70e470a63f82b53a7
This file contains 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
$ bundle exec rubocop | |
〜省略〜 | |
spec/rails_helper.rb:4:14: C: Style/ExpandPathArguments: Use expand_path('../config/environment', __dir__) instead of expand_path('../../config/environment', __FILE__). | |
require File.expand_path('../../config/environment', __FILE__) | |
^^^^^^^^^^^ | |
〜省略〜 |
This file contains 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
{app_dir} | |
├── config | |
│ ├── environment.rb # ←ここを参照しようとしている | |
├── spec # 実行されるカレントディレクトリ | |
│ ├── rails_helper.rb # ←ここから |
This file contains 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
$ cd spec/ | |
$ pry | |
[1] pry(main)> File.expand_path('../../config/environment', __FILE__) | |
=> "/Users/XXX/app/{app_dir}/config/environment" | |
[2] pry(main)> File.expand_path('../config/environment', __dir__) | |
=> "/Users/XXX/app/{app_dir}/config/environment" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment