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