[RAILS] What to do if Failure / Error: require File.expand_path ('../ config / environment', __dir__) appears in RSpec

what's happened

When I ran the test with the rspec command, I suddenly got an error like the title, even though I was able to run it without any problems. As a result, I found out that it was due to bundle update. As a person who casually did a bundle update, I felt like "I got an error even though I didn't do anything".

Below is the result output when the rspec command is executed

$ rspec spec/models/task_spec.rb 
 
 An error occurred while loading ./spec/models/task_spec.rb.
 Hint: Install the `did_you_mean` gem in order to provide suggestions for similarly named files.
 Failure/Error: require File.expand_path('../config/environment', __dir__)
 
 LoadError:
   cannot load such file -- public_suffix
 # ./config/application.rb:7:in `<top (required)>'
 # ./config/environment.rb:2:in `require_relative'
 # ./config/environment.rb:2:in `<top (required)>'
 # ./spec/rails_helper.rb:5:in `<top (required)>'
 # ./spec/models/task_spec.rb:1:in `<top (required)>'
 No examples found.
 
 Finished in 0.00005 seconds (files took 1.39 seconds to load)
 0 examples, 0 failures, 1 error occurred outside of examples

Solutions

I will write the solution first The problem with this error is the version of the library As it says cannot load such file --public_suffix, the library called public_suffix cannot be loaded because of the version. In my case it was public_suffix (4.0.6) at the time of the error Looking at the previous commit without any error, it was public_suffix (4.0.5), so change from Gemfile.lock to public_suffix (4.0.6)public_suffix (4.0.5) Run bundle install

When I run the test with rspec again

$ rspec spec/models/task_spec.rb 
 
 An error occurred while loading ./spec/models/task_spec.rb.
 Hint: Install the `did_you_mean` gem in order to provide suggestions for similarly named files.
 Failure/Error: require 'rspec/rails'
 
 LoadError:
   cannot load such file -- minitest/assertions
 # ./spec/rails_helper.rb:8:in `<top (required)>'
 # ./spec/models/task_spec.rb:1:in `<top (required)>'
 No examples found.
 
 Finished in 0.00013 seconds (files took 2.54 seconds to load)
 0 examples, 0 failures, 1 error occurred outside of examples

And I got an error again, but I will fix the version of cannot load such file --minitest / assertions and minitest in the same way as public_suffix. In my case, I changed it from minitest (5.14.2) to minitest (5.14.1) Also bundle install and run rspec

$ rspec spec/models/task_spec.rb 
 
 Task
Hoge 2
 
 Finished in 0.00808 seconds (files took 1.99 seconds to load)
 1 example, 0 failures

Passed! Fixed: joy:

What I did to solve the cause

Below, I will write why this error occurred and what kind of search I tried to solve.

The essence of the problem is not Failure / Error: require File.expand_path ('../ config / environment', __dir__), but cannot load such file --public_suffix I have a library called public_suffix, but the problem was that it wasn't loaded. Just look at Gemfile.lock and it's installed. So is the version different? I came up with the idea and solved it

At first, I thought it was an error and searched for Failure / Error: require File.expand_path ('../ config / environment', __dir__). Therefore, it is included in the title. However, searching did not solve the problem, I only knew that it was not a problem on the rspec side.

Even if I introduced rspec again from the initial project with rails new, the error did not disappear, so it was clear from this that it was not a problem with rspec.

After struggling for about 6 hours, I realized that Failure / Error: require File.expand_path ('../ config / environment', __dir__) was a side effect of the essential problem, so Load Error: cannot load such file- --I realized that public_suffix is the essence of the error I didn't know that public_suffix was a library, so I thought it was an error, which is why it took a long time to resolve. After that, I searched Gemfile.lock with public_suffix and noticed that the version was different compared to the previous commit, so I returned it and it was fixed.

By the way, searching for Failure / Error: require File.expand_path ('../ config / environment', __dir__) did not solve the problem, so I wrote this article for those who got the same error. Tata

Lesson

Let's quit the innocent bundle update! The cause of the error was a change in the version of the library, so if you suddenly get an error, suspect the version. In the first place, I did not understand the behavior around bundle, and it was the worst element that I used somehow. I had a pain in the bundle so I studied in this article https://qiita.com/lasershow/items/1a048d03ddaaba98171e

appendix

Gemfile and Gemfile.lock which fixed the versions of public_suffix and minitest so that rspec works.

Gemfile


