Skip to content

Use __dir__ for expand_path in rails_helper template #2048

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

Merged
merged 2 commits into from
Dec 18, 2018

Conversation

okuramasafumi
Copy link
Contributor

Ruby 2.0 introduced __dir__ pseudo variable, and we can replace it with __FILE__ for expand_path method.
There is a RuboCop Cop pointing this out.
http://www.rubocop.org/en/latest/cops_style/#styleexpandpatharguments
This change reduces one RuboCop warning after installing rspec-rails.

Ruby 2.0 introduced `__dir__` pseudo variable, and we can replace it with `__FILE__` for `expand_path` method.
There is a RuboCop Cop pointing this out.
http://www.rubocop.org/en/latest/cops_style/#styleexpandpatharguments
This change reduces one RuboCop warning after installing rspec-rails.
Copy link
Member

@JonRowe JonRowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Thanks for taking the time to introduce this. rspec-rails still supports Ruby 1.9.x for older versions of Rails, so for us to merge this it'll have to be gated by a check for Ruby version.

<% if RUBY_VERSION >= '2.0.0' %>
require File.expand_path('../config/environment', __dir__)
<% else %>
require File.expand_path('../../config/environment', __FILE__)
<% end %>

This will produce the right snippet into the generated file for each version.

Use `__FILE__` otherwise so that the gem can support ruby 1.9.3 and lower.
@JonRowe JonRowe merged commit 30820f4 into rspec:master Dec 18, 2018
@okuramasafumi okuramasafumi deleted the patch-1 branch December 18, 2018 09:23
JonRowe added a commit that referenced this pull request Dec 18, 2018
benoittgt pushed a commit to benoittgt/rspec-rails that referenced this pull request May 1, 2019
* Use __dir__ for expand_path in rails_helper template

Ruby 2.0 introduced `__dir__` pseudo variable, and we can replace it with `__FILE__` for `expand_path` method.
There is a RuboCop Cop pointing this out.
http://www.rubocop.org/en/latest/cops_style/#styleexpandpatharguments
This change reduces one RuboCop warning after installing rspec-rails.

* Use `__dir__` only when RUBY_VERSION >= 2.0

Use `__FILE__` otherwise so that the gem can support ruby 1.9.3 and lower.
benoittgt pushed a commit to benoittgt/rspec-rails that referenced this pull request May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants