rspec을 사용하여 컨트롤러의 동작 및 플래시 메시지 존재를 테스트하고 싶습니다.
액션 :
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
사양 :
describe "#create" do
it "sends reset password instructions if user exists" do
post :create, email: "email@example.com"
expect(response).to redirect_to(root_path)
expect(flash[:success]).to be_present
end
...
하지만 오류가 있습니다.
Failure/Error: expect(flash[:success]).to be_present
expected `nil.present?` to return true, got false