• using Rails 5.2.4.3
  • Mac OSX Catalina 10.15.6

After updating ruby to 2.7.1 (via rvm) ran rspec spec and received error:

Trying to register Bundler::GemfileError for status code 4 but Bundler::GemfileError is already registered
    # /Users/----/.rvm/gems/ruby-2.7.1@xmx/gems/bundler-2.1.4/lib/bundler.rb:7:in `require_relative'
    # /Users/----/.rvm/gems/ruby-2.7.1@xmx/gems/bundler-2.1.4/lib/bundler.rb:7:in `<top (required)>'
    # ./config/boot.rb:4:in `require'
    # ./config/boot.rb:4:in `<top (required)>'
    # ./config/application.rb:1:in `require'
    # ./config/application.rb:1:in `<top (required)>'
    # ./config/environment.rb:2:in `require_relative'
    # ./config/environment.rb:2:in `<top (required)>'
    # ./spec/spec_helper.rb:18:in `require'
    # ./spec/spec_helper.rb:18:in `<top (required)>'
    # ./spec/models/activation_spec.rb:1:in `require'
    # ./spec/models/activation_spec.rb:1:in `<top (required)>
  • switching to global gemset resolved the issue, but using default gemset continued to throw the error.
  • uninstalling and reinstalling bundler did not solve the issue (ensured bundler v 2.1.4)
  • I could run by using bundle exec rspec spec (but wanted to actually solve the problem)
4

There are 4 answers

0
ea0723 On BEST ANSWER

A lot of the discussions I found on this error were pretty old. Then, finally stumbled upon this recent github discussion:

Running the following solved my issue:

gem update --system 3.0.8 && gem update --system

Note: To run update without installing documentation

gem update --system 3.0.8 --no-document && gem update --system --no-document

1
Gaurav Rathor On

update gem to higher version ,as your version is 2.7

0
zofy29 On
gem update --system

it works for me

0
kangkyu On

In my case I came to this page because of the same error on Github Actions workflow. And the fix gem update --system 3.1.2 && gem update --system (for Ruby 2.7.6) was not enough.

The sample workflow yaml file has following lines,

- name: Install Ruby and gems
  uses: ruby/setup-ruby@v1
  with:
    bundler-cache: true

which installs Ruby and gems together. I was able to get out of this error by removing bundler-cache: true and running bundle install over again.

- name: Install Ruby and gems
  uses: ruby/setup-ruby@v1
  with:
    ruby-version: 2.7.6
- name: Upgrade rubygems and reinstall gems
  run: |
    gem update --system 3.1.2 && gem update --system
    gem update bundler
    bundle install

Then my rspec test passed without error.