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.
Expectation:
When writing a unit test for something that creates a
Sidekiq::Batch
, I expect methods not defined onSidekiq::Batch
to raise aNoMethod
exception. e.g.,Actual:
Instead, due to the
method_missing
implementation, thefoobar!
call returnsself
and the test passes, but production code will not.