Sha256: 9cc6915591dde8bf7dabce1fd7122567038f727950ee0ec2cfb6fea6c367ae32

Contents?: true

Size: 1.75 KB

Versions: 9

Compression:

Stored size: 1.75 KB

Contents

# coding: utf-8

$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')

require 'onix'

context "ONIX::Reader" do

  before(:each) do
    data_path = File.join(File.dirname(__FILE__),"..","data")
    @file1    = File.join(data_path, "9780194351898.xml")
    @file2    = File.join(data_path, "two_products.xml")
  end

  specify "should initialize with a filename" do
    reader = ONIX::Reader.new(@file1)
    reader.instance_variable_get("@reader").should be_a_kind_of(LibXML::XML::Reader)
  end

=begin
  specify "should initialize with an IO object" do
    File.open(@file1,"rb") do |f|
      reader = ONIX::Reader.new(f)
      reader.instance_variable_get("@reader").should be_a_kind_of(LibXML::XML::Reader)
    end
  end
=end

  specify "should provide access to various XML metadata from file" do
    reader = ONIX::Reader.new(@file1)
    reader.encoding.should eql("utf-8")
    reader.xml_lang.should eql(nil)
    reader.xml_version.should eql(1.0)
    reader.version.should eql([2,1,0])
  end

  specify "should provide access to the header in an ONIX file" do
    reader = ONIX::Reader.new(@file1)
    reader.header.should be_a_kind_of(ONIX::Header)
  end

  specify "should iterate over all product records in an ONIX file" do
    reader = ONIX::Reader.new(@file1)
    counter = 0
    reader.each do |product|
      product.should be_a_kind_of(ONIX::Product)
      counter += 1
    end

    counter.should eql(1)
  end

  specify "should iterate over all product records in an ONIX file" do
    reader = ONIX::Reader.new(@file2)
    products = []
    reader.each do |product|
      products << product
    end

    products.size.should eql(2)
    products[0].record_reference.should eql("365-9780194351898")
    products[1].record_reference.should eql("9780754672326")
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
onix-0.4.0 spec/reader_spec.rb
onix-0.4.2 spec/reader_spec.rb
onix-0.4.3 spec/reader_spec.rb
onix-0.4.4 spec/reader_spec.rb
onix-0.5.1 spec/reader_spec.rb
onix-0.5.0 spec/reader_spec.rb
onix-0.4.5 spec/reader_spec.rb
onix-0.4.6 spec/reader_spec.rb
onix-0.4.7 spec/reader_spec.rb