Skip to content

Commit 3a496b0

Browse files
authored
Merge pull request #2528 from jdufresne/rel
Prefer require_relative to avoid calculating relative paths
2 parents 3f0e350 + 86565b9 commit 3a496b0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is copied to spec/ when you run 'rails generate rspec:install'
22
require 'spec_helper'
33
ENV['RAILS_ENV'] ||= 'test'
4-
require File.expand_path('../config/environment', __dir__)
4+
require_relative '../config/environment'
55
# Prevent database truncation if the environment is production
66
abort("The Rails environment is running in production mode!") if Rails.env.production?
77
require 'rspec/rails'

spec/generators/rspec/install/install_generator_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ def maintain_test_schema
1919
match(/ActiveRecord::Migration\.maintain_test_schema!/m)
2020
end
2121

22+
def require_rails_environment
23+
match(/^require_relative '\.\.\/config\/environment'$/m)
24+
end
25+
2226
def require_rspec_rails
2327
match(/^require 'rspec\/rails'$/m)
2428
end
@@ -62,6 +66,11 @@ def filter_rails_from_backtrace
6266
end
6367

6468
context "generates spec/rails_helper.rb" do
69+
specify "requiring Rails environment" do
70+
run_generator
71+
expect(rails_helper).to require_rails_environment
72+
end
73+
6574
specify "requiring rspec/rails" do
6675
run_generator
6776
expect(rails_helper).to require_rspec_rails
@@ -99,6 +108,11 @@ def filter_rails_from_backtrace
99108
hide_const("ActiveRecord")
100109
end
101110

111+
specify "requiring Rails environment" do
112+
run_generator
113+
expect(rails_helper).to require_rails_environment
114+
end
115+
102116
specify "requiring rspec/rails" do
103117
run_generator
104118
expect(rails_helper).to require_rspec_rails

0 commit comments

Comments
 (0)