spec/stateful_spec.rb in json-write-stream-1.0.1 vs spec/stateful_spec.rb in json-write-stream-1.0.2
- old
+ new
@@ -1,27 +1,36 @@
# encoding: UTF-8
require 'spec_helper'
describe JsonWriteStream::YieldingWriter do
- let(:stream) { StringIO.new }
+ let(:stream) do
+ StringIO.new.tap do |io|
+ io.set_encoding(Encoding::UTF_8)
+ end
+ end
+
let(:stream_writer) { JsonWriteStream::StatefulWriter.new(stream) }
def check_roundtrip(obj)
StatefulRoundtripChecker.check_roundtrip(obj)
end
+ def utf8(str)
+ str.encode(Encoding::UTF_8)
+ end
+
it_behaves_like 'a json stream'
describe '#close' do
it 'unwinds the stack, adds appropriate closing punctuation for each unclosed item, and closes the stream' do
stream_writer.write_array
stream_writer.write_element('abc')
stream_writer.write_object
stream_writer.write_key_value('def', 'ghi')
stream_writer.close
- expect(stream.string).to eq('["abc",{"def":"ghi"}]')
+ expect(stream.string).to eq(utf8('["abc",{"def":"ghi"}]'))
expect(stream_writer).to be_closed
expect(stream).to be_closed
end
end