Testing question: try to login

Hey everybody,
I’m trying to test some code I wrote, and I wrote the following

def try_to_login(antonio)
antonio = users(:one)
#post :login, :user => { :screen_name => user.screen_name, :email =>
user.email, :password => user.password }
#post :login, :screen_name => antonio.screen_name, :email =>
antonio.email, :password => antonio.password
assert logged_in?
end

If I uncomment the first post line, I get "undefined local method or
variable ‘user’ for UserControllerTest, even though I have a model
called User.rb with a table called users in my database.
However, if I comment that line and uncomment the second post line,
everything works like a charm… could anyone tell me why?

Thanks everybody in advance!

Manu L. wrote:

def try_to_login(antonio)
antonio = users(:one)
#post :login, :user => { :screen_name => user.screen_name, :email =>
user.email, :password => user.password }
#post :login, :screen_name => antonio.screen_name, :email =>
antonio.email, :password => antonio.password
assert logged_in?
end

If I uncomment the first post line, I get "undefined local method or
variable ‘user’ for UserControllerTest, even though I have a model
called User.rb with a table called users in my database.
However, if I comment that line and uncomment the second post line,
everything works like a charm… could anyone tell me why?

user.screen_name # where is user defined?

The problem is exactly what the error message is telling you “undefined
local method or variable ‘user’.”

antonio is defined on the first line of the method so
antonio.screen_name is perfectly valid.

Robert W. wrote:

Manu L. wrote:

def try_to_login(antonio)
antonio = users(:one)
#post :login, :user => { :screen_name => user.screen_name, :email =>
user.email, :password => user.password }
#post :login, :screen_name => antonio.screen_name, :email =>
antonio.email, :password => antonio.password
assert logged_in?
end

If I uncomment the first post line, I get "undefined local method or
variable ‘user’ for UserControllerTest, even though I have a model
called User.rb with a table called users in my database.
However, if I comment that line and uncomment the second post line,
everything works like a charm… could anyone tell me why?

user.screen_name # where is user defined?

The problem is exactly what the error message is telling you “undefined
local method or variable ‘user’.”

antonio is defined on the first line of the method so
antonio.screen_name is perfectly valid.

Definitely, now I know what fails: I hadn’t defined in the setup method
at the beginning of the file the valid_user.

Thanks a lot Robert!