13
  • 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)
ea0723
  • 805
  • 11
  • 25
  • noted several days later setting up a new machine, when I started sidekiq server also caused the issue (not related to rspec tests). Solution below fixed the problem. – ea0723 Aug 07 '20 at 21:31
  • Completely new install of Ruby 2.7.1 same issue... same fix – ea0723 Aug 17 '20 at 02:58

4 Answers4

9

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

ea0723
  • 805
  • 11
  • 25
2
gem update --system

it works for me

zofy29
  • 481
  • 4
  • 5
0

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.

kangkyu
  • 5,252
  • 3
  • 34
  • 36
0

update gem to higher version ,as your version is 2.7

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 26 '23 at 08:48