Skip to content

Commit 70fadab

Browse files
committed
Adds InvalidProfileError to AchievementScraper
1 parent 9c8e24d commit 70fadab

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lib/bnet_scraper/starcraft2/achievement_scraper.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ def scrape
4444
# retrieves the account's achievements overview page HTML for scraping
4545
def get_response
4646
response = Faraday.get "#{profile_url}achievements/"
47-
@response = Nokogiri::HTML(response.body)
47+
if response.success?
48+
@response = Nokogiri::HTML(response.body)
49+
else
50+
raise BnetScraper::InvalidProfileError
51+
end
4852
end
4953

5054
# scrapes the recent achievements from the account's achievements overview page

spec/starcraft2/achievement_scraper_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
subject.should_receive(:scrape_showcase)
2626
subject.scrape
2727
end
28+
29+
it 'should return InvalidProfileError if response is 404' do
30+
url = 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/achievements/'
31+
scraper = BnetScraper::Starcraft2::AchievementScraper.new(url: url)
32+
expect { scraper.scrape }.to raise_error(BnetScraper::InvalidProfileError)
33+
end
2834
end
2935

3036
describe '#scrape_showcase' do

spec/support/load_fakeweb.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

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'
13+
FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/achievements/', body: failure_html, status: 404, content_type: 'text/html'
1314
FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/', body: profile_html, status: 200, content_type: 'text/html'
1415
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'
1516
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)