Strange class loading in integration tests

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

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.

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