Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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