ruby '2.6.5'
 gem 'bootstrap', '4.5.2'
 gem 'slim-rails', '3.2.0'
 gem 'html2slim', '0.2.0'
 gem 'enum_help', '0.0.17'
 
 gem 'rails', '~> 6.0.1'
 gem 'pg', '>= 0.18', '< 2.0'
 gem 'puma', '~> 4.1'
 gem 'sass-rails', '>= 6'
 gem 'webpacker', '~> 4.0'
 gem 'turbolinks', '~> 5'
 gem 'jbuilder', '~> 2.7'
 gem 'bootsnap', '>= 1.4.2'
 
 group :development, :test do
   gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
 end
 
 group :development do
   gem 'web-console', '>= 3.3.0'
   gem 'listen', '>= 3.0.5', '< 3.2'
   gem 'spring'
   gem 'spring-watcher-listen', '~> 2.0.0'
 end
 
 group :test do
   gem 'capybara', '>= 2.15'
   gem 'selenium-webdriver'
   gem 'webdrivers'
   gem 'rspec-rails', '< 4.0.0'
 end
 
 gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    actioncable (6.0.3.4)
      actionpack (= 6.0.3.4)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
    actionmailbox (6.0.3.4)
      actionpack (= 6.0.3.4)
      activejob (= 6.0.3.4)
      activerecord (= 6.0.3.4)
      activestorage (= 6.0.3.4)
      activesupport (= 6.0.3.4)
      mail (>= 2.7.1)
    actionmailer (6.0.3.4)
      actionpack (= 6.0.3.4)
      actionview (= 6.0.3.4)
      activejob (= 6.0.3.4)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 2.0)
    actionpack (6.0.3.4)
      actionview (= 6.0.3.4)
      activesupport (= 6.0.3.4)
      rack (~> 2.0, >= 2.0.8)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.2.0)
    actiontext (6.0.3.4)
      actionpack (= 6.0.3.4)
      activerecord (= 6.0.3.4)
      activestorage (= 6.0.3.4)
      activesupport (= 6.0.3.4)
      nokogiri (>= 1.8.5)
    actionview (6.0.3.4)
      activesupport (= 6.0.3.4)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.1, >= 1.2.0)
    activejob (6.0.3.4)
      activesupport (= 6.0.3.4)
      globalid (>= 0.3.6)
    activemodel (6.0.3.4)
      activesupport (= 6.0.3.4)
    activerecord (6.0.3.4)
      activemodel (= 6.0.3.4)
      activesupport (= 6.0.3.4)
    activestorage (6.0.3.4)
      actionpack (= 6.0.3.4)
      activejob (= 6.0.3.4)
      activerecord (= 6.0.3.4)
      marcel (~> 0.3.1)
    activesupport (6.0.3.4)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 0.7, < 2)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
      zeitwerk (~> 2.2, >= 2.2.2)
    addressable (2.7.0)
      public_suffix (>= 2.0.2, < 5.0)
    autoprefixer-rails (10.0.1.0)
      execjs
    bindex (0.8.1)
    bootsnap (1.4.8)
      msgpack (~> 1.0)
    bootstrap (4.5.2)
      autoprefixer-rails (>= 9.1.0)
      popper_js (>= 1.14.3, < 2)
      sassc-rails (>= 2.0.0)
    builder (3.2.4)
    byebug (11.1.3)
    capybara (3.33.0)
      addressable
      mini_mime (>= 0.1.3)
      nokogiri (~> 1.8)
      rack (>= 1.6.0)
      rack-test (>= 0.6.3)
      regexp_parser (~> 1.5)
      xpath (~> 3.2)
    childprocess (3.0.0)
    concurrent-ruby (1.1.7)
    crass (1.0.6)
    diff-lcs (1.4.4)
    enum_help (0.0.17)
      activesupport (>= 3.0.0)
    erubi (1.9.0)
    execjs (2.7.0)
    ffi (1.13.1)
    globalid (0.4.2)
      activesupport (>= 4.2.0)
    hpricot (0.8.6)
    html2slim (0.2.0)
      hpricot
    i18n (1.8.5)
      concurrent-ruby (~> 1.0)
    jbuilder (2.10.1)
      activesupport (>= 5.0.0)
    listen (3.1.5)
      rb-fsevent (~> 0.9, >= 0.9.4)
      rb-inotify (~> 0.9, >= 0.9.7)
      ruby_dep (~> 1.2)
    loofah (2.7.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    mail (2.7.1)
      mini_mime (>= 0.1.1)
    marcel (0.3.3)
      mimemagic (~> 0.3.2)
    method_source (1.0.0)
    mimemagic (0.3.5)
    mini_mime (1.0.2)
    mini_portile2 (2.4.0)
    minitest (5.14.1)
    msgpack (1.3.3)
    nio4r (2.5.4)
    nokogiri (1.10.10)
      mini_portile2 (~> 2.4.0)
    pg (1.2.3)
    popper_js (1.16.0)
    public_suffix (4.0.5)
    puma (4.3.6)
      nio4r (~> 2.0)
    rack (2.2.3)
    rack-proxy (0.6.5)
      rack
    rack-test (1.1.0)
      rack (>= 1.0, < 3)
    rails (6.0.3.4)
      actioncable (= 6.0.3.4)
      actionmailbox (= 6.0.3.4)
      actionmailer (= 6.0.3.4)
      actionpack (= 6.0.3.4)
      actiontext (= 6.0.3.4)
      actionview (= 6.0.3.4)
      activejob (= 6.0.3.4)
      activemodel (= 6.0.3.4)
      activerecord (= 6.0.3.4)
      activestorage (= 6.0.3.4)
      activesupport (= 6.0.3.4)
      bundler (>= 1.3.0)
      railties (= 6.0.3.4)
      sprockets-rails (>= 2.0.0)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.3.0)
      loofah (~> 2.3)
    railties (6.0.3.4)
      actionpack (= 6.0.3.4)
      activesupport (= 6.0.3.4)
      method_source
      rake (>= 0.8.7)
      thor (>= 0.20.3, < 2.0)
    rake (13.0.1)
    rb-fsevent (0.10.4)
    rb-inotify (0.10.1)
      ffi (~> 1.0)
    regexp_parser (1.8.1)
    rspec-core (3.9.3)
      rspec-support (~> 3.9.3)
    rspec-expectations (3.9.2)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.9.0)
    rspec-mocks (3.9.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.9.0)
    rspec-rails (3.9.1)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 3.9.0)
      rspec-expectations (~> 3.9.0)
      rspec-mocks (~> 3.9.0)
      rspec-support (~> 3.9.0)
    rspec-support (3.9.3)
    ruby_dep (1.5.0)
    rubyzip (2.3.0)
    sass-rails (6.0.0)
      sassc-rails (~> 2.1, >= 2.1.1)
    sassc (2.4.0)
      ffi (~> 1.9)
    sassc-rails (2.1.2)
      railties (>= 4.0.0)
      sassc (>= 2.0)
      sprockets (> 3.0)
      sprockets-rails
      tilt
    selenium-webdriver (3.142.7)
      childprocess (>= 0.5, < 4.0)
      rubyzip (>= 1.2.2)
    slim (4.1.0)
      temple (>= 0.7.6, < 0.9)
      tilt (>= 2.0.6, < 2.1)
    slim-rails (3.2.0)
      actionpack (>= 3.1)
      railties (>= 3.1)
      slim (>= 3.0, < 5.0)
    spring (2.1.1)
    spring-watcher-listen (2.0.1)
      listen (>= 2.7, < 4.0)
      spring (>= 1.2, < 3.0)
    sprockets (4.0.2)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.2.2)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    temple (0.8.2)
    thor (1.0.1)
    thread_safe (0.3.6)
    tilt (2.0.10)
    turbolinks (5.2.1)
      turbolinks-source (~> 5.2)
    turbolinks-source (5.2.0)
    tzinfo (1.2.7)
      thread_safe (~> 0.1)
    web-console (4.0.4)
      actionview (>= 6.0.0)
      activemodel (>= 6.0.0)
      bindex (>= 0.4.0)
      railties (>= 6.0.0)
    webdrivers (4.4.1)
      nokogiri (~> 1.6)
      rubyzip (>= 1.3.0)
      selenium-webdriver (>= 3.0, < 4.0)
    webpacker (4.3.0)
      activesupport (>= 4.2)
      rack-proxy (>= 0.6.1)
      railties (>= 4.2)
    websocket-driver (0.7.3)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)
    xpath (3.2.0)
      nokogiri (~> 1.8)
    zeitwerk (2.4.0)

PLATFORMS
  ruby

DEPENDENCIES
  bootsnap (>= 1.4.2)
  bootstrap (= 4.5.2)
  byebug
  capybara (>= 2.15)
  enum_help (= 0.0.17)
  html2slim (= 0.2.0)
  jbuilder (~> 2.7)
  listen (>= 3.0.5, < 3.2)
  pg (>= 0.18, < 2.0)
  puma (~> 4.1)
  rails (~> 6.0.1)
  rspec-rails (< 4.0.0)
  sass-rails (>= 6)
  selenium-webdriver
  slim-rails (= 3.2.0)
  spring
  spring-watcher-listen (~> 2.0.0)
  turbolinks (~> 5)
  tzinfo-data
  web-console (>= 3.3.0)
  webdrivers
  webpacker (~> 4.0)

RUBY VERSION
   ruby 2.6.5p114

BUNDLED WITH
   2.1.4

Recommended Posts

What to do if Failure / Error: require File.expand_path ('../ config / environment', __dir__) appears in RSpec
What to do if you get a DISPLAY error in gym.render ()
What to do if build from command line fails in Android development environment
What to do if an ActionController :: UnknownFormat error occurs
What to do if password authentication fails in Docker/Postgres
What to do if you get a wrong number of arguments error in binding.pry
What to do if you get an Argument Error: wrong number of arguments (given 2, expected 0) in your RSpec test
[Rails / Maybe it can be applied to other things? ] What to do if failure / error __send__ (method file) rspec cannnot road such file appears when executing RSpec
What to do if mysql2 gets a bundle install error
[Rails] What to do if you accidentally install bundle in the production environment in your local environment
What to do when a could not find driver appears when connecting to a DB in a Docker environment
What to do if you get a "302" error in your controller unit test code in Rails
What to do if you get an error in Basic authentication during Rails test code
[Rails] What to do if data is not registered in DB
[Programming beginner] What to do when rails s becomes an error in the local development environment
What to do if you get a "Mysql2 :: Error: Operand should contain 1 column (s)" error in Rails
What to do if Cloud9 is full in the Rails tutorial
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do if you get an [An HTTP request took too long to complete.] Error in Docker.
What to do if you forget the root password in CentOS7
What to do if an error occurs when doing npm install axios in React + Typescript project
What to do if you get an error with bundle install by entering gem'bcrypt' in your Gemfile
What to do if the image posted by refile disappears after setting a 404 error page in Rails
What to do if you get a groovy warning in Thymeleaf Layout
Add gem'rails-i18n','~> 6.0.0' and what to do if bundle install gives an error
What to do if you get an error during rails db: reset
What to do if the prefix c is not bound in JSP
What to do if you get an uninitialized constant Likes Controller error
What to do when Blocked Host: "host name" appears in Ruby on Rails
What to do and how to install when an error occurs in DXRuby 1.4.7
What to do if an error occurs when nokogiri enters when bundle install
no space left on device What to do if an error occurs
What to do if tomcat process remains when tomcat is stopped in eclipse
What to do if you get an error when you hit Heroku logs
What to do if you install Ubuntu
What to do if Command line is too long appears when building a gradle project in Intellij IDEA
How to translate the error message into Japanese (What to do if you cannot log in for some reason)
What to do if you get a SQLite3 :: BusyException: database is locked error
What to do if you get the error message unrecognized selector send to instance "***"
What to do if the changes are not reflected in the jar manifest file
wildflly10 java8 ERROR [org.jboss.jca.core.tx.jbossts.XAResourceRecoveryImpl] (Periodic Recovery) IJ000906 What to do if an error occurs
What to do if you get an error on heroku rake db: migrate
What to do if ffi installation fails when launching an application in Rails
[Java] What to do if you get an error in Eclipse saying "Not allowed at source level below 1.X"
What to do if the server tomcat dies
What to do if you push incorrect information
What to do when IllegalStateException occurs in PlayFramework
What to do if you can't get the text of an element in Selenium
What to do if you get the error Couldn't find Item without an ID
What to do if you get a port error when docker-compose up on Mac
What to do when an error (StandardError: An error has occurred, this and all later migrations canceled:) appears in rails db: migrate
<Dot installation> What to do if you cannot proceed due to an error when building a development environment for Rails learning.
What to do if the debug gem installation fails
What to do if the Rails server can't start
What to do if you accidentally create a model
What to do when a null byte error occurs
Error ExecJS :: RuntimeUnavailable: What to do when it occurs
What to do if you get a "Cannot Pull Container Error" when starting ECS ​​Fargate
What to do if a SAX Parser error occurs when using Liferay 7 / DXP on AWS
[Rails] What to do if you can't get an error message with the errors method
What to do if Could not find hoge in any of the sources Run `bundle install` to install missing gems. Appears in the docker container