# Strange class loading in integration tests

**URL:** <https://www.ruby-forum.com/t/strange-class-loading-in-integration-tests/123880>\
**Category:** Rails\
**Created:** [December 21, 2007, 5:57pm UTC](https://www.ruby-forum.com/t/strange-class-loading-in-integration-tests/123880 "2007-12-21T17:57:01Z")\
**Posts on this page:** 1\
**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 21, 2007, 5:57pm UTC](https://www.ruby-forum.com/t/strange-class-loading-in-integration-tests/123880/1 "2007-12-21T17:57:01Z")

</div>

So I have a working site and have a good amount of experience with Rails  
from building it. I recently decided it was time to start writing  
tests. Yeah, thanks, I know I should have done it earlier.

I’m jumping straight into integration tests because that’s what I need  
right now. I’ll write other tests later.

I am really struggling with getting a simple test working. There seem  
to be strange class loading issues, a subject that I’m not an expert in.

First it took me a while to figure out I had to have this line at the  
head of my tests:

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

I’m passed that now though. Some tests work. For instance, I can do  
this:

```
get("/foo")

```

# assert\_redirected\_to “[http://www.foobar.com](http://www.foobar.com)”

```
follow_redirect!
assert_response :success

```

But when I uncomment that assert\_redirected\_to line, I get an exception  
(with abbreviated stack trace):

NameError: uninitialized constant ApplicationController  
…  
my\_controller.rb  
…  
my\_test.rb

I also get an exception when I try to load one of my models, e.g.  
User.find\_by\_username(“foobar”)

This one is even stranger as my exception looks like this:

NoMethodError: undefined method `foobar’ for #User:0x362a324

Where foobar is a method in my User class which is always used in my  
application (it’s a low level permissions thing) and is most definitely  
defined.

What is going on here? It’s driving me nuts.

Thanks.
