summaryrefslogtreecommitdiffhomepage
path: root/spec/dispatch/adapter/errors_spec.rb
blob: 906a4c27e28426b9d222dd687c0b40c84cf64b6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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 do
      raise described_class, "test"
    end.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 do
      raise described_class, "rate limited"
    end.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