Skip to content

Commit

Permalink
Merge pull request #2528 from jdufresne/rel
Browse files Browse the repository at this point in the history
Prefer require_relative to avoid calculating relative paths
  • Loading branch information
JonRowe committed Oct 26, 2021
2 parents 3f0e350 + 86565b9 commit 3a496b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
@@ -1,7 +1,7 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
require_relative '../config/environment'
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
Expand Down
14 changes: 14 additions & 0 deletions spec/generators/rspec/install/install_generator_spec.rb
Expand Up @@ -19,6 +19,10 @@ def maintain_test_schema
match(/ActiveRecord::Migration\.maintain_test_schema!/m)
end

def require_rails_environment
match(/^require_relative '\.\.\/config\/environment'$/m)
end

def require_rspec_rails
match(/^require 'rspec\/rails'$/m)
end
Expand Down Expand Up @@ -62,6 +66,11 @@ def filter_rails_from_backtrace
end

context "generates spec/rails_helper.rb" do
specify "requiring Rails environment" do
run_generator
expect(rails_helper).to require_rails_environment
end

specify "requiring rspec/rails" do
run_generator
expect(rails_helper).to require_rspec_rails
Expand Down Expand Up @@ -99,6 +108,11 @@ def filter_rails_from_backtrace
hide_const("ActiveRecord")
end

specify "requiring Rails environment" do
run_generator
expect(rails_helper).to require_rails_environment
end

specify "requiring rspec/rails" do
run_generator
expect(rails_helper).to require_rspec_rails
Expand Down

0 comments on commit 3a496b0

Please sign in to comment.