Sha256: 8b3bb9c1a2ca5a71ff45b47900d7d60af0f10bb35abe3cf61ebb1903646b52ec

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

describe Moip2::Response do
  let(:parsed_json) { { "id" => "ORD-SOMETHING" } }

  let(:response) { described_class.new(nil, parsed_json) }

  describe "method delegation" do
    it "delegates []" do
      expect(response["id"]).to eq("ORD-SOMETHING")
    end

    it "delegates attribute to property accessor" do
      expect(response.id).to eq("ORD-SOMETHING")
    end
  end

  describe "#success?" do
    let(:success_response) do
      double("Success Response").tap do |success_response|
        allow(success_response).to receive(:code).and_return(200)
      end
    end

    let(:response) { described_class.new(success_response, parsed_json) }

    it "returns true when response code == 2xx" do
      expect(response).to be_success
    end
  end

  describe "#client_error?" do
    let(:error_response) do
      double("Error Response").tap do |error_response|
        allow(error_response).to receive(:code).and_return(400)
      end
    end

    let(:response) { described_class.new(error_response, {}) }

    it "returns false when response code == 4xx" do
      expect(response).to be_client_error
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
moip2-1.0.0 spec/moip2/response_spec.rb