Tôi muốn kiểm tra hành động của bộ điều khiển và thông báo flash hiện diện với rspec.Rspec 3 cách kiểm tra thông báo flash
hành động:
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
đặc tả:
describe "#create" do
it "sends reset password instructions if user exists" do
post :create, email: "[email protected]"
expect(response).to redirect_to(root_path)
expect(flash[:success]).to be_present
end
...
Nhưng tôi đã có một lỗi:
Failure/Error: expect(flash[:success]).to be_present
expected `nil.present?` to return true, got false
Ồ, xin lỗi, tôi vừa bị trượt ở đây. Lỗi tương tự với flash [: notice] – MikeAndr
Trong trường hợp đó, sự cố có thể xảy ra với mã điều khiển và/hoặc dữ liệu thử nghiệm của bạn. Cố gắng thay đổi 'mong đợi (flash [: thông báo])' thành 'mong đợi (flash [: alert])', và nếu kiểm tra vượt qua thì có lẽ nó chỉ là email kiểm tra không tồn tại. – rabusmar