public
Description: Scrapes the official golf world ranking and outputs it in a more usable format
Homepage: http://holtsblog.blogspot.com/2008/10/open-source-ogwr-scraper.html
Clone URL: git://github.com/holtonma/ogwr.git
ogwr / test_ogwr.rb
100644 70 lines (57 sloc) 2.015 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'ogwr'
require 'rubygems'
require 'test/unit'
require 'flexmock/test_unit'
require 'stringio'
require 'ostruct'
 
class TestOGWR < Test::Unit::TestCase
  include OGWR
  
  def setup
    # i really should mock this out and not hit the network... will do that later
    # page = 1
    # url = "http://www.officialworldgolfranking.com/rankings/default.sps?region=world&PageCount=#{page}"
    # flexmock(fetcher).should_receive(:open).with(url, page).and_return{
    # File.open(sample.html, 'r')
    # }
  end
  
  def test_scrape_top50
    fetcher = Fetcher.new
    page = 1
    url = "http://www.officialworldgolfranking.com/rankings/default.sps?region=world&PageCount=#{page}"
    players = fetcher.fetch(url, page)
    assert_equal 50, players.length
    assert_equal 1, players[0].rank
    assert_equal "Tiger", players[0].fname
    assert_equal "Woods", players[0].lname
  end
  
  def test_scrape_251to300
    fetcher = Fetcher.new
    page = 6
    url = "http://www.officialworldgolfranking.com/rankings/default.sps?region=world&PageCount=#{page}"
    players = fetcher.fetch(url, page)
    assert_equal 50, players.length
    assert_equal 251, players[0].rank
    assert_equal "Marc", players[0].fname
    assert_equal "Warren", players[0].lname
  end
  
  def test_via_noko
    fetcher = Fetcher.new
    page = 6
    url = "http://www.officialworldgolfranking.com/rankings/default.sps?region=world&PageCount=#{page}"
    data = fetcher.fetch_via_noko(url, page)
    #puts data
    #puts "data.length: #{data.length}"
  end
  
  def test_friendly_structure
    fetcher = Fetcher.new
    #page = 6
    (1..6).each do |page|
      url = "http://www.officialworldgolfranking.com/rankings/default.sps?region=world&PageCount=#{page}"
      players = fetcher.friendly_structure(fetcher.fetch_via_noko(url, page))
      players.each do |p|
        puts "#{p.rank} :: #{p.fname} #{p.lname} #{p.avg_pts} #{p.tot_pts}"
      end
      assert_equal 50, players.length
      
    end
    
  end
  
  
  
end