# Uninitialized constant in integration test

**URL:** <https://www.ruby-forum.com/t/uninitialized-constant-in-integration-test/124112>\
**Category:** Rails\
**Created:** [December 24, 2007, 9:58pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-in-integration-test/124112 "2007-12-24T21:58:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![osteo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a87d85/32.png) [@osteo](https://www.ruby-forum.com/u/osteo)\
**Post date:** [December 24, 2007, 9:58pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-in-integration-test/124112/1 "2007-12-24T21:58:13Z")

</div>

I am seeing weird issues when trying to create integration tests. Here  
is a very simple example of something that is failing. The  
assert\_redirected\_to, and other methods, fail with this or similar  
exceptions.

I have tried requiring both ‘application’ and ‘listings\_controller’, but  
neither solves this problem, although the exception changes.

Anybody know what’s going on here?

Thanks.

* * *

require “#{File.dirname( **FILE** )}/…/test\_helper”

## class FooTest \< ActionController::IntegrationTest def test\_redirect get “/” assert\_redirected\_to “/” end end

with this exception:

NameError: uninitialized constant ApplicationController  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active\_support/dependencies.rb:266:in  
`load_missing_constant' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/dependencies.rb:453:in`const\_missing’  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active\_support/dependencies.rb:465:in  
`const_missing' /Users/.../trunk/rails/app/controllers/listings_controller.rb:3 /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/dependencies.rb:203:in`load\_without\_new\_constant\_marking’  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active\_support/dependencies.rb:203:in  
`load_file' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/dependencies.rb:342:in`new\_constants\_in’  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active\_support/dependencies.rb:202:in  
`load_file' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/dependencies.rb:94:in`require\_or\_load’  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active\_support/dependencies.rb:248:in  
`load_missing_constant' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/dependencies.rb:453:in`const\_missing’  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active\_support/dependencies.rb:465:in  
`const_missing' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/inflector.rb:257:in`constantize’  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active\_support/core\_ext/string/inflections.rb:148:in  
`constantize' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_controller/routing.rb:1423:in`recognize’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action\_controller/assertions/routing\_assertions.rb:138:in  
`recognized_request_for' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_controller/assertions/response_assertions.rb:70:in`assert\_redirected\_to’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action\_controller/assertions/response\_assertions.rb:62:in  
`each' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_controller/assertions/response_assertions.rb:62:in`assert\_redirected\_to’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action\_controller/assertions.rb:54:in  
`clean_backtrace' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_controller/assertions/response_assertions.rb:54:in`assert\_redirected\_to’  
test/integration/foo\_test.rb:6:in `test_redirect' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_controller/integration.rb:532:in`run’

---

<div class="post-metadata">

**Author:** ![osteo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a87d85/32.png) [@osteo](https://www.ruby-forum.com/u/osteo)\
**Post date:** [December 24, 2007, 10:07pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-in-integration-test/124112/2 "2007-12-24T22:07:39Z")

</div>

Slight correction. In the above case, require ‘listings\_controller’  
allows it to work. However if I add a second test as in this:

require “#{File.dirname( **FILE** )}/…/test\_helper”  
require ‘listings\_controller’

class FooTest \< ActionController::IntegrationTest

def test\_redirect  
get “/”  
assert\_redirected\_to “/”  
end

def test\_foo  
get “/”  
assert\_redirected\_to “/”  
end  
end

Then I get exceptions like this:

ArgumentError (A copy of ApplicationController has been removed from the  
module tree but is still active!):  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active\_support/dependencies.rb:237:in  
`load_missing_constant' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/dependencies.rb:469:in`const\_missing’  
/app/controllers/application.rb:75:in `prepare_session' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_controller/filters.rb:469:in`send!’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action\_controller/filters.rb:469:in  
`call' ... /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_controller/integration.rb:157:in`get’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action\_controller/integration.rb:382:in  
`send!' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_controller/integration.rb:382:in`get’  
test/integration/foo\_test.rb:7:in `test_redirect' /usr/local/lib/ruby/1.8/test/unit/testcase.rb:78:in` **send** ’  
/usr/local/lib/ruby/1.8/test/unit/testcase.rb:78:in `run' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_controller/integration.rb:532:in`run’
