|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe BnetScraper::Starcraft2::AchievementScraper do |
| 4 | + describe '#initialize' do |
| 5 | + context 'with url parameter passed' do |
| 6 | + subject { BnetScraper::Starcraft2::AchievementScraper.new(url: 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/achievements/') } |
| 7 | + |
| 8 | + it 'should extract bnet_id from the URL' do |
| 9 | + subject.bnet_id.should == '2377239' |
| 10 | + end |
| 11 | + |
| 12 | + it 'should extract account from the URL' do |
| 13 | + subject.account.should == 'Demon' |
| 14 | + end |
| 15 | + |
| 16 | + it 'should extract the bnet_index from the URL' do |
| 17 | + subject.bnet_index.should == '1' |
| 18 | + end |
| 19 | + |
| 20 | + it 'should extract the region from the URL' do |
| 21 | + subject.region.should == 'na' |
| 22 | + end |
| 23 | + end |
| 24 | + |
| 25 | + context 'when bnet_id and account parameters are passed' do |
| 26 | + subject { BnetScraper::Starcraft2::AchievementScraper.new(bnet_id: '2377239', account: 'Demon') } |
| 27 | + it 'should set the bnet_id and account parameters' do |
| 28 | + subject.bnet_id.should == '2377239' |
| 29 | + subject.account.should == 'Demon' |
| 30 | + end |
| 31 | + |
| 32 | + it 'should default the region to na' do |
| 33 | + subject.region.should == 'na' |
| 34 | + end |
| 35 | + |
| 36 | + it 'should assign region if passed' do |
| 37 | + BnetScraper::Starcraft2::AchievementScraper.any_instance.should_receive(:set_bnet_index) |
| 38 | + scraper = BnetScraper::Starcraft2::AchievementScraper.new(bnet_id: '2377239', account: 'Demon', region: 'fea') |
| 39 | + scraper.region.should == 'fea' |
| 40 | + end |
| 41 | + |
| 42 | + it 'should not call set_bnet_index if bnet_index is passed' do |
| 43 | + BnetScraper::Starcraft2::AchievementScraper.any_instance.should_not_receive(:set_bnet_index) |
| 44 | + scraper = BnetScraper::Starcraft2::AchievementScraper.new(bnet_id: '2377239', account: 'Demon', region: 'fea', bnet_index: '1') |
| 45 | + end |
| 46 | + |
| 47 | + it 'should call set_bnet_index_if bnet_index is not passed' do |
| 48 | + BnetScraper::Starcraft2::AchievementScraper.any_instance.should_receive(:set_bnet_index) |
| 49 | + scraper = BnetScraper::Starcraft2::AchievementScraper.new(bnet_id: '2377239', account: 'Demon', region: 'fea') |
| 50 | + end |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + describe '#scrape' do |
| 55 | + subject { BnetScraper::Starcraft2::AchievementScraper.new(url: 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/achievements/') } |
| 56 | + before :each do |
| 57 | + subject.scrape |
| 58 | + end |
| 59 | + |
| 60 | + it 'should set the showcase' do |
| 61 | + subject.showcase.should have(5).achievements |
| 62 | + end |
| 63 | + |
| 64 | + it 'should set the recently earned' do |
| 65 | + subject.recent.should have(6).achievements |
| 66 | + end |
| 67 | + |
| 68 | + it 'should set the liberty campaign progress' do |
| 69 | + subject.progress[:liberty_campaign].should == '1580' |
| 70 | + end |
| 71 | + |
| 72 | + it 'should set the exploration progress' do |
| 73 | + subject.progress[:exploration].should == '480' |
| 74 | + end |
| 75 | + |
| 76 | + it 'should set the custom game progress' do |
| 77 | + subject.progress[:custom_game].should == '330' |
| 78 | + end |
| 79 | + |
| 80 | + it 'should set the cooperative progress' do |
| 81 | + subject.progress[:cooperative].should == '660' |
| 82 | + end |
| 83 | + |
| 84 | + it 'should set the quick match progress' do |
| 85 | + subject.progress[:quick_match].should == '170' |
| 86 | + end |
| 87 | + end |
| 88 | +end |
0 commit comments