spec/stateful_spec.rb in xml-write-stream-1.0.2 vs spec/stateful_spec.rb in xml-write-stream-1.1.0
- old
+ new
@@ -43,26 +43,47 @@
stream_writer.write_header
end.to raise_error(XmlWriteStream::InvalidHeaderPositionError)
end
end
+ describe '#open_single_line_tag' do
+ it 'writes a tag and its contents on a single line' do
+ stream_writer.open_single_line_tag('maytag')
+ stream_writer.write_text('foobar')
+ stream_writer.close_tag
+ expect(stream.string).to eq("<maytag>foobar</maytag>")
+ end
+
+ it 'works with nested tags' do
+ stream_writer.open_single_line_tag('maytag')
+ stream_writer.write_text('foobar')
+ stream_writer.open_single_line_tag('gutentag')
+ stream_writer.write_text('foobaz')
+ stream_writer.close_tag
+ stream_writer.close_tag
+ expect(stream.string).to eq(
+ "<maytag>foobar<gutentag>foobaz</gutentag></maytag>"
+ )
+ end
+ end
+
describe '#open_tag' do
it 'writes an opening tag' do
stream_writer.open_tag('maytag')
stream_writer.close
expect(stream.string).to eq(
- utf8("<maytag>\n</maytag>\n")
+ utf8("<maytag>\n</maytag>")
)
end
it 'writes an opening tag with attributes' do
stream_writer.open_tag('maytag', type: 'washing_machine')
stream_writer.close
expect(stream.string).to eq(
- utf8("<maytag type=\"washing_machine\">\n</maytag>\n")
+ utf8("<maytag type=\"washing_machine\">\n</maytag>")
)
end
it 'raises an error if one of the attribute keys is invalid' do
expect do
@@ -80,11 +101,11 @@
stream_writer.open_tag('foo9')
stream_writer.open_tag('bar:baz')
stream_writer.close
expect(stream.string).to eq(
- utf8("<foo9>\n <bar:baz>\n </bar:baz>\n</foo9>\n")
+ utf8("<foo9>\n <bar:baz>\n </bar:baz>\n</foo9>")
)
end
it 'raises an error if the stream is already closed' do
stream_writer.close
@@ -99,11 +120,11 @@
it 'closes the currently open tag' do
stream_writer.open_tag('maytag')
stream_writer.close_tag
expect(stream.string).to eq(
- utf8("<maytag>\n</maytag>\n")
+ utf8("<maytag>\n</maytag>")
)
end
end
describe '#write_text' do
@@ -111,21 +132,21 @@
stream_writer.open_tag('places')
stream_writer.write_text("Alaska & Hawai'i")
stream_writer.close
expect(stream.string).to eq(
- utf8("<places>\n Alaska & Hawai'i\n</places>\n")
+ utf8("<places>\n Alaska & Hawai'i\n</places>")
)
end
it 'writes raw text if asked not to escape' do
stream_writer.open_tag('places')
stream_writer.write_text("Alaska & Hawai'i", escape: false)
stream_writer.close
expect(stream.string).to eq(
- utf8("<places>\n Alaska & Hawai'i\n</places>\n")
+ utf8("<places>\n Alaska & Hawai'i\n</places>")
)
end
it 'raises an error if no tag has been written yet' do
expect do
@@ -148,11 +169,11 @@
stream_writer.open_tag('bar')
stream_writer.open_tag('baz')
stream_writer.flush
expect(stream.string).to eq(
- utf8("<foo>\n <bar>\n <baz>\n </baz>\n </bar>\n</foo>\n")
+ utf8("<foo>\n <bar>\n <baz>\n </baz>\n </bar>\n</foo>")
)
expect(stream).to_not be_closed
expect(stream_writer).to be_eos
end
@@ -164,10 +185,10 @@
stream_writer.open_tag('bar')
stream_writer.open_tag('baz')
stream_writer.close
expect(stream.string).to eq(
- utf8("<foo>\n <bar>\n <baz>\n </baz>\n </bar>\n</foo>\n")
+ utf8("<foo>\n <bar>\n <baz>\n </baz>\n </bar>\n</foo>")
)
expect(stream).to be_closed
expect(stream_writer).to be_eos
end