gpt4 book ai didi

ruby-on-rails - rspec rails 测试 : how can I force ActiveJob job's to run inline for certain tests?

转载 作者:数据小太阳 更新时间:2023-10-29 07:07:01 25 4
gpt4 key购买 nike

我希望我的后台作业能够内联运行某些标记测试。我可以通过用 perform_enqueued do 包装测试来做到这一点,但我希望能够用元数据标记它们,如果可能的话,它会自动发生。

我试过以下方法:

it "does everything in the job too", perform_enqueued: true do
end

config.around(:each) do |example|
if example.metadata[:perform_enqueued]
perform_enqueued_jobs do
example.run
end
end
end

但它会导致错误:

undefined method `perform_enqueued_jobs=' for ActiveJob::QueueAdapters::InlineAdapter:Class

最佳答案

您需要将用于测试的适配器设置为 ActiveJob::QueueAdapters::TestAdapter,它响应 .perform_enqueued_jobs =。您可以在 spec/rails_helper.rb 文件中执行此操作:

ActiveJob::Base.queue_adapter = :test

关于ruby-on-rails - rspec rails 测试 : how can I force ActiveJob job's to run inline for certain tests?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37281665/

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