| 1 | # encoding: utf-8 |
|---|
| 2 | %w[ ../ext ./ext ../lib ./lib ].each { |lp| $: << lp } |
|---|
| 3 | |
|---|
| 4 | require 'fastxml' |
|---|
| 5 | |
|---|
| 6 | describe FastXml::Doc, " when created" do |
|---|
| 7 | before(:all) do |
|---|
| 8 | @data_raw = open( "./test_data/hasno_feed.xml" ) |
|---|
| 9 | @data_ary = @data_raw.readlines |
|---|
| 10 | @data_str = @data_ary.join('') |
|---|
| 11 | end |
|---|
| 12 | |
|---|
| 13 | before do |
|---|
| 14 | @data_raw.rewind if @data_raw |
|---|
| 15 | end |
|---|
| 16 | |
|---|
| 17 | after(:all) do |
|---|
| 18 | @data_raw.close if @data_raw |
|---|
| 19 | end |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | it 'should parse string input' do |
|---|
| 23 | @data_str.should_not be_nil |
|---|
| 24 | doc = FastXml::Doc.new( @data_str ) |
|---|
| 25 | doc.should_not be_nil |
|---|
| 26 | doc.to_s.should_not be_nil |
|---|
| 27 | end |
|---|
| 28 | |
|---|
| 29 | it 'should parse array input' do |
|---|
| 30 | @data_ary.should_not be_nil |
|---|
| 31 | doc = FastXml::Doc.new( @data_ary ) |
|---|
| 32 | doc.should_not be_nil |
|---|
| 33 | doc.to_s.should_not be_nil |
|---|
| 34 | end |
|---|
| 35 | |
|---|
| 36 | it 'should be able to parse large files' do |
|---|
| 37 | raw_data = open( "./test_data/xslspec.xml" ).readlines.join('') |
|---|
| 38 | doc = FastXml( raw_data ) |
|---|
| 39 | doc.should_not be_nil |
|---|
| 40 | doc.to_s.should_not be_nil |
|---|
| 41 | doc.to_s.length.should >= 1584496 |
|---|
| 42 | doc.root.should_not be_nil |
|---|
| 43 | (doc/"").should_not be_nil |
|---|
| 44 | doc.root.children.should_not be_nil |
|---|
| 45 | end |
|---|
| 46 | |
|---|
| 47 | it 'should be able to process io from open' do |
|---|
| 48 | doc = FastXml( open( "./test_data/hasno_feed.xml" ) ) |
|---|
| 49 | doc.should_not be_nil |
|---|
| 50 | doc.to_s.should_not be_nil |
|---|
| 51 | doc.to_s.length.should >= 200 |
|---|
| 52 | end |
|---|
| 53 | |
|---|
| 54 | it 'should be able to handle data being appended in' do |
|---|
| 55 | doc = FastXml <<-END |
|---|
| 56 | <testing/> |
|---|
| 57 | END |
|---|
| 58 | doc.should_not be_nil |
|---|
| 59 | doc.to_s.should_not be_nil |
|---|
| 60 | doc.root.to_s.should == "<testing/>" |
|---|
| 61 | end |
|---|
| 62 | |
|---|
| 63 | end |
|---|