You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rails test无法运行:找不到arel/visitors/mysql文件报错求助

Rails执行rails test报错:找不到arel/visitors/mysql

问题情况

刚接触Rails框架,项目其他功能正常,但执行rails test时出现LoadError,提示无法加载arel/visitors/mysql。已尝试卸载arel和activerecord gem后重新执行bundle install,问题仍未解决。

报错信息

MyApp$ rails test
/usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:33:in `require': cannot load such file -- arel/visitors/mysql (LoadError)
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:291:in `block in require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:257:in `load_dependency'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:291:in `require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/arel-9.0.0/lib/arel/visitors.rb:7:in `<top (required)>'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:291:in `block in require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:257:in `load_dependency'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:291:in `require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/arel-9.0.0/lib/arel.rb:17:in `<top (required)>'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:291:in `block in require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:257:in `load_dependency'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:291:in `require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activerecord-5.2.4/lib/active_record.rb:29:in `<top (required)>'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:291:in `block in require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:257:in `load_dependency'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:291:in `require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activerecord-5.2.4/lib/active_record/railtie.rb:3:in `<top (required)>'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
from /usr/share/rvm/gems/ruby-2.5.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:291:in `block in require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:257:in `load_dependency'
from /usr/share/rvm/gems/ruby-2.5.7/gems/activesupport-5.2.4/lib/active_support/dependencies.rb:291:in `require'
from /home/akhilr/Documents/Metastore/cpmetastore/cpmetastore/config/application.rb:8:in `<top (required)>'
from /usr/share/rvm/gems/ruby-2.5.7/gems/spring-2.1.0/lib/spring/application.rb:92:in `require'
from /usr/share/rvm/gems/ruby-2.5.7/gems/spring-2.1.0/lib/spring/application.rb:92:in `preload'
from /usr/share/rvm/gems/ruby-2.5.7/gems/spring-2.1.0/lib/spring/application.rb:157:in `serve'
from /usr/share/rvm/gems/ruby-2.5.7/gems/spring-2.1.0/lib/spring/application.rb:145:in `block in run'
from /usr/share/rvm/gems/ruby-2.5.7/gems/spring-2.1.0/lib/spring/application.rb:139:in `loop'
from /usr/share/rvm/gems/ruby-2.5.7/gems/spring-2.1.0/lib/spring/application.rb:139:in `run'
from /usr/share/rvm/gems/ruby-2.5.7/gems/spring-2.1.0/lib/spring/application/boot.rb:19:in `<top (required)>'
from /usr/share/rvm/rubies/ruby-2.5.7/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/share/rvm/rubies/ruby-2.5.7/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'

解决步骤

  • 检查数据库配置与依赖:确认config/database.yml中使用的是mysql2适配器,同时Gemfile里已添加gem 'mysql2',执行bundle install确保依赖安装完整。
  • 清理Bootsnap缓存:执行命令bundle exec rails tmp:clear,或者手动删除项目根目录下的tmp/cache文件夹,清除缓存后再尝试运行测试。
  • 指定兼容的Arel版本:Rails 5.2.4默认依赖的Arel版本为8.x,当前使用的9.0.0存在兼容性问题。在Gemfile中添加gem 'arel', '~> 8.0',然后执行bundle update arel更新依赖。
  • 重置Gem依赖:删除项目根目录下的Gemfile.lock文件,执行bundle install重新安装所有依赖,确保版本匹配。
  • 确认RVM环境:执行rvm use 2.5.7切换到正确的Ruby版本,再重新执行bundle install和rails test。

内容的提问来源于stack exchange,提问作者Akhil S R

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 23:10:28