holtonma / ogwr

Scrapes the official golf world ranking and outputs it in a more usable format

This URL has Read+Write access

Mark Holton (author)
Tue Nov 18 21:03:41 -0800 2008
commit  9baf4c56ef34d9c3cabbca78c9a5cdbe0cdb5b38
tree    7225a0a2ad472c7b19e0f77912a41c56278a676c
parent  5e9680a11b6f9df9a881145604bb9b5ed59c2e42
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