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
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:
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
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
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