3
mail(mail_content).deliver への呼び出しをスペックとするrspecテストを作成する最良の方法を見つけようとしています。 Rails.loggerが呼び出されることをアサートすることができます。スーパークラスメソッドをテストする方法Rubyでrspecを使用して例外をスローする
私はあなたがテスト対象のクラスを模擬するつもりはないと知っていますが、これはスーパークラスにも当てはまりますか?
class MyMailer < ActionMailer::Base
default from: '[email protected]'
default charset: 'UTF-8'
default content_type: 'text/plain'
default subject: 'Test'
def send_email (to, mail_headers_hash, mail_body)
begin
headers mail_headers_hash
mail_content = {to: to, body: mail_body}
mail(mail_content).deliver
rescue ArgumentError, StandardError => e
Rails.logger.error "Failed to email order response - #{e}"
end
end
end
end