간단한 비밀번호 재설정 작업을 테스트 중이며 lambda에 대한 RSpec의 "변경"일치자를 원합니다. 그러나이 컨트롤러 동작에는 작동하지 않습니다. Matcher 없이는 모든 것이 잘 작동합니다. 다음은 사양입니다.람다가 있거나없는 컨트롤러 스펙 "이 변경되어야 함"
describe "#update" do
it "Updates the password and resets the token" do
@user = Factory :user
getter = lambda{
get :edit, :id => @user.perishable_token, :user => {:password_confirmation => "new_password",
:password => "new_password"}
@user.reload
}
getter.should change(@user, :password)
getter.should change(@user, :perishable_token)
end
it "Updates the password and resets the token" do
@user = Factory :user
old_password = @user.password
old_token = @user.perishable_token
get :edit, :id => @user.perishable_token, :user => {:password_confirmation => "new_password",
:password => "new_password"}
@user.reload.password.should != old_password
@user.perishable_token.should != old_token
end
end
두 번째 it 블록은 작동하지만 첫 번째 블록은 작동하지 않습니다. 나는 람다 내부에 값을 인쇄하려했지만 실제로 변경되지 않았습니다.
이 문제에 대한 아이디어를 제공해 주셔서 감사합니다.
람다가 이미 실행 얻을 것으로 보인다 다음은 현재 작업 코드입니다. 람다 정의와 기대 사이에 "getter.call"을 시도했지만 아무 것도 변경되지 않았습니다. 그런 다음 "getter.call.should change (@user, : password)"를 시도했지만 사용자에게 'call'메서드가 없음을 알리는 오류가 발생했습니다. 그래서 나는 lamda가 @ user.reload라는 마지막 문장을 반환했다고 결론을 내렸다. 그것은 실행 된 lamda의 끝에서 print 문을 추가함으로써 확인되었고 오류 메시지는 nil에 대해 정의되지 않은 메서드 인 'call'로 변경되었습니다. – ajmurmann