Add RSpec suite with WebMock: core, OAuth, pagination, and resource behavior
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Fiken::Object do
|
||||
subject(:object) do
|
||||
described_class.new(
|
||||
"invoiceNumber" => 5,
|
||||
"customer" => { "name" => "Acme" },
|
||||
"lines" => [{ "vat" => 25 }, { "vat" => 0 }]
|
||||
)
|
||||
end
|
||||
|
||||
it "exposes camelCase keys via dot access" do
|
||||
expect(object.invoiceNumber).to eq(5)
|
||||
end
|
||||
|
||||
it "exposes the same keys via snake_case dot access" do
|
||||
expect(object.invoice_number).to eq(5)
|
||||
end
|
||||
|
||||
it "supports hash-style access with string or symbol keys" do
|
||||
expect(object[:invoiceNumber]).to eq(5)
|
||||
expect(object["invoiceNumber"]).to eq(5)
|
||||
end
|
||||
|
||||
it "wraps nested hashes recursively" do
|
||||
expect(object.customer.name).to eq("Acme")
|
||||
end
|
||||
|
||||
it "wraps arrays of hashes recursively" do
|
||||
expect(object.lines.map(&:vat)).to eq([25, 0])
|
||||
end
|
||||
|
||||
it "round-trips to a plain hash" do
|
||||
expect(object.to_h).to eq(
|
||||
invoiceNumber: 5,
|
||||
customer: { name: "Acme" },
|
||||
lines: [{ vat: 25 }, { vat: 0 }]
|
||||
)
|
||||
end
|
||||
|
||||
it "raises NoMethodError for unknown keys" do
|
||||
expect { object.nope }.to raise_error(NoMethodError)
|
||||
end
|
||||
|
||||
it "answers key? for present and absent keys" do
|
||||
expect(object.key?(:invoiceNumber)).to be(true)
|
||||
expect(object.key?(:missing)).to be(false)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user