ruby-on-rails – rspec rails测试:如何强制ActiveJob作业在某
发布时间:2020-12-17 03:10:27 所属栏目:百科 来源:网络整理
导读:我希望我的后台作业能够内联运行某些标记测试.我可以通过perform_enqueued包装测试来做到这一点,但我想能够用元数据标记它们,如果可能的话,它会自动发生. 我尝试过以下方法: it "does everything in the job too",perform_enqueued: true doendconfig.aroun
我希望我的后台作业能够内联运行某些标记测试.我可以通过perform_enqueued包装测试来做到这一点,但我想能够用元数据标记它们,如果可能的话,它会自动发生.
我尝试过以下方法: 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |