Testing to see if emails are sent out on exceptions


#1

Hi,

I’m using ActionController::rescue_action_in_public() to send emails
when uncaught exceptions happen.

Is it possible to write tests for that?

Joe


#2

Something like:

file system_notifier_test.rb:

require File.dirname(FILE) + ‘/…/test_helper’
require ‘application’

class SystemNotifierTest < Test::Unit::TestCase
class MyController < ApplicationController
def anaction
raise ‘Action Exception’
end

def local_request?
  false
end

alias consider_all_requests_local local_request?

end

def setup
@emails = ActionMailer::Base.deliveries
@emails.clear

@controller = MyController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new

end

def test_exception_notification
get :anaction
assert_match /^A RuntimeError occured in/, @emails.first.body
end
end

Kent.


#3

On 2/2/06, Kent S. removed_email_address@domain.invalid wrote:

  raise 'Action Exception'
@emails = ActionMailer::Base.deliveries

end
end

That’s brilliant. Thanks.

Joe