Execute pending job with ActiveJob in rspec

后端 未结 3 1374
伪装坚强ぢ
伪装坚强ぢ 2021-02-12 19:49

I have this code to test ActiveJob and ActionMailer with Rspec I don\'t know how really execute all enqueued job

describe \'whatever\' do
  include ActiveJob::         


        
3条回答
  •  面向向阳花
    2021-02-12 20:27

    The proper way to test will be to check number of enqueued jobs as in your example, and then test each job separately. If you want to do integration testing you can try perform_enqueued_jobs helper:

    describe 'whatever' do
      include ActiveJob::TestHelper
    
      after do
        clear_enqueued_jobs
      end  
    
      it 'should email' do
        perform_enqueued_jobs do
          SomeClass.some_action
        end
      end
    
    end
    

    See ActiveJob::TestHelper docs

提交回复
热议问题