RSpec - ロード中にエラーが発生しました - ということですか?
概要
TDDから始めたいのですが、rvm - Ruby 3.0.0とRails 6.1.1を使用しているため、このエラーが発生しています。
An error occurred while loading ./spec/models/user_spec.rb. - Did you mean?
rspec ./spec/spec_helper.rb
Failure/Error: require File.expand_path('../config/environment', __dir__)
LoadError:
cannot load such file -- rexml/document
/home/manci/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:34:in `require'
/home/manci/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
/home/manci/.rvm/gems/ruby-3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
/home/manci/.rvm/gems/ruby-3.0.0/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/firefox.rb:22:in `<main>'
/home/manci/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
この問題を解決するにはどうすればよいでしょうか?
解決策
RSpec のメンバーである Jon Rowe がここ (https://github.com/rspec/rspec-rails/issues/2441#issuecomment-756621403) で指摘しているように、Ruby 3.0.0 を使用している場合は、rexml をインストールする必要があります。
この gem は Ruby 3.0.0 の標準 gemset から削除され、rails-controller-tests で必要になります。