From: James Hunt Date: 2007-09-09T16:25:23+09:00 Subject: Re: how to fix assigns(:user) on controller test On 9/8/07, OnRails Ruby claimed: > Hi everyon, > Thank you for your help! > I did the controller test, but there is a problem when run the test. > > def test_should_allow_password_change > post :change_password, { :old_password => '123', :password => > 'newpassword', :password_confirmation => 'newpassword'}, > {:user_id=>users(:user1).id} > assert_equal 'newpassword', assigns(:user).password > end > > 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 > Are you using fixtures for your tests? (I assume you are, from the assigns() usage). Can you post the fixtures? > Thanks! You're welcome -- James