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 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
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.
34 35 36 37 |
# File 'lib/rspec/sidekiq/batch.rb', line 34 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.
32 33 34 |
# File 'lib/rspec/sidekiq/batch.rb', line 32 def bid @bid end |
#description ⇒ Object
Returns the value of attribute description.
31 32 33 |
# File 'lib/rspec/sidekiq/batch.rb', line 31 def description @description end |
Instance Method Details
#jobs ⇒ Object
47 48 49 |
# File 'lib/rspec/sidekiq/batch.rb', line 47 def jobs(*) yield end |
#on(*args) ⇒ Object
43 44 45 |
# File 'lib/rspec/sidekiq/batch.rb', line 43 def on(*args) @callbacks << args end |
#status ⇒ Object
39 40 41 |
# File 'lib/rspec/sidekiq/batch.rb', line 39 def status NullStatus.new(@bid, @callbacks) end |