Sha256: 3f5963d1da6f48ed876b1d09bea9cf886e7dcfd8b517aade8f61d6277d375352
Contents?: true
Size: 981 Bytes
Versions: 4
Compression:
Stored size: 981 Bytes
Contents
# encoding: utf-8 require "spec_helper" describe Her::Middleware::JsonApiParser do subject { described_class.new } context "with valid JSON body" do let(:body) { '{"data": {"type": "foo", "id": "bar", "attributes": {"baz": "qux"} }, "meta": {"api": "json api"} }' } let(:env) { { body: body } } it "parses body as json" do subject.on_complete(env) env.fetch(:body).tap do |json| expect(json[:data]).to eql( type: "foo", id: "bar", attributes: { baz: "qux" } ) expect(json[:errors]).to eql([]) expect(json[:metadata]).to eql(api: "json api") end end end # context "with invalid JSON body" do # let(:body) { '"foo"' } # it 'ensures that invalid JSON throws an exception' do # expect { subject.parse(body) }.to raise_error(Her::Errors::ParseError, 'Response from the API must behave like a Hash or an Array (last JSON response was "\"foo\"")') # end # end end
Version data entries
4 entries across 4 versions & 1 rubygems