|
1 | 1 | require 'spec_helper'
|
2 | 2 |
|
3 | 3 | describe BnetScraper::Starcraft2::LeagueScraper do
|
| 4 | + let(:url) { "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/12345" } |
| 5 | + subject { BnetScraper::Starcraft2::LeagueScraper.new(url) } |
| 6 | + |
4 | 7 | describe '#initialize' do
|
5 | 8 | it 'should take a league URL parameter' do
|
6 |
| - url = "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/12345" |
7 |
| - scraper = BnetScraper::Starcraft2::LeagueScraper.new(url) |
8 |
| - scraper.url.should == url |
| 9 | + subject.url.should == url |
| 10 | + end |
| 11 | + |
| 12 | + it 'should dissect the bnet_id from the URL' do |
| 13 | + subject.bnet_id.should == '2377239' |
| 14 | + end |
| 15 | + |
| 16 | + it 'should dissect the account from the URL' do |
| 17 | + subject.account.should == 'Demon' |
| 18 | + end |
| 19 | + |
| 20 | + it 'should dissect the league_id from the URL' do |
| 21 | + subject.league_id.should == '12345' |
| 22 | + end |
| 23 | + |
| 24 | + it 'should dissect the bnet_index from the URL' do |
| 25 | + subject.bnet_index.should == '1' |
| 26 | + end |
| 27 | + |
| 28 | + it 'should dissect the lang from the URL' do |
| 29 | + subject.lang.should == 'en' |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + describe '#scrape' do |
| 34 | + it 'should set the season value' do |
| 35 | + subject.season.should be_nil |
| 36 | + subject.scrape |
| 37 | + subject.season.should == '6' |
| 38 | + end |
| 39 | + |
| 40 | + it 'should set the name' do |
| 41 | + subject.name.should be_nil |
| 42 | + subject.scrape |
| 43 | + subject.name.should == 'Aleksander Pepper' |
| 44 | + end |
| 45 | + |
| 46 | + it 'should set the divison' do |
| 47 | + subject.division.should be_nil |
| 48 | + subject.scrape |
| 49 | + subject.division.should == 'Diamond' |
| 50 | + end |
| 51 | + |
| 52 | + it 'should set the size' do |
| 53 | + subject.size.should be_nil |
| 54 | + subject.scrape |
| 55 | + subject.size.should == '4v4' |
| 56 | + end |
| 57 | + |
| 58 | + it 'should set if player is random' do |
| 59 | + subject.random.should be_nil |
| 60 | + subject.scrape |
| 61 | + subject.random.should be_false |
| 62 | + end |
| 63 | + |
| 64 | + it 'should call parse_response' do |
| 65 | + subject.should_receive(:parse_response) |
| 66 | + subject.scrape |
| 67 | + end |
| 68 | + end |
| 69 | + |
| 70 | + describe '#parse_response' do |
| 71 | + it 'should return a hash of league data' do |
| 72 | + expected = { |
| 73 | + season: '6', |
| 74 | + name: 'Aleksander Pepper', |
| 75 | + division: 'Diamond', |
| 76 | + size: '4v4', |
| 77 | + random: false, |
| 78 | + bnet_id: '2377239', |
| 79 | + account: 'Demon' |
| 80 | + } |
| 81 | + |
| 82 | + subject.scrape |
| 83 | + subject.parse_response.should == expected |
9 | 84 | end
|
10 | 85 | end
|
11 | 86 | end
|
0 commit comments