public
Description: ruby libxml library targetting speed and ease of use. provides an hpricot-like interface to xml
Homepage: http://trac.hasno.info/fastxml
Clone URL: git://github.com/segfault/fastxml.git
Search Repo:
fastxml / specs / fastxml_nodelist_spec.rb
100644 65 lines (53 sloc) 1.593 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# encoding: utf-8
%w[ ../ext ./ext ../lib ./lib ].each { |lp| $: << lp }
 
require 'fastxml'
 
describe FastXml::NodeList, ' functionality' do
  before(:all) do
    data_raw = open( "./test_data/hasno_feed.xml" )
    @data_ary = data_raw.readlines
    data_raw.close
    @data_str = @data_ary.join('')
    @doc = FastXml::Doc.new( @data_str )
    @list = @doc.children
  end
  
  it 'should provide a length method' do
    @list.length.should_not be_nil
    @list.length.should >= 1
  end
  
  it 'should have an index accessor' do
    @list[0].should_not be_nil
  end
  
  it 'should have an entry method ala Array' do
    @list.entry(0).should_not be_nil
    @list.entry(0).should == @list[0]
  end
  
  it 'entry should not explode when faced with insane indexes' do
    @list.entry(99999999**99999).should be_nil
    @list.entry(0x3fffffff).should be_nil
  end
  
  it 'should provide an each method' do
    @list.should respond_to(:each)
    cnt = 0
    @list.each do |x|
      x.should_not be_nil
      cnt += 1
    end
    @list.length.should == cnt
  end
  
  it 'should provide an inspect method' do
    @list.should respond_to( :inspect )
    @list.inspect.should_not be_nil
  end
  
  it 'should provide a first method' do
    @list.should respond_to( :first )
    @list.first.should_not be_nil
    @list.first.should == @list[0]
    @list.first.to_s.should == @list[0].to_s
  end
  
  it 'should provide a last method' do
    @list.should respond_to( :last )
    @list.last.should_not be_nil
    @list.last.should == @list[-1]
    @list.last.to_s.should == @list[-1].to_s
  end
 
end