-1
我正在編寫更新密碼的測試! 這裏是我的代碼:使用Rspec更新密碼測試
def update_password
if @current_user.update(user_params)
# Sign in the user by passing validation in case their password changed
# sign_in @user, :bypass => true
json_success("Password successfully updated")
else
json_not_found("#{ @user.errors.full_messages.to_sentence}")
end
末
和我的測試是:
context 'update password' do
def update_password
patch :update_password, { password: 'password',
password_confirmation: 'password' }
end
it 'should update user password on user request' do
expect(user.valid_password?('password')).to eq(false)
update_password
user.reload
puts response.body.inspect
expect(user.valid_password?('password')).to eq(true)
end
end
,但我不斷收到錯誤:
1) Api::V2::UsersController patch #update_password update password should update user password on user request
Failure/Error: expect(user.valid_password?('password')).to eq(true)
expected: true
got: false
(compared using ==)
還有一個追問如何會傳遞一個帶有驗證令牌的json頭文件:謝謝