# Functional Test - assert\_raise exception gives headache!

**URL:** <https://www.ruby-forum.com/t/functional-test-assert-raise-exception-gives-headache/143242>\
**Category:** Rails\
**Created:** [July 16, 2008, 6:13pm UTC](https://www.ruby-forum.com/t/functional-test-assert-raise-exception-gives-headache/143242 "2008-07-16T18:13:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [July 16, 2008, 6:13pm UTC](https://www.ruby-forum.com/t/functional-test-assert-raise-exception-gives-headache/143242/1 "2008-07-16T18:13:13Z")

</div>

in one of my functional test, I check the followoing :

def test\_user\_should\_not\_show\_documents  
login\_as (:quentin)  
assert\_raise (Exceptions::SecurityTransgression) { get :show, :id  
=\> 2, :franchise\_id =\> 3 }  
end

In my controller , I wrote :

before\_filter :login\_required  
before\_filter :find\_parent  
def show  
raise SecurityTransgression unless @parent.can\_be\_edited\_by?  
(current\_user)  
@document = Document.find(params[:id].to\_i)  
…  
end

I wrote the exception class and rescue action in my application.rb  
class SecurityTransgression \< StandardError; end

class ApplicationController \< ActionController::Base  
include AuthenticatedSystem  
…  
def rescue\_action\_locally(exception)  
begin  
case exception  
when ::Exceptions::SecurityTransgression  
render :file =\> “#{RAILS\_ROOT}/public/403.html”, :status =\>  
403  
…  
end

in testing, the exception is raised, (as @parent cannot be edited by  
the current\_user… I checked it…) the log gives a failure I cannot  
explain :

1. Failure:  
test\_user\_should\_not\_show\_documents(DocumentsControllerTest)  
[./test/functional/documents\_controller\_test.rb:66:in  
`test_user_should_not_show_documents' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/ active_support/testing/setup_and_teardown.rb:67:in` **send** ’  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/  
active\_support/testing/setup\_and\_teardown.rb:67:in `run']: <Exceptions::SecurityTransgression> exception expected but was Class: <SecurityTransgression> Message: <"SecurityTransgression"> ---Backtrace--- /Users/yves/Developpement/Projects/aelmat/intranet/app/controllers/ documents_controller.rb:19:in`show’  
…

the exception is expected, but …

what could be the problem ?

Note : I am using the same assert\_raise  
(Exceptions::SecurityTransgression) in testing another controller  
without any problem …

thanks for your suggestions

erwin

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [July 16, 2008, 6:47pm UTC](https://www.ruby-forum.com/t/functional-test-assert-raise-exception-gives-headache/143242/2 "2008-07-16T18:47:10Z")

</div>

got it… I forgot to write an Include Exceptions in my  
DocumentsController  
where the SecurityTransgression is defined…
