Skip to content

Ruby 3: LoadError: cannot load such file -- rexml/document #2436

@dennyluan

Description

@dennyluan

What Ruby, Rails and RSpec versions are you using?

Ruby version: 3.0.0
Rails version: 6.1.0
RSpec version: 3.10
MacOS big sur

Observed behaviour

On a fresh Rails 6.1 app with Ruby 3.0.0, rake spec fails to run any tests with the error:

» rake spec
/Users/dluan/.rbenv/versions/3.0.0/bin/ruby -I/Users/dluan/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rspec-core-3.10.1/lib:/Users/dluan/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rspec-support-3.10.1/lib /Users/dluan/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rspec-core-3.10.1/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb

An error occurred while loading ./spec/requests/cars_spec.rb. - Did you mean?
                    rspec ./spec/rails_helper.rb

Failure/Error: require File.expand_path('../config/environment', __dir__)

LoadError:
  cannot load such file -- rexml/document
# ./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:4:in `require'
# ./spec/rails_helper.rb:4:in `<top (required)>'
# ./spec/requests/cars_spec.rb:1:in `require'
# ./spec/requests/cars_spec.rb:1:in `<top (required)>'

I'm not sure if it's because I recently also upgraded my mac os to big sur, but for some reason this only breaks on fresh rails apps.

Likewise, running the test app below in Ruby 2.7.2 and 2.6.6 works just fine.

Expected behaviour

These tests pass on fresh rails 6.1 app with ruby 2.7.2.

Can you provide an example app?

rails new testapp
bundle add rspec-rails
rails generate rspec:install

Sample app here: https://github.com/dennyluan/rspec-ruby3-rails6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions