Sha256: ea60576b8e10046398c898f7c892cbd80e4d1477b5cedc8529bea39bf310d5a2

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

# coding: utf-8

require File.dirname(__FILE__) + '/spec_helper.rb'

describe ONIX2::Writer do

  before(:each) do
    @output = StringIO.new
  end

  it "should output the correct xml metadata" do
    header = ONIX2::Header.new
    writer = ONIX2::Writer.new(@output, header)
    writer.end_document

    lines = @output.string.split("\n")

    # xml declaration
    expect(lines[0][0,5]).to be_eql("<?xml")

    # doctype
    expect(lines[1][0,9]).to be_eql("<!DOCTYPE")
  end

  it "should output the correct xml metadata when used in block form" do
    header = ONIX2::Header.new
    ONIX2::Writer.open(@output, header) { |writer| }

    lines = @output.string.split("\n")

    # xml declaration
    expect(lines[0][0,5]).to be_eql("<?xml")

    # doctype
    expect(lines[1][0,9]).to be_eql("<!DOCTYPE")
  end

  it "should output the header node" do
    header = ONIX2::Header.new

    ONIX2::Writer.open(@output, header) { |writer| }

    lines = @output.string.split("\n")

    expect(lines[3][0,7]).to be_eql("<Header")
  end

  it "should output the product node" do
    header = ONIX2::Header.new
    product = ONIX2::Product.new

    ONIX2::Writer.open(@output, header) do |writer|
      writer << product
    end

    lines = @output.string.split("\n")

    expect(lines[4][0,8]).to be_eql("<Product")
  end

  it "should correctly store finished state" do
    header = ONIX2::Header.new
    writer = ONIX2::Writer.new(@output, header)
    expect(writer).not_to be_finished
    writer.end_document
    expect(writer).to be_finished
  end

=begin
  it "should convert non-ASCII chars to references when outputting as a string" do
    header = ONIX2::Header.new
    header.from_person = "Hans Küng"
    ONIX2::Writer.open(@output, header) { |writer| }

    @output.string.include?("K&#252;ng").should be_true
  end
=end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
onix2-1.0.0 spec/writer_spec.rb