Sha256: a21a8f93e113359d23993a2219c1b7a3f91a3fce7ccd0f386a85fa2236822c4c

Contents?: true

Size: 902 Bytes

Versions: 4

Compression:

Stored size: 902 Bytes

Contents

require 'spec_helper'
module Alf
  class Renderer
    describe JSON do

      context 'the class' do
        subject{ JSON }

        it_should_behave_like "a Renderer class"
      end

      context "an instance on a Relation" do
        subject{ JSON.new(input).execute("") }

        let(:input){ Relation(id: [1, 2]) }

        it 'outputs as expected' do
          subject.should eq('[{"id":1},{"id":2}]' << "\n")
        end

        it 'allows roundtripping' do
          Relation(::JSON.parse(subject)).should eq(input)
        end
      end

      context "an instance on a Hash" do
        subject{ JSON.new(input).execute("") }

        let(:input){ {id: 1} }

        it 'outputs as expected' do
          subject.should eq('{"id":1}' << "\n")
        end

        it 'allows roundtripping' do
          ::JSON.parse(subject).should eq({'id' => 1})
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alf-core-0.15.0 spec/unit/alf-io/renderer/test_json.rb
alf-core-0.14.0 spec/unit/alf-io/renderer/test_json.rb
alf-core-0.13.1 spec/unit/alf-io/renderer/test_json.rb
alf-core-0.13.0 spec/unit/alf-io/renderer/test_json.rb