Sha256: 09964e22115242fdb92d0d3c70a0c9cf0c5d7c7a68c3de1bace5dedd81d2e07f

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

require 'ronin/web/extensions/hpricot'

require 'spec_helper'

describe Hpricot do
  before(:all) do
    @doc = Hpricot(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html <i>page</i>.</p></div></body></html>})

    @edited_doc = Hpricot(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html page.</p></div></body></html>})
  end

  it "should be able to test if two elements are equal" do
    elem1 = @doc.at('b')
    elem2 = @edited_doc.at('b')

    (elem1 == elem2).should == true
  end

  it "should be able to test if two elements are not equal" do
    elem1 = @doc.at('p').children.last
    elem2 = @edited_doc.at('b')

    (elem1 == elem2).should == false
  end

  it "should be able to compare two elements" do
    elem1 = @doc.at('p')
    elem2 = @edited_doc.at('p')

    (elem1 > elem2).should == true
    (elem2 < elem1).should == true
  end

  it "should be able to iterate over every child" do
    children = []

    @doc.every_child { |child| children << child }

    children.length.should == 13
  end

  it "should be able to iterate over every text node" do
    text = []

    @doc.all_text { |node| text << node.content }

    text.should == ['test', 'This is a test', ' html ', 'page', '.']
  end

  it "should provide a count of all sub-children" do
    @doc.count_children.should == 13
  end

  it "should be able to test if two Hpricot documents are equal" do
    (@doc == @doc).should == true
  end

  it "should be able to compare two Hpricot documents" do
    (@doc > @edited_doc).should == true
    (@edited_doc < @doc).should == true
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ronin-0.1.2 spec/web/extensions/hpricot_spec.rb
ronin-0.1.3 spec/web/extensions/hpricot_spec.rb