6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

$rails testができなかった問題→rexmlを追加すれば良い

Posted at

#問題
$rails testをしたらエラー文が吐かれた
ロードができないようだ

sample_app $ rails test
Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:34:in `require': cannot load such file -- rexml/document (LoadError)
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/firefox.rb:22:in `<main>'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/webdrivers-4.5.0/lib/webdrivers/geckodriver.rb:72:in `<main>'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/webdrivers-4.5.0/lib/webdrivers.rb:4:in `<main>'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bundler-2.2.6/lib/bundler/runtime.rb:66:in `block (2 levels) in require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bundler-2.2.6/lib/bundler/runtime.rb:61:in `each'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bundler-2.2.6/lib/bundler/runtime.rb:61:in `block in require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bundler-2.2.6/lib/bundler/runtime.rb:50:in `each'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bundler-2.2.6/lib/bundler/runtime.rb:50:in `require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bundler-2.2.6/lib/bundler.rb:173:in `require'
	from /Users/yuya/environment/sample_app/config/application.rb:7:in `<top (required)>'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:92:in `require'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:92:in `preload'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:157:in `serve'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
	from /Users/yuya/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>'
	from <internal:/Users/yuya/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/Users/yuya/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from -e:1:in `<main>'

#原因
Rails 6.1: What is preventing tests from running?
こちらの記事を見たところrexml gemを追加してないことによって起きたエラーだそうです

rexml gem is a bundled gem since Ruby 3.0.0.
( rexml gemは、Ruby3.0.0以降にバンドルされたgemです。)

So you must add rexml to Gemfile.
(したがって、rexmlGemfileに追加する必要があります。)

#解決
rexmlGemfileに追加

Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.0.0'

gem 'rails', '~> 6.1.1'
gem 'sqlite3', '~> 1.4'

/省略/

gem 'rexml'

gemを追加したのでbundle

terminal
$ bundle install

#結果
$rails testができました

terminal
$ rails test
Running via Spring preloader in process 7862
Run options: --seed 12855

# Running:

....

Finished in 4.874390s, 0.8206 runs/s, 0.8206 assertions/s.
4 runs, 4 assertions, 0 failures, 0 errors, 0 skips

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?