Sha256: 6caf1d7007e9896723776a0dfe882f5e55117c00036f18f2acfa4f31958e0daf

Contents?: true

Size: 1.68 KB

Versions: 22

Compression:

Stored size: 1.68 KB

Contents

require File.join( File.dirname(__FILE__), '..', 'lib', 'blackbook.rb' )
require File.join( File.dirname(__FILE__), 'test_helper.rb' )
require 'test/unit'
require 'mocha'

class TestBlackbookImporterPageScraper < Test::Unit::TestCase

  include TestHelper

  def setup
    @scraper = Blackbook::Importer::PageScraper.new
  end

  def test_mechanize_patch_to_absolute_uri
    @scraper.create_agent
    response = {'content-type' => 'text/html'}
    page = WWW::Mechanize::Page.new(uri=nil, response, '<html></html>', code=nil, mech=nil)
    url = "http://localhost/?arg=val&jank=AAA%3D"
    assert_equal URI.parse(url), @scraper.agent.send(:to_absolute_uri, url)
    # pattern of odd URL created by javascript validator in AOL webmail login
    url = "http://localhost/?arg=val&jank=AAA%3D%3D"
    assert_equal URI.parse(url), @scraper.agent.send(:to_absolute_uri, url)
  end

  def test_create_agent
    agent = nil
    assert_nothing_raised do
      agent = @scraper.create_agent
    end
    assert_equal agent, @scraper.agent
    assert_equal true, agent.is_a?(WWW::Mechanize)
    assert_equal "Mozilla/4.0 (compatible; Blackbook #{Blackbook::VERSION})", agent.user_agent
    assert_equal false, agent.keep_alive
  end

  def test_strip_html
    assert_equal '', @scraper.strip_html('<foo></foo>')
    assert_equal 'bar', @scraper.strip_html('<foo>bar</foo>')
    assert_equal 'bar', @scraper.strip_html('bar</foo>')
    assert_equal 'bar', @scraper.strip_html('<foo>bar')
  end

  def test_fetch_contacts!
    @scraper.expects(:create_agent).once
    @scraper.expects(:prepare).once
    @scraper.expects(:scrape_contacts).once
    assert_nothing_raised do
      agent = @scraper.fetch_contacts!
    end
  end
end

Version data entries

22 entries across 22 versions & 5 rubygems

Version Path
alexjp-blackbook_csv-1.0.5 test/test_blackbook_importer_page_scraper.rb
alexjp-blackbook_csv-3.0.1 test/test_blackbook_importer_page_scraper.rb
alexjp-blackbook_csv-3.0.2 test/test_blackbook_importer_page_scraper.rb
bcardarella-blackbook-1.0.10 test/test_blackbook_importer_page_scraper.rb
bcardarella-blackbook-1.0.11 test/test_blackbook_importer_page_scraper.rb
bcardarella-blackbook-1.0.7 test/test_blackbook_importer_page_scraper.rb
bcardarella-blackbook-1.0.8 test/test_blackbook_importer_page_scraper.rb
bcardarella-blackbook-1.0.9 test/test_blackbook_importer_page_scraper.rb
briancollins-blackbook-1.0.15 test/test_blackbook_importer_page_scraper.rb
rakutenusa-blackbook-1.0.12 test/test_blackbook_importer_page_scraper.rb
rakutenusa-blackbook-1.0.13 test/test_blackbook_importer_page_scraper.rb
rakutenusa-blackbook-1.0.14 test/test_blackbook_importer_page_scraper.rb
rakutenusa-blackbook-1.0.15 test/test_blackbook_importer_page_scraper.rb
rakutenusa-blackbook-1.0.16 test/test_blackbook_importer_page_scraper.rb
rakutenusa-blackbook-1.0.17 test/test_blackbook_importer_page_scraper.rb
rakutenusa-blackbook-1.0.18 test/test_blackbook_importer_page_scraper.rb
rakutenusa-blackbook-1.0.19 test/test_blackbook_importer_page_scraper.rb
blackbook-1.0.0 test/test_blackbook_importer_page_scraper.rb
blackbook-1.0.3 test/test_blackbook_importer_page_scraper.rb
blackbook-1.0.2 test/test_blackbook_importer_page_scraper.rb