Skip to content

Commit 30820f4

Browse files
okuramasafumiJonRowe
authored andcommitted
Use __dir__ for expand_path in rails_helper template (#2048)
* 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.
1 parent 8c3a238 commit 30820f4

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/generators/rspec/install/templates/spec/rails_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# This file is copied to spec/ when you run 'rails generate rspec:install'
22
require 'spec_helper'
33
ENV['RAILS_ENV'] ||= 'test'
4+
<% if RUBY_VERSION >= '2.0.0' %>
5+
require File.expand_path('../config/environment', __dir__)
6+
<% else %>
47
require File.expand_path('../../config/environment', __FILE__)
8+
<% end %>
59
# Prevent database truncation if the environment is production
610
abort("The Rails environment is running in production mode!") if Rails.env.production?
711
require 'rspec/rails'

0 commit comments

Comments
 (0)