为什么fixture_file_upload 在RSpec(没有ActiveRecord)中不可用?

mlt*_*tsy 6 rspec ruby-on-rails rspec-rails ruby-on-rails-5

我正在尝试在 Rails 5.2 应用程序中使用 RSpec 3.7 测试文件上传,我见过的最简单的建议(几个地方,包括这篇 SO 帖子)是使用fixture_file_upload- 看起来不错,只是它似乎没有在我的应用程序中可用,我不知道为什么。

我唯一能想到的是我们的应用程序没有使用 ActiveRecord,它使用的是 MongoID。但是不应该要求 ActiveRecord 使用这些方法……它们完全无关。Rails 5 中是否还有另一个我缺少的新“ActiveSomething”库?(此应用程序是从 Rails 4 应用程序升级而来的...)

为了更具体地解释我的问题,我试过:

let(:file) { fixture_file_upload('invalid_csv.csv') }
Run Code Online (Sandbox Code Playgroud)

在我的一个上下文中,它引发了一个例外:

undefined local variable or method 'fixture_path' for #<RSpec::ExampleGroups::...>
Run Code Online (Sandbox Code Playgroud)

我尝试config.file_fixture_path 按照此处概述的方式定义,这引发了它自己的异常:

undefined method `file_fixture_path=' for #<RSpec::Core::Configuration::...>
Run Code Online (Sandbox Code Playgroud)

这真的有效吗?显然我错过了一些东西......

seq*_*elo 2

我通过将其模块包含在 RSpec 配置块中来修复此问题:

RSpec.configure do |config|
  #...
  config.include ActionDispatch::TestProcess::FixtureFile
  #...
end
Run Code Online (Sandbox Code Playgroud)