0

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 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

4 Comments

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.
Deleted my comment as I saw which line is 23 in the error message.
its not complaining about the test_auth_bob function
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.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.