ruby-on-rails - RSpec 给了我一个 LoadError
问题描述
我最近一直在尝试在 Rails 应用程序中运行 RSpec,但我似乎无法让它工作。我已按照所有说明进行操作,但我什至无法运行一个简单的测试。
RSpec 在我的 Gemfile 中,我已经运行了rails generate rspec:install
.
我用一个简单的模型测试设置了 spec 文件夹。但是,每次我尝试运行 RSpec 时,都会收到以下错误:
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
我的 user_spec.rb 看起来像这样:
require 'rails_helper'
RSpec.describe User, type: :model do
it "tests my rspec installation"
end
我是 Rails 的新手,所以我非常感谢任何帮助!
解决方案
只需添加gem 'rexml'
到您的 Gemfile 并bundle
在终端中运行。
推荐阅读
- android - java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“java.lang.String java.lang.String.toLowerCase()”
- python - Pepper Robot 无法正常启动
- socket.io - NestJS 8 Socket.io 4 在服务器端有套接字但未到达
- blazor - Blazor 服务器“找不到路由值指定的回退终结点:{ page: /_Host, area: }。”
- sql - SAS studio / SQL,如何对列进行计数和求和并创建一个新列来存储它们?
- python - Python Regex - 在每场比赛中引用第一行,直到新组开始
- python - 我想生成一个循环来查找多列的 groupby 平均值
- apollo - Apollo 客户端向错误的 uri 发送请求
- swift - 文字不透明度渐变
- amazon-web-services - AWS AMI 类型通过其名称来解释