|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | describe BnetScraper::Starcraft2::ProfileScraper do |
4 | | - subject { BnetScraper::Starcraft2::ProfileScraper.new(bnet_id: '2377239', account: 'Demon') } |
5 | | - |
6 | | - describe '#initialize' do |
7 | | - context 'when bnet_id and account parameters are passed' do |
8 | | - it 'should set the bnet_id and account parameters' do |
9 | | - subject.bnet_id.should == '2377239' |
10 | | - subject.account.should == 'Demon' |
11 | | - end |
12 | | - |
13 | | - it 'should default the region to na' do |
14 | | - subject.region.should == 'na' |
15 | | - end |
16 | | - |
17 | | - it 'should assign region if passed' do |
18 | | - BnetScraper::Starcraft2::ProfileScraper.any_instance.should_receive(:set_bnet_index) |
19 | | - scraper = BnetScraper::Starcraft2::ProfileScraper.new(bnet_id: '2377239', account: 'Demon', region: 'fea') |
20 | | - scraper.region.should == 'fea' |
21 | | - end |
22 | | - |
23 | | - it 'should not call set_bnet_index if bnet_index is passed' do |
24 | | - BnetScraper::Starcraft2::ProfileScraper.any_instance.should_not_receive(:set_bnet_index) |
25 | | - scraper = BnetScraper::Starcraft2::ProfileScraper.new(bnet_id: '2377239', account: 'Demon', region: 'fea', bnet_index: '1') |
26 | | - end |
27 | | - |
28 | | - it 'should call set_bnet_index_if bnet_index is not passed' do |
29 | | - BnetScraper::Starcraft2::ProfileScraper.any_instance.should_receive(:set_bnet_index) |
30 | | - scraper = BnetScraper::Starcraft2::ProfileScraper.new(bnet_id: '2377239', account: 'Demon', region: 'fea') |
31 | | - end |
32 | | - end |
33 | | - |
34 | | - context 'when url is passed' do |
35 | | - subject { BnetScraper::Starcraft2::ProfileScraper.new(url: 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/') } |
36 | | - it 'should extract the bnet_id from the url' do |
37 | | - subject.bnet_id.should == '2377239' |
38 | | - end |
39 | | - |
40 | | - it 'should extract the account from the url' do |
41 | | - subject.account.should == 'Demon' |
42 | | - end |
43 | | - |
44 | | - it 'should extract the region from the url' do |
45 | | - subject.region.should == 'na' |
46 | | - end |
47 | | - |
48 | | - it 'should extract the bnet_index from the url' do |
49 | | - subject.bnet_index.should == '1' |
50 | | - end |
51 | | - end |
52 | | - end |
53 | | - |
54 | | - describe '#region_info' do |
55 | | - it 'should return information based on the set region' do |
56 | | - subject.region_info.should == { domain: 'us.battle.net', dir: 'en' } |
57 | | - end |
58 | | - end |
59 | | - |
60 | | - describe '#set_bnet_index' do |
61 | | - it 'should return the valid integer needed for a proper URL parse from bnet' do |
62 | | - subject.set_bnet_index |
63 | | - subject.bnet_index.should == 1 |
64 | | - end |
65 | | - end |
66 | | - |
67 | | - describe '#profile_url' do |
68 | | - it 'should return a string URL for bnet' do |
69 | | - subject.profile_url.should == 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/' |
70 | | - end |
71 | | - |
72 | | - it 'should optionally take a bnet_index to use instead of saved bnet_index' do |
73 | | - subject.profile_url(2).should == 'http://us.battle.net/sc2/en/profile/2377239/2/Demon/' |
74 | | - end |
| 4 | + it_behaves_like 'an SC2 Scraper' do |
| 5 | + let(:scraper_class) { BnetScraper::Starcraft2::BaseScraper } |
| 6 | + let(:subject) { scraper_class.new(url: 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/') } |
75 | 7 | end |
76 | 8 |
|
| 9 | + subject { BnetScraper::Starcraft2::ProfileScraper.new(bnet_id: '2377239', account: 'Demon') } |
77 | 10 |
|
78 | 11 | describe '#get_profile_data' do |
79 | 12 | it 'should set the race, wins, and achievements attributes' do |
|
0 commit comments