在Rails + Minitest + Sidekiq中测试作业排队

时间:2016-06-15 07:44:19

标签: ruby-on-rails testing sidekiq rails-activejob

这是我的测试文件:

require "test_helper"
include ActiveJob::TestHelper

ActiveJob::Base.queue_adapter = :test

describe "A provider requests premium activation", :capybara do
  it "sends an email to SALES_MAIL", js: true do
    login_with_provider(:regular_with_courses, "12345edu")
    click_link('activate-premium-btn')
    assert_enqueued_jobs 1
  end
end

click_link('activate-premium-btn')发出执行此操作的AJAX调用:

def process_premium_provider
    provider = Provider.find(params["provider_id"])
    SendInternalInfo.perform_later(provider, "premium_activation_requested")
end

我手动测试,它的工作原理。但是,似乎assert_enqueued_jobs与实际排队的作业之间存在差异。

运行测试,测试已执行,但失败了:

A provider requests premium activation::capybara
  test_0001_sends an email to SALES_MAIL                         ERROR (10.22s)
Minitest::Assertion:         1 jobs expected, but 0 were enqueued.
        Expected: 1
          Actual: 0
        test/features/premium_requested_spec.rb:10:in `block (2 levels) in <top (required)>'


Finished in 10.22569s
1 tests, 1 assertions, 1 failures, 0 errors, 0 skips
然而,有一些奇怪的东西。测试失败但它也抛出了错误,但它没有指出错误的位置。

我知道Sidekiq测试功能,但我更喜欢采用不可知的队列适配器方式。

关于可能发生的事情的任何想法?

感谢。

0 个答案:

没有答案