From 7e0e3abce05cdca0c249cf0acef9b849cae0fd44 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Mon, 1 Apr 2024 19:29:39 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Favor=20`Rails.root`=20to=20ensu?= =?UTF-8?q?re=20correct=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In CI we're seeing this error: ``` LoadError: cannot load such file -- /app/samvera/spec/hyrax-webapp/config/environment ``` The rails_helper is in the /app/samvera/spec directory and then it's trying to load the environment from the hyrax-webapp directory within its current directory. --- spec/rails_helper.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 7d7fcc6..9128b06 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -5,14 +5,17 @@ ENV["RAILS_ENV"] ||= "test" # require File.expand_path('../config/environment', __dir__) -require File.expand_path("hyrax-webapp/config/environment", __dir__) +require Rails.root.join("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" # Add additional requires below this line. Rails is not loaded until this point! require "factory_bot_rails" -FactoryBot.definition_file_paths = [File.expand_path("spec/factories", HykuAddons::Engine.root)] -FactoryBot.find_definitions + +if defined?(HykuAddons) + FactoryBot.definition_file_paths = [File.expand_path("spec/factories", HykuAddons::Engine.root)] + FactoryBot.find_definitions +end # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are