跳至内容 跳至搜索

Active Job 的测试适配器

测试适配器应仅在测试中使用。它与 ActiveJob::TestCaseActiveJob::TestHelper 一起,是测试你的 Rails 应用程序的强大工具。

要使用测试适配器,请将 queue_adapter 配置设置为 :test

Rails.application.config.active_job.queue_adapter = :test
方法
E
P
S

Attributes

[RW] at
[W] enqueued_jobs
[RW] filter
[RW] perform_enqueued_at_jobs
[RW] perform_enqueued_jobs
[W] performed_jobs
[RW] queue
[RW] reject
[RW] stopping

实例公共方法

enqueued_jobs()

提供一个存储所有已入队作业的存储库,使用 TestAdapter,以便你可以进行检查。

# File activejob/lib/active_job/queue_adapters/test_adapter.rb, line 19
def enqueued_jobs
  @enqueued_jobs ||= []
end

performed_jobs()

提供一个存储所有已执行作业的存储库,使用 TestAdapter,以便你可以进行检查。

# File activejob/lib/active_job/queue_adapters/test_adapter.rb, line 24
def performed_jobs
  @performed_jobs ||= []
end

stopping?()

# File activejob/lib/active_job/queue_adapters/test_adapter.rb, line 38
def stopping?
  @stopping.is_a?(Proc) ? @stopping.call : @stopping
end