views:

191

answers:

2

I'm trying to write basic assert test:

def assert_session_has ( sessionvar )
    return assert_not_nil session[:sessionvar]
end

when I compile:

def test_auth_bob
    #some setup and other validation methods
    assert_not_nil session[user]
    #more validations...
end

I get the following error:

test_auth_bob(UserControllerTest):
NameError: undefined local variable or method `user' for #<UserControllerTest:0x3460c28>
/test/functional/user_controller_test.rb:23:in `test_auth_bob'

Any ideas?

+2  A: 

Where do you declare user in your test_auth_bob function? The interpreter is complaining that the symbol is undefined.

Andrew Hare
line 23 is the assert_not_nil call. I know it is this line because if I comment it out the rest of the test function is fine.
cbrulak
Deleted my comment as I saw which line is 23 in the error message.
theIV
its not complaining about the test_auth_bob function
cbrulak
Your error message above says `user_controller_test.rb:23:in `test_auth_bob'`. Both the answer above and below seem to be valid, unless there is something I'm completely missing.
theIV
+1  A: 

You lost a colon. As painful as that sounds, some people don't even notice.

def test_auth_bob
    #some setup and other validation methods
    assert_not_nil session[:user]
    #more validations...
end

Without the : user refers to a variable or method, with a colon user is the symbol :user. This post on the internet about symbols appears to explain more… but I have not read it. I'm being called away from the computer by a thrilling but slow moving episode of The Wire. It's good.

cwninja