File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
lib/bnet_scraper/starcraft2 Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -20,11 +20,15 @@ class BaseScraper
2020 def initialize options = { }
2121 if options [ :url ]
2222 extracted_data = options [ :url ] . match ( /http:\/ \/ (.+)\/ sc2\/ (.+)\/ profile\/ (.+)\/ (\d {1})\/ (.[^\/ ]+)\/ / )
23- @region = REGION_DOMAINS [ extracted_data [ 1 ] ]
24- @bnet_id = extracted_data [ 3 ]
25- @bnet_index = extracted_data [ 4 ]
26- @account = extracted_data [ 5 ]
27- @url = options [ :url ]
23+ if extracted_data
24+ @region = REGION_DOMAINS [ extracted_data [ 1 ] ]
25+ @bnet_id = extracted_data [ 3 ]
26+ @bnet_index = extracted_data [ 4 ]
27+ @account = extracted_data [ 5 ]
28+ @url = options [ :url ]
29+ else
30+ raise BnetScraper ::InvalidProfileError , "URL provided does not match Battle.net format"
31+ end
2832 elsif options [ :bnet_id ] && options [ :account ]
2933 @bnet_id = options [ :bnet_id ]
3034 @account = options [ :account ]
Original file line number Diff line number Diff line change 66 let ( :subject ) { scraper_class . new ( url : 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/' ) }
77 end
88
9+ it 'raises InvalidProfileError on poorly formatted URL' do
10+ expect {
11+ BnetScraper ::Starcraft2 ::BaseScraper . new url : 'mangled_url'
12+ } . to raise_error BnetScraper ::InvalidProfileError
13+ end
14+
915 describe '#scrape' do
1016 it 'should raise an error calling scrape' do
1117 expect { subject . scrape } . to raise_error NotImplementedError
You can’t perform that action at this time.
0 commit comments