| 1 | # encoding: utf-8 |
|---|
| 2 | %w[ ../ext ./ext ../lib ./lib ].each { |lp| $: << lp } |
|---|
| 3 | |
|---|
| 4 | require 'fastxml' |
|---|
| 5 | |
|---|
| 6 | describe FastXml::Doc, " doing html parsing" do |
|---|
| 7 | before(:all) do |
|---|
| 8 | @data_raw = open( "./test_data/hasno_feed.html" ) |
|---|
| 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, {:html=>true} ) |
|---|
| 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, {:html=>true} ) |
|---|
| 32 | doc.should_not be_nil |
|---|
| 33 | doc.to_s.should_not be_nil |
|---|
| 34 | end |
|---|
| 35 | |
|---|
| 36 | it 'should be able to parse hasno and search' do |
|---|
| 37 | doc = FastHtml( @data_str ) |
|---|
| 38 | descs = (doc/"p[class=description]") |
|---|
| 39 | descs.should_not be_nil |
|---|
| 40 | descs.each do |d| |
|---|
| 41 | d.should_not be_nil |
|---|
| 42 | d.length.should_be >= 1 |
|---|
| 43 | end |
|---|
| 44 | end |
|---|
| 45 | |
|---|
| 46 | it 'should handle the twitter public timeline' do |
|---|
| 47 | raw_data = open( "./test_data/twitter_public.html" ).readlines.join('') |
|---|
| 48 | doc = FastHtml( raw_data ) |
|---|
| 49 | doc.should_not be_nil |
|---|
| 50 | doc.to_s.should_not be_nil |
|---|
| 51 | doc.to_s.length.should >= 30000 |
|---|
| 52 | doc.root.should_not be_nil |
|---|
| 53 | (doc/"").should_not be_nil |
|---|
| 54 | doc.root.children.should_not be_nil |
|---|
| 55 | end |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | it 'should be able to handle the cnn site' do |
|---|
| 60 | raw_data = open( "./test_data/cnn_main.html" ).readlines.join('') |
|---|
| 61 | doc = FastHtml( raw_data ) |
|---|
| 62 | doc.should_not be_nil |
|---|
| 63 | doc.to_s.should_not be_nil |
|---|
| 64 | doc.to_s.length.should >= 10000 |
|---|
| 65 | (doc/"").should_not be_nil |
|---|
| 66 | doc.root.children.should_not be_nil |
|---|
| 67 | end |
|---|
| 68 | |
|---|
| 69 | end |
|---|