Add RSpec suite with WebMock: core, OAuth, pagination, and resource behavior

This commit is contained in:
2026-05-29 15:01:18 +02:00
parent 3b4d5ae5c3
commit 6a4380637a
7 changed files with 413 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
# frozen_string_literal: true
RSpec.describe Fiken::Error do
describe ".from_response" do
it "maps known statuses to specific subclasses" do
{
400 => Fiken::BadRequest,
401 => Fiken::Unauthorized,
403 => Fiken::Forbidden,
404 => Fiken::NotFound,
422 => Fiken::UnprocessableEntity,
429 => Fiken::RateLimited
}.each do |status, klass|
expect(described_class.from_response(status, {})).to be_a(klass)
end
end
it "maps unknown 5xx statuses to ServerError" do
expect(described_class.from_response(503, "")).to be_a(Fiken::ServerError)
end
it "extracts a message from a JSON error body" do
error = described_class.from_response(400, { "message" => "Bad slug" })
expect(error.message).to eq("Bad slug")
expect(error.status).to eq(400)
end
it "falls back to a generic message when the body has none" do
error = described_class.from_response(404, "")
expect(error.message).to eq("Fiken API error (HTTP 404)")
end
end
end