I am currently trying to test a portion of code in my rails worker class as shown below(simplified version);
class SenderWorker
include Sidekiq::Worker
sidekiq_options :retry => 5
def perform(current_user_guid)
Rails.logger.info "Starting for user_guid: #{current_user_guid}"
user = User.find_by!(guid: current_user_guid)
team = Team.find_by!(uuid: user.team.uuid)
profiles = team.profiles
profiles.each do |profile|
SenderClass.new(profile,
user).send(User::RECALL_USER)
end
Rails.logger.info "Finishing for user_guid: #{current_user_guid}"
end
end
The tests that I have written are these and they are passing;
context 'when something occurs' do
it 'should send' do
sender = double("sender")
allow(SenderClass).to receive(:new).with(user_profile, current_user) { sender }
expect(sender).to receive(:send)
expect(Rails.logger).to receive(:info).exactly(2).times
worker.perform(user.guid)
end
end
However, I am not testing for all calls. Is there a way to ensure that I test for everything called in the each do
loop. Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire