Skip to content
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

Prefer require_relative to avoid calculating relative paths #2528

Merged
merged 1 commit into from Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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