Sha256: 5a2cb11074703e2e79a80a932abc8254175e647d67ab47405f3fc776fb3c2364

Contents?: true

Size: 1.33 KB

Versions: 19

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'

describe RestPack::Service::Response do
  describe '#from_rest' do
    it 'parses a successful response' do
      response = RestPack::Service::Response.from_rest(
        double(code: 200, body: '{ "key": "value" }')
      )

      expect(response.status).to eq(:ok)
      expect(response.code).to eq(200)
      expect(response.success?).to eq(true)
      expect(response.result).to eq({ key: "value" })
    end

    it "extracts errors from response body" do
      response = RestPack::Service::Response.from_rest(
        double(code: 200, body: '{ "key": "value", "errors": {
          "name": ["error 1", "error 2"]
        } }')
      )

      expect(response.success?).to eq(false)
      expect(response.result).to eq({ key: "value" })
      expect(response.errors).to eq({ name: ["error 1", "error 2"] })
    end

  end

  describe RestPack::Service::Response::Status do
    describe '#from_code' do
      context 'valid status' do
        it 'maps a code to a status' do
          expect(RestPack::Service::Response::Status.from_code(200)).to eq(:ok)
        end
      end

      context 'invalid status' do
        it 'raises an exception' do
          expect {
            RestPack::Service::Response::Status.from_code(999)
          }.to raise_exception('Invalid Status Code: 999')
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
restpack_service-0.0.83 spec/response_spec.rb
restpack_service-0.0.82 spec/response_spec.rb
restpack_service-0.0.81 spec/response_spec.rb
restpack_service-0.0.80 spec/response_spec.rb
restpack_service-0.0.79 spec/response_spec.rb
restpack_service-0.0.78 spec/response_spec.rb
restpack_service-0.0.77 spec/response_spec.rb
restpack_service-0.0.76 spec/response_spec.rb
restpack_service-0.0.75 spec/response_spec.rb
restpack_service-0.0.74 spec/response_spec.rb
restpack_service-0.0.73 spec/response_spec.rb
restpack_service-0.0.72 spec/response_spec.rb
restpack_service-0.0.71 spec/response_spec.rb
restpack_service-0.0.70 spec/response_spec.rb
restpack_service-0.0.69 spec/response_spec.rb
restpack_service-0.0.68 spec/response_spec.rb
restpack_service-0.0.67 spec/response_spec.rb
restpack_service-0.0.66 spec/response_spec.rb
restpack_service-0.0.65 spec/response_spec.rb