# Functional test with exception\_notification fails when run with rake, passes when run with Ruby

**URL:** <https://www.ruby-forum.com/t/functional-test-with-exception-notification-fails-when-run-with-rake-passes-when-run-with-ruby/126640>\
**Category:** Rails\
**Created:** [January 20, 2008, 9:53pm UTC](https://www.ruby-forum.com/t/functional-test-with-exception-notification-fails-when-run-with-rake-passes-when-run-with-ruby/126640 "2008-01-20T21:53:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Farrel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bcef8e/32.png) [@Farrel](https://www.ruby-forum.com/u/Farrel)\
**Post date:** [January 20, 2008, 9:53pm UTC](https://www.ruby-forum.com/t/functional-test-with-exception-notification-fails-when-run-with-rake-passes-when-run-with-ruby/126640/1 "2008-01-20T21:53:31Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Farrel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bcef8e/32.png) [@Farrel](https://www.ruby-forum.com/u/Farrel)\
**Post date:** [January 21, 2008, 9:23am UTC](https://www.ruby-forum.com/t/functional-test-with-exception-notification-fails-when-run-with-rake-passes-when-run-with-ruby/126640/2 "2008-01-21T09:23:31Z")

</div>

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