Sha256: 2c39e1adfb473b2f350f63dd1e0cae046bf65d573cd14fb75f9220683330531d

Contents?: true

Size: 1.07 KB

Versions: 14

Compression:

Stored size: 1.07 KB

Contents

require 'spec_helper'

RSpec.describe RDStation::ApiResponse do
  describe ".build" do
    context "when the response HTTP status is 2xx" do
      let(:response) { OpenStruct.new(code: 200, body: '{}') }

      it "returns the response body" do
        expect(RDStation::ApiResponse.build(response)).to eq({})
      end
    end

    shared_examples_for 'call_error_handler' do
      it "calls error handler" do
        error_handler = instance_double(RDStation::ErrorHandler)
        allow(error_handler).to receive(:raise_error)
        expect(RDStation::ErrorHandler).to receive(:new).with(response).and_return(error_handler)
        RDStation::ApiResponse.build(response)
      end
    end

    context "when the response is not in the 2xx range" do
      let(:response) { OpenStruct.new(code: 404, body: '{}') }

      it_behaves_like 'call_error_handler'
    end

    context "when the response body is not JSON-parseable" do
      let(:response) { OpenStruct.new(code: 504, body: '<html><head></head><body></body></html>') }

      it_behaves_like 'call_error_handler'
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rdstation-ruby-client-2.9.0 spec/lib/rdstation/api_response_spec.rb
rdstation-ruby-client-2.8.2 spec/lib/rdstation/api_response_spec.rb
rdstation-ruby-client-2.8.1 spec/lib/rdstation/api_response_spec.rb
rdstation-ruby-client-2.8.0 spec/lib/rdstation/api_response_spec.rb
rdstation-ruby-client-2.7.0 spec/lib/rdstation/api_response_spec.rb
rdstation-ruby-client-2.6.0 spec/lib/rdstation/api_response_spec.rb
rdstation-ruby-client-2.5.3 spec/lib/rdstation/api_response_spec.rb
rdstation-ruby-client-2.5.2 spec/lib/rdstation/api_response_spec.rb
rdstation-ruby-client-2.5.1 spec/lib/rdstation/api_response_spec.rb
rdstation-ruby-client-2.5.0 spec/lib/rdstation/api_response_spec.rb
rdstation-ruby-client-2.4.0 spec/lib/rdstation/api_response_spec.rb
rdstation-ruby-client-2.3.1 spec/lib/rdstation/api_response_spec.rb
rdstation-ruby-client-2.3.0 spec/lib/rdstation/api_response_spec.rb
rdstation-ruby-client-2.2.0 spec/lib/rdstation/api_response_spec.rb