首页 > 解决方案 > 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 的新手,所以我非常感谢任何帮助!

标签: ruby-on-railsrspec

解决方案


只需添加gem 'rexml'到您的 Gemfile 并bundle在终端中运行。


推荐阅读