Files
ubicloud/spec/routes/web/clover_web_spec.rb
Jeremy Evans a36710b96a Do not swallow unexpected errors when testing
Swallowing unexpected errors during testing makes debugging much
more difficult.  This only swallows errors that we expect the
error handler to catch.

To avoid duplication, this inlines parse_error into the error
handler.  parse_error was needed as a separate method back when
we had CloverWeb and CloverApi, but it no longer needs to be
a separate method.  This adds raising to the code that was in
parse_error, and it doesn't make sense for a method named
parse_error to raise, so inlining into the error handler makes
sense.

This does an earlier return for 204 response, avoiding
unnecessary hash allocation, and avoiding the need for elsif.

As all local variables are now defined in the error handler,
this uses the local variables directly, instead on indirectly
through the error hash.

Also use hash value ommission to DRY up code.

Co-authored-by: Enes Cakir <enes@ubicloud.com>
2024-11-20 10:41:15 -08:00

29 lines
784 B
Ruby

# frozen_string_literal: true
require_relative "spec_helper"
RSpec.describe Clover do
it "handles CSRF token errors" do
visit "/login"
find("input[name=_csrf]", visible: false).set("")
click_button "Sign in"
expect(page.status_code).to eq(200)
expect(page).to have_content("An invalid security token submitted with this request")
end
it "handles expected errors" do
expect(Clog).to receive(:emit).with("route exception").and_call_original
visit "/webhook/test-error"
expect(page.title).to eq("Ubicloud - UnexceptedError")
end
it "raises unexpected errors in test environment" do
expect(Clog).not_to receive(:emit)
expect { visit "/webhook/test-error?message=treat+as+unexpected+error" }.to raise_error(RuntimeError)
end
end