wspurgin / rspec-sidekiq

RSpec for Sidekiq
https://github.com/wspurgin/rspec-sidekiq
Other
655 stars 132 forks source link

Null Object method missing for Null Batch masks NoMethod errors #189

Closed wspurgin closed 1 year ago

wspurgin commented 1 year ago

Expectation:

When writing a unit test for something that creates a Sidekiq::Batch, I expect methods not defined on Sidekiq::Batch to raise a NoMethod exception. e.g.,

class SomeService
  def self.call(n)
    batch = Sidekiq::Batch
    batch.jobs do
      n.times { |i| SomeJob.perform_async(i) }
    end

    # This method doesn't exist on `Sidekiq::Batch`
    batch.foobar!
  end
end

# in spec, this should fail
it "works without error!" do
  expect { SomeService.call! }.not_to raise_error
end

Actual:

Instead, due to the method_missing implementation, the foobar! call returns self and the test passes, but production code will not.