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
fastxml / specs / fastxml_node_attribute_spec.rb
100644 45 lines (39 sloc) 1.373 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
# encoding: utf-8 # :nodoc:
%w[ ../ext ./ext ../lib ./lib ].each { |lp| $: << lp }
require 'fastxml'
 
describe FastXml::AttrList, ' 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 )
    @node = @doc.root
  end
  
  it 'should provide an indexer [] method using both symbols and strings' do
    @node.should respond_to( 'attr' )
    @node.attr.should respond_to( '[]' )
    @node.attr[:ab].should be_nil
    @node.attr["ab"].should be_nil
  end
  
  it 'should provide an indexer p[] mutator method using both symbols and strings' do
    @node.should respond_to( 'attr' )
    @node.attr.should respond_to( '[]' )
    @node.attr[:ab] = "test"
    @node.attr[:ab].should == "test"
    @node.attr["ab"].should == "test"
  end
  
  it 'should provide an include? method' do
    @node.should respond_to( 'attr' )
    @node.attr.should respond_to( 'include?' )
    @node.attr.include?(:ab).should == true
  end
 
  it "should remove an attribute when it's value is set to nil" do
    @node.should respond_to( 'attr' )
    @node.attr.should respond_to( '[]' )
    @node.attr[:ab].should == "test"
    @node.attr[:ab] = nil
    @node.attr[:ab].should == nil
    @node.attr.include?(:ab).should == nil
  end
end