Skip to content

Commit 69f9f1b

Browse files
committed
Adds conditions for accounts without laddering
1 parent b7ebd0c commit 69f9f1b

File tree

5 files changed

+1605
-1
lines changed

5 files changed

+1605
-1
lines changed

lib/bnet_scraper/starcraft2/profile_scraper.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ def get_profile_data
3535
if response.success?
3636
html = Nokogiri::HTML(response.body)
3737

38-
@race = html.css("#season-snapshot .module-footer a").first().inner_html()
38+
if race_div = html.css("#season-snapshot .module-footer a").first()
39+
@race = race_div.inner_html()
40+
end
41+
3942
@wins = html.css("#career-stats h2").inner_html()
4043
@achievement_points = html.css("#profile-header h3").inner_html()
4144
else

spec/starcraft2/profile_scraper_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@
3636
subject.should_receive(:get_profile_data)
3737
subject.scrape
3838
end
39+
3940
it 'should call get_league_list' do
4041
subject.should_receive(:get_league_list)
4142
subject.scrape
4243
end
4344

45+
46+
4447
it 'should call output' do
4548
subject.should_receive(:output)
4649
subject.scrape
@@ -50,6 +53,21 @@
5053
scraper = BnetScraper::Starcraft2::ProfileScraper.new url: 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/'
5154
expect { scraper.scrape }.to raise_error(BnetScraper::InvalidProfileError)
5255
end
56+
57+
context 'account that has not laddered' do
58+
let(:scraper) {BnetScraper::Starcraft2::ProfileScraper.new(url: 'http://us.battle.net/sc2/en/profile/3354437/1/ClarkeKent/') }
59+
before do
60+
scraper.scrape
61+
end
62+
63+
it 'should set nil race' do
64+
scraper.race.should be_nil
65+
end
66+
67+
it 'should have an empty array of leagues' do
68+
scraper.leagues.should == []
69+
end
70+
end
5371
end
5472

5573
describe '#output' do

spec/support/load_fakeweb.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
matches_html = File.read File.dirname(__FILE__) + '/matches.html'
88
status_html = File.read File.dirname(__FILE__) + '/status.html'
99
failure_html = File.read File.dirname(__FILE__) + '/failure.html'
10+
no_ladder_html = File.read File.dirname(__FILE__) + '/no_ladder.html'
11+
no_leagues_html = File.read File.dirname(__FILE__) + '/no_ladder_leagues.html'
1012

1113
FakeWeb.allow_net_connect = false
1214
FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/', body: failure_html, status: 404, content_type: 'text/html'
@@ -31,3 +33,5 @@
3133
FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/achievements/', body: achievements_html, status: 200, content_type: 'text/html'
3234
FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/matches', body: matches_html, status: 200, content_type: 'text/html'
3335
FakeWeb.register_uri :get, 'http://www.teamliquid.net/forum/viewmessage.php?topic_id=138846', body: status_html, status: 200, content_type: 'text/html'
36+
FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/3354437/1/ClarkeKent/', body: no_ladder_html, status: 200, content_type: 'text/html'
37+
FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/3354437/1/ClarkeKent/ladder/leagues', body: no_leagues_html, status: 200, content_type: 'text/html'

0 commit comments

Comments
 (0)