From: Rob Biedenharn Date: 2007-09-10T06:05:40+09:00 Subject: Re: how to fix assigns(:user) on controller test On Sep 9, 2007, at 4:56 PM, OnRails Ruby wrote: > James Hunt wrote: >> On 9/8/07, OnRails Ruby claimed: >>> >>> when I run this test, There always said, >>> NoMetodError: You have a ni object when you didn't expect it: >>> the error occurred while evaluating nil.password. >>> >>> I have try to use: >>> assert_equal 'newpassword', assigns('user').password >>> assert_equal 'newpassword', assigns[:user].password >>> assert_equal 'newpassword', assigns['user'].password >>> But did you try: assert_equal 'newpassword', assigns(:user).password and you actually do assign to @user in the controller, right? -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com >> >> Are you using fixtures for your tests? (I assume you are, from the >> assigns() usage). >> >> Can you post the fixtures? >> >>> Thanks! >> You're welcome > > the fixtures file is: > user1: > id: 1 > login: testuser1 > user_name:asb > password: 123 > created_at: 2006-04-12 14:30:25 > user2: > id: 2 > login: testuser2 > user_name:asb123 > password: 123 > created_at: 2006-04-12 14:30:25