Skip to content

Commit 06037ba

Browse files
committed
Adds InvalidProfileError to LeagueScraper
1 parent 70fadab commit 06037ba

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

lib/bnet_scraper/starcraft2/league_scraper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def scrape
4141

4242
@random = !@random.nil?
4343
output
44+
else
45+
raise BnetScraper::InvalidProfileError
4446
end
4547
end
4648

spec/starcraft2/league_scraper_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
subject.should_receive(:output)
5151
subject.scrape
5252
end
53+
54+
it 'should raise InvalidProfileError when response is 404' do
55+
url = 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/leagues/12345'
56+
scraper = BnetScraper::Starcraft2::LeagueScraper.new(url: url)
57+
expect { scraper.scrape }.to raise_error(BnetScraper::InvalidProfileError)
58+
end
5359
end
5460

5561
describe '#output' do

spec/support/load_fakeweb.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
FakeWeb.allow_net_connect = false
1212
FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/', body: failure_html, status: 404, content_type: 'text/html'
1313
FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/achievements/', body: failure_html, status: 404, content_type: 'text/html'
14+
FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/leagues/12345', body: failure_html, status: 404, content_type: 'text/html'
1415
FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/', body: profile_html, status: 200, content_type: 'text/html'
1516
FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/leagues', body: leagues_html, status: 200, content_type: 'text/html'
1617
FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/12345', body: league_html, status: 200, content_type: 'text/html'

0 commit comments

Comments
 (0)