Rails 6.1, Ruby 3.0.0: tests error as they cannot load rexml

I've created a new Rails 6.1 application from scratch with Ruby 3.0.0.

I've run db:create and generated a single model with some string columns, followed by rails db:migrate.

I ran rails test but got this require rexml error:

/Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:34:in `require': cannot load such file -- rexml/document (LoadError)
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `block in require'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:299:in `load_dependency'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/firefox.rb:22:in `<main>'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `block in require'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:299:in `load_dependency'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/webdrivers-4.4.1/lib/webdrivers/geckodriver.rb:72:in `<main>'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `block in require'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:299:in `load_dependency'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/webdrivers-4.4.1/lib/webdrivers.rb:4:in `<main>'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:66:in `block (2 levels) in require'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:61:in `each'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:61:in `block in require'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:50:in `each'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:50:in `require'
  from /Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler.rb:174:in `require'
  from /Users/froop/Rails/froop_app/config/application.rb:7:in `<top (required)>'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application.rb:92:in `require'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application.rb:92:in `preload'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application.rb:157:in `serve'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
  from /Users/froop/.rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>'
  from <internal:/Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
  from <internal:/Users/froop/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
  from -e:1:in `<main>'

I'm not at all sure what's causing this. Rails is up to date. Can anyone point me in the right direction?


rexml gem is a bundled gem since Ruby 3.0.0. So you must add rexml to Gemfile.

On Ruby 2.6 and 2.7, rexml gem is default gem. So default rexml is used if Gemfile does not include rexml. On these versions of ruby, you must add rexml to Gemfile only if you want to use specific rexml version.


To install rexml just paste: gem 'rexml', '~> 3.2', '>= 3.2.4' in Gemfile. You can find it at https://rubygems.org/gems/rexml


Why is it happening now?

Ruby has been going through a process of Gemifying Ruby - breaking up Ruby from a standard library to Gems.

In Ruby 2.7 rexml gem is a 'default gem' which means that it could not be removed and could be required without declaring them as dependencies in Gemfiles.

In Ruby 3.0 rexml gem is a 'bundled gem':

Bundled gems are regular gems that ship with the default Ruby installation. These libraries are maintained outside the Ruby core team and can be uninstalled if necessary. As with other 3rd-party gems, you have to include them into gemspec or gemfile.

Blog article by strzibny - What are default and bundled gems in Ruby anyway?

So, in Ruby 3.0.0 changed to a bundled gem (from being default Gem in 2.7) so if it is used it must be added to the Gemfile.