How to properly test the Mail object in rspec -
in reading of rspec, sounds doing like...
expect_any_instance_of(mail).to receive(:deliver)
...should cause rspec replace deliver method it's own deliver method isn't called. in case when following error in test leads me believe still being called.
failure/error: task.send_email_alert('test', dummy) errno::econnrefused: connection refused - connect(2) "localhost" port 25
here's method
def send_email_alert(alert_body, alert) mail = mail.new alert.send_emails_from alert.email_address subject 'new job posted ' + alert.job_board_name body alert_body end mail.deliver! end
and here's test.
context 'send_email_alert' 'creates email , calls deliver method' dummy = openstruct.new(send_emails_from: 'test@test.com', job_board_name: 'test', email_address: 'test@test.com') expect(mail).to receive(:deliver).and_return(true) task.send_email_alert('test', dummy) end end
you've stubbed deliver
, did not stub deliver!
, method called. separate methods.
Comments
Post a Comment