class RSpec::Sidekiq::NullBatch
Sidekiq::Batch is a Sidekiq::Pro feature. However the general consensus is that, by defeault, you can’t test without redis. RSpec::Sidekiq
includes a “null object” pattern implementation to mock Batches. This will mock Sidekiq::Batch and prevent it from using Redis.
This is opt-in only feature.
RSpec.describe "Using mocked batches", stub_batches: true do it "uses mocked batches" do batch = Sidekiq::Batch.new batch.jobs do SomeJob.perform_async 123 end expect(SomeJob).to have_enqueued_sidekiq_job end end
Attributes
bid[R]
description[RW]
Public Class Methods
new(bid = nil)
click to toggle source
# File lib/rspec/sidekiq/batch.rb, line 34 def initialize(bid = nil) @bid = bid || SecureRandom.hex(8) @callbacks = [] end
Public Instance Methods
jobs(*) { || ... }
click to toggle source
# File lib/rspec/sidekiq/batch.rb, line 47 def jobs(*) yield end
on(*args)
click to toggle source
# File lib/rspec/sidekiq/batch.rb, line 43 def on(*args) @callbacks << args end
status()
click to toggle source
# File lib/rspec/sidekiq/batch.rb, line 39 def status NullStatus.new(@bid, @callbacks) end