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! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Manu Lorenzo 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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker wrote:> Manu Lorenzo 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! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.