I have a block:
def already_syncing?
Sidekiq::Queue.new(queue_name).any? { |q| q.args[0] == car_id }
end
How would I test this? If I stub it out like this:
allow(Sidekiq::Queue).to receive_message_chain(:new, :any?) { true }
Then the condition in my actual block is not tested.
I think what you were looking for was
and_yield
:allow(Sidekiq::Queue).to receive_message_chain(:new, :any?).and_yield(<something>)
Here's some sample code/specs for you (with values/method calls that I didn't know about stubbed out) that you can try yourself and change as you see fit: