Sha256: c1e5726070f2a19367f87d68228585753fadf5174b28eb40ef59be8213cbc07b

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# encoding: UTF-8

require 'spec_helper'

describe YamlWriteStream::YieldingWriter do
  let(:stream) do
    StringIO.new.tap do |io|
      io.set_encoding(Encoding::UTF_8)
    end
  end

  let(:stream_writer) do
    YieldingRoundtripChecker.create_writer(stream)
  end

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

  def utf8(str)
    str.encode(Encoding::UTF_8)
  end

  it_behaves_like 'a yaml stream'

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

    it 'quotes empty strings' do
      stream_writer.write_map do |map_writer|
        map_writer.write_key_value('foo', '')
      end

      stream_writer.close
      expect(stream.string).to eq("foo: \"\"\n")
    end

    it 'writes nils as blank entries' do
      stream_writer.write_map do |map_writer|
        map_writer.write_key_value('foo', nil)
      end

      stream_writer.close
      expect(stream.string).to eq("foo: \n")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yaml-write-stream-1.0.4 spec/yielding_spec.rb
yaml-write-stream-1.0.3 spec/yielding_spec.rb