Uninitialized constant in integration test

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:inconst_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:inload_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:innew_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:inrequire_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:inconst_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:inconstantize’
/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:inrecognize’
/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:inassert_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:inassert_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:inassert_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:inrun’

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:inconst_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:insend!’
/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:inget’
/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:inget’
test/integration/foo_test.rb:7:in test_redirect' /usr/local/lib/ruby/1.8/test/unit/testcase.rb:78:insend
/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:inrun’

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs