Here's rake task that's using threads to email async...Why is this rspec test for a rake task green if I put expect before the invoke? And is it appropriate to put the "expect" before "subject.invoke"?
rspec test
describe 'send foxes' do
subject { rake['send_foxes'] }
before do
allow(SomeMailer).to receive_message_chain(:send_free_fox, :deliver_now)
end
it "should send fox" do
expect(SomeMailer).to receive(:send_free_fox)
subject.invoke
end
end
rake task
task :send_foxes do
foxObject.find_in_batches(batch_size: 600) do |foxes|
batch = Proc.new do
fox_it(foxes)
end
Thread.new { batch.call }
end
end
private
def fox_it(foxes)
foxes.each do |fox|
if fox.status == 'kitten'
user = User.find_by(id: fox.user_id)
SomeMailer.send_free_fox(user: user).deliver_now
end
end
end
end