Class: RSpec::Sidekiq::NullBatch
- Inherits:
-
NullObject
- Object
- NullObject
- RSpec::Sidekiq::NullBatch
- Defined in:
- lib/rspec/sidekiq/batch.rb
Overview
Sidekiq::Batch is a Sidekiq::Pro feature. However the general consensus is that, by default, 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
Instance Attribute Summary collapse
-
#bid ⇒ Object
readonly
Returns the value of attribute bid.
-
#description ⇒ Object
Returns the value of attribute description.
Instance Method Summary collapse
-
#initialize(bid = nil) ⇒ NullBatch
constructor
A new instance of NullBatch.
- #jobs ⇒ Object
- #on(*args) ⇒ Object
- #status ⇒ Object
Methods inherited from NullObject
Constructor Details
#initialize(bid = nil) ⇒ NullBatch
Returns a new instance of NullBatch.
37 38 39 40 |
# File 'lib/rspec/sidekiq/batch.rb', line 37 def initialize(bid = nil) @bid = bid || SecureRandom.hex(8) @callbacks = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RSpec::Sidekiq::NullObject
Instance Attribute Details
#bid ⇒ Object (readonly)
Returns the value of attribute bid.
35 36 37 |
# File 'lib/rspec/sidekiq/batch.rb', line 35 def bid @bid end |
#description ⇒ Object
Returns the value of attribute description.
34 35 36 |
# File 'lib/rspec/sidekiq/batch.rb', line 34 def description @description end |
Instance Method Details
#jobs ⇒ Object
50 51 52 |
# File 'lib/rspec/sidekiq/batch.rb', line 50 def jobs(*) yield end |
#on(*args) ⇒ Object
46 47 48 |
# File 'lib/rspec/sidekiq/batch.rb', line 46 def on(*args) @callbacks << args end |
#status ⇒ Object
42 43 44 |
# File 'lib/rspec/sidekiq/batch.rb', line 42 def status NullStatus.new(@bid, @callbacks) end |