Functional test with exception_notification fails when run with rake, passes when run with Ruby

I've got a wierd problem with a functional test that passes when run
individually ('ruby test/functional/exception_notifier.rb') but fails
when run as part of 'rake test:functionals'. I'm testing whether a
broken page is handled by the exception_notification plugin. Using
Mocha (http://agilewebdevelopment.com/plugins/mocha) I set a method
called from a partial to throw a RuntimeError so that
exception_notification will handle it.

The test is as follows:
   def test_broken_home
     # plan our exception around a failing testimonial call

Testimonial.expects( :active_testimonials ).raises( RuntimeError )

     # make sure we're not seen as a local request
     HomeController.consider_all_requests_local = false

     # count our mails
     base_mails = ActionMailer::Base.deliveries.size
     bg_mails = ActionMailer::Background.background_deliveries.size

     # get our page
     get :index

     # make sure its an error
     assert_response :error

     # count our mails
     assert_equal base_mails + 1, ActionMailer::Base.deliveries.size
     assert_equal bg_mails,
ActionMailer::Background.background_deliveries.size
  end

When run as an individual test everything passes, the exception is
handled a 500 is returned and the appropriate mails are sent. When
called as part of the functional test suite the RuntimeError causes an
error in the test and the response code is 0 with no mails being sent
(I put the get :index in a begin rescue block to check this).

I assume the problem is due either to the environment that rake sets
up that either prevents exception_notification from handling the
exception but I have no ideas at the

Has anyone handled an issue like this before? Any ideas on what to
change?

Farrel

The most likely reason for the difference is you are not declaring a
fixture.