gpt4 book ai didi

ruby-on-rails - 为什么 Fixture_file_upload 在 RSpec 中不可用(没有 ActiveRecord)?

转载 作者:行者123 更新时间:2023-12-03 14:49:04 27 4
gpt4 key购买 nike

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

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

为了更具体地解释我的问题,我尝试提出:

let(:file) { fixture_file_upload('invalid_csv.csv') }

在我的一种情况下,它引发了一个异常(exception):
undefined local variable or method 'fixture_path' for #<RSpec::ExampleGroups::...>

我尝试定义 config.file_fixture_path as outlined here ,这引发了它自己的异常:
undefined method `file_fixture_path=' for #<RSpec::Core::Configuration::...>

这行得通吗?显然我错过了一些东西......

最佳答案

我已经通过在 RSpec 配置 block 中包含他们的模块来解决这个问题:

RSpec.configure do |config|
#...
config.include ActionDispatch::TestProcess::FixtureFile
#...
end

关于ruby-on-rails - 为什么 Fixture_file_upload 在 RSpec 中不可用(没有 ActiveRecord)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54469435/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com