Skip to content

Commit

Permalink
[#7] Refactor tests with inline vcr
Browse files Browse the repository at this point in the history
  • Loading branch information
malparty committed Jun 30, 2021
1 parent 9be2612 commit 84d4330
Showing 1 changed file with 15 additions and 35 deletions.
50 changes: 15 additions & 35 deletions spec/services/google_service/parser_service_spec.rb
Expand Up @@ -4,67 +4,47 @@

RSpec.describe GoogleService::ParserService, type: :service do
context 'when parsing a page having 1 top ads' do
it 'counts exactly 1 top ads' do
result = nil
VCR.use_cassette('google_search_top_ads_1') do
result = GoogleService::ClientService.query('squarespace')
end
it 'counts exactly 1 top ads', vcr: 'google_search_top_ads_1' do
result = GoogleService::ClientService.new('squarespace').query_result

expect(described_class.new(result).ads_top_count).to eq(1)
end
end

context 'when parsing a page having 3 top ads, 3 bottom ads and 14 non ads links' do
it 'counts exactly 3 top ads' do
result = nil
VCR.use_cassette('google_search_top_ads_6') do
result = GoogleService::ClientService.query('vpn')
end
it 'counts exactly 3 top ads', vcr: 'google_search_top_ads_6' do
result = GoogleService::ClientService.new('vpn').query_result

expect(described_class.new(result).ads_top_count).to eq(3)
end

it 'counts exactly 6 ads in total' do
result = nil
VCR.use_cassette('google_search_top_ads_6') do
result = GoogleService::ClientService.query('vpn')
end
it 'counts exactly 6 ads in total', vcr: 'google_search_top_ads_6' do
result = GoogleService::ClientService.new('vpn').query_result

expect(described_class.new(result).ads_page_count).to eq(6)
end

it 'finds exactly the 3 top ads urls' do
result = nil
VCR.use_cassette('google_search_top_ads_6') do
result = GoogleService::ClientService.query('vpn')
end
it 'finds exactly the 3 top ads urls', vcr: 'google_search_top_ads_6' do
result = GoogleService::ClientService.new('vpn').query_result

expect(described_class.new(result).ads_top_url).to contain_exactly('https://cloud.google.com/free', 'https://www.expressvpn.com/', 'https://www.top10vpn.com/best-vpn-for-vietnam/')
end

it 'counts exactly 14 non ads results' do
result = nil
VCR.use_cassette('google_search_top_ads_6') do
result = GoogleService::ClientService.query('vpn')
end
it 'counts exactly 14 non ads results', vcr: 'google_search_top_ads_6' do
result = GoogleService::ClientService.new('vpn').query_result

expect(described_class.new(result).non_ads_result_count).to eq(14)
end

it 'gets 14 results' do
result = nil
VCR.use_cassette('google_search_top_ads_6') do
result = GoogleService::ClientService.query('vpn')
end
it 'gets 14 results', vcr: 'google_search_top_ads_6' do
result = GoogleService::ClientService.new('vpn').query_result

expect(described_class.new(result).non_ads_url.count).to eq(14)
end

it 'gets exactly 113 links' do # Counted from cassette html raw code
result = nil
VCR.use_cassette('google_search_top_ads_6') do
result = GoogleService::ClientService.query('vpn')
end
it 'gets exactly 113 links', vcr: 'google_search_top_ads_6' do
# Counted from cassette html raw code
result = GoogleService::ClientService.new('vpn').query_result

expect(described_class.new(result).total_link_count).to eq(113)
end
Expand Down

0 comments on commit 84d4330

Please sign in to comment.