Sha256: 92a212073c27d917a1ce3e44626f81c8d985e38b0792efcc46e77fd5a7076de7

Contents?: true

Size: 975 Bytes

Versions: 2

Compression:

Stored size: 975 Bytes

Contents

# encoding: UTF-8

require 'spec_helper'

describe JsonWriteStream::YieldingWriter do
  let(:stream) { StringIO.new }
  let(:stream_writer) { JsonWriteStream::YieldingWriter.new(stream) }

  def check_roundtrip(obj)
    YieldingRoundtripChecker.check_roundtrip(obj)
  end

  it_behaves_like 'a json stream'

  describe '#write_key_value' do
    it 'converts all keys to strings' do
      stream_writer.write_object do |object_writer|
        object_writer.write_key_value(123, 'abc')
      end

      expect(stream.string).to eq('{"123":"abc"}')
    end

    it 'supports non-string values' do
      stream_writer.write_object do |object_writer|
        object_writer.write_key_value('abc', 123)
        object_writer.write_key_value('def', true)
      end

      expect(stream.string).to eq('{"abc":123,"def":true}')
    end
  end

  describe '#close' do
    it 'closes the underlying stream' do
      stream_writer.close
      expect(stream).to be_closed
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
json-write-stream-1.0.1 spec/yielding_spec.rb
json-write-stream-1.0.0 spec/yielding_spec.rb