Joe Van Dyk
2006-Feb-03 04:22 UTC
[Rails] testing to see if emails are sent out on exceptions
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
Kent Sibilev
2006-Feb-03 06:31 UTC
[Rails] testing to see if emails are sent out on exceptions
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.
On 2/2/06, Joe Van Dyk <joevandyk@gmail.com>
wrote:> 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
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
Joe Van Dyk
2006-Feb-03 07:54 UTC
[Rails] testing to see if emails are sent out on exceptions
On 2/2/06, Kent Sibilev <ksruby@gmail.com> wrote:> 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 > endThat''s brilliant. Thanks. Joe> On 2/2/06, Joe Van Dyk <joevandyk@gmail.com> wrote: > > 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 > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >