From 3e32dec579fbdedec8c7ddb881207b25bb342e60 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Tue, 31 Mar 2026 20:22:45 +0900 Subject: imp --- spec/dispatch/adapter/errors_spec.rb | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 spec/dispatch/adapter/errors_spec.rb (limited to 'spec/dispatch/adapter/errors_spec.rb') diff --git a/spec/dispatch/adapter/errors_spec.rb b/spec/dispatch/adapter/errors_spec.rb new file mode 100644 index 0000000..77c8389 --- /dev/null +++ b/spec/dispatch/adapter/errors_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +RSpec.describe Dispatch::Adapter::Error do + it "carries message, status_code, and provider" do + error = described_class.new("test error", status_code: 500, provider: "TestProvider") + expect(error.message).to eq("test error") + expect(error.status_code).to eq(500) + expect(error.provider).to eq("TestProvider") + end + + it "defaults status_code and provider to nil" do + error = described_class.new("simple error") + expect(error.status_code).to be_nil + expect(error.provider).to be_nil + end + + it "inherits from StandardError" do + expect(described_class.ancestors).to include(StandardError) + end + + it "can be rescued as StandardError" do + expect { + raise described_class.new("test") + }.to raise_error(StandardError) + end +end + +RSpec.describe Dispatch::Adapter::AuthenticationError do + it "inherits from Error" do + expect(described_class.ancestors).to include(Dispatch::Adapter::Error) + end +end + +RSpec.describe Dispatch::Adapter::RateLimitError do + it "carries retry_after" do + error = described_class.new("rate limited", status_code: 429, provider: "Test", retry_after: 30) + expect(error.retry_after).to eq(30) + expect(error.status_code).to eq(429) + end + + it "defaults retry_after to nil" do + error = described_class.new("rate limited") + expect(error.retry_after).to be_nil + end + + it "is rescuable as Dispatch::Adapter::Error" do + expect { + raise described_class.new("rate limited") + }.to raise_error(Dispatch::Adapter::Error) + end +end + +RSpec.describe Dispatch::Adapter::ServerError do + it "inherits from Error" do + expect(described_class.ancestors).to include(Dispatch::Adapter::Error) + end +end + +RSpec.describe Dispatch::Adapter::RequestError do + it "inherits from Error" do + expect(described_class.ancestors).to include(Dispatch::Adapter::Error) + end +end + +RSpec.describe Dispatch::Adapter::ConnectionError do + it "inherits from Error" do + expect(described_class.ancestors).to include(Dispatch::Adapter::Error) + end +end -- cgit v1.2.3