rspec을 사용하여 컨트롤러의 동작과 플래시 메시지 존재를 테스트하고 싶습니다.Rspec 3 플래시 메시지를 테스트하는 방법
행동 :
def create
user = Users::User.find_by_email(params[:email])
if user
user.send_reset_password_instructions
flash[:success] = "Reset password instructions have been sent to #{user.email}."
else
flash[:alert] = "Can't find user with this email: #{params[:email]}"
end
redirect_to root_path
end
사양는 :
Failure/Error: expect(flash[:success]).to be_present
expected `nil.present?` to return true, got false
아, 죄송합니다. 방금 전 미끄러졌습니다. 플래시 오류 [: notice] – MikeAndr
이 경우 문제는 아마도 컨트롤러 코드 및/또는 테스트 데이터 때문일 수 있습니다. 'expect (flash [: notice])를'expect (flash [: alert])'로 변경해보십시오. 그러면 테스트가 통과하면 아마도 테스트 이메일이 존재하지 않는다는 것입니다. – rabusmar