Sha256: 514fb8dc8fa319f7b67436a1f8a8b2a8d5a310fcb7a2f8c033ca16ae73568e94

Contents?: true

Size: 1.32 KB

Versions: 40

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'

describe RestPack::Service::Response do
  pending "Write some specs"

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

      response.status.should == :ok
      response.code.should == 200
      response.success?.should == true
      response.result.should == { 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"]
        } }')
      )

      response.success?.should == false
      response.result.should == { key: "value" }
      response.errors.should == { 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
          RestPack::Service::Response::Status.from_code(200).should == :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

40 entries across 40 versions & 1 rubygems

Version Path
restpack_service-0.0.64 spec/response_spec.rb
restpack_service-0.0.63 spec/response_spec.rb
restpack_service-0.0.62 spec/response_spec.rb
restpack_service-0.0.61 spec/response_spec.rb
restpack_service-0.0.60 spec/response_spec.rb
restpack_service-0.0.59 spec/response_spec.rb
restpack_service-0.0.58 spec/response_spec.rb
restpack_service-0.0.57 spec/response_spec.rb
restpack_service-0.0.56 spec/response_spec.rb
restpack_service-0.0.55 spec/response_spec.rb
restpack_service-0.0.54 spec/response_spec.rb
restpack_service-0.0.53 spec/response_spec.rb
restpack_service-0.0.52 spec/response_spec.rb
restpack_service-0.0.51 spec/response_spec.rb
restpack_service-0.0.50 spec/response_spec.rb
restpack_service-0.0.49 spec/response_spec.rb
restpack_service-0.0.48 spec/response_spec.rb
restpack_service-0.0.47 spec/response_spec.rb
restpack_service-0.0.46 spec/response_spec.rb
restpack_service-0.0.45 spec/response_spec.rb