Sha256: c2edff4d853eb94b2e87d22bf53a76a95a24b0472a80cd5ee17385bdb5af80b8

Contents?: true

Size: 1.76 KB

Versions: 14

Compression:

Stored size: 1.76 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "example_helper.rb"))

describe "Relevance::Tarantula::HtmlDocumentHandler" do
  
  before do
    @handler = Relevance::Tarantula::HtmlDocumentHandler.new(nil)
  end
  
  it "does not write HTML Scanner warnings to the console" do
    bad_html = "<html><div></form></html>"    
    err = Recording.stderr do
      @handler.handle(Relevance::Tarantula::Result.new(:response => stub(:html? => true, :body => bad_html)))
    end
    err.should == ""
  end
  
  it "ignores non-html" do
    @handler.expects(:queue_link).never
    @handler.handle(Relevance::Tarantula::Result.new(:response => stub(:html? => false, :body => '<a href="/foo">foo</a>')))
  end
  
  it "queues anchor tags" do
    @handler.expects(:queue_link).with {|*args| args[0]['href'] == "/foo" && args[1] == nil}
    @handler.handle(Relevance::Tarantula::Result.new(:response => stub(:html? => true, :body => '<a href="/foo">foo</a>')))
  end

  it "queues link tags" do
    @handler.expects(:queue_link).with {|*args| args[0]['href'] == "/bar" && args[1] == nil}
    @handler.handle(Relevance::Tarantula::Result.new(:response => stub(:html? => true, :body => '<link href="/bar">bar</a>')))
  end
  
  it "queues forms" do
    @handler.expects(:queue_form).with{|tag,referrer| Hpricot::Elem === tag}
    @handler.handle(Relevance::Tarantula::Result.new(:url => "/page-url", :response => stub(:html? => true, :body => '<form>stuff</form>')))
  end
  
  it "infers form action from page url if form is not explicit" do
    @handler.expects(:queue_form).with{|tag,referrer| tag['action'].should == '/page-url'; true }
    @handler.handle(Relevance::Tarantula::Result.new(:url => "/page-url", :response => stub(:html? => true, :body => '<form>stuff</form>')))
  end
  
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
relevance-tarantula-0.1.6 examples/relevance/tarantula/html_document_handler_example.rb
relevance-tarantula-0.1.7 examples/relevance/tarantula/html_document_handler_example.rb
relevance-tarantula-0.1.8 examples/relevance/tarantula/html_document_handler_example.rb
relevance-tarantula-0.2.0 examples/relevance/tarantula/html_document_handler_example.rb
relevance-tarantula-0.2.1 examples/relevance/tarantula/html_document_handler_example.rb
relevance-tarantula-0.3.2 examples/relevance/tarantula/html_document_handler_example.rb
relevance-tarantula-0.3.3 examples/relevance/tarantula/html_document_handler_example.rb
romanbsd-tarantula-0.1.8 examples/relevance/tarantula/html_document_handler_example.rb
romanbsd-tarantula-0.2.0 examples/relevance/tarantula/html_document_handler_example.rb
tarantula-rails3-0.3.3 examples/relevance/tarantula/html_document_handler_example.rb
panmind-tarantula-0.3.3 examples/relevance/tarantula/html_document_handler_example.rb
tarantula-0.3.3 examples/relevance/tarantula/html_document_handler_example.rb
tarantula-0.1.8 examples/relevance/tarantula/html_document_handler_example.rb
tarantula-0.2.0 examples/relevance/tarantula/html_document_handler_example.rb