From eb09e27a4f58480f05e1c17afc9d1e1499dfb88a Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Mon, 28 Jun 2021 09:26:03 +0700 Subject: [PATCH] [#7] Rename vcr to simpler google_search/xx name --- .../{google_search.yml => google_search/base.yml} | 0 .../too_many_requests.yml} | 0 .../top_ads_1.yml} | 0 .../top_ads_6.yml} | 0 spec/services/google/client_service_spec.rb | 8 ++++---- spec/services/google/parser_service_spec.rb | 14 +++++++------- 6 files changed, 11 insertions(+), 11 deletions(-) rename spec/fixtures/vcr/{google_search.yml => google_search/base.yml} (100%) rename spec/fixtures/vcr/{google_warn.yml => google_search/too_many_requests.yml} (100%) rename spec/fixtures/vcr/{google_search_top_ads_1.yml => google_search/top_ads_1.yml} (100%) rename spec/fixtures/vcr/{google_search_top_ads_6.yml => google_search/top_ads_6.yml} (100%) diff --git a/spec/fixtures/vcr/google_search.yml b/spec/fixtures/vcr/google_search/base.yml similarity index 100% rename from spec/fixtures/vcr/google_search.yml rename to spec/fixtures/vcr/google_search/base.yml diff --git a/spec/fixtures/vcr/google_warn.yml b/spec/fixtures/vcr/google_search/too_many_requests.yml similarity index 100% rename from spec/fixtures/vcr/google_warn.yml rename to spec/fixtures/vcr/google_search/too_many_requests.yml diff --git a/spec/fixtures/vcr/google_search_top_ads_1.yml b/spec/fixtures/vcr/google_search/top_ads_1.yml similarity index 100% rename from spec/fixtures/vcr/google_search_top_ads_1.yml rename to spec/fixtures/vcr/google_search/top_ads_1.yml diff --git a/spec/fixtures/vcr/google_search_top_ads_6.yml b/spec/fixtures/vcr/google_search/top_ads_6.yml similarity index 100% rename from spec/fixtures/vcr/google_search_top_ads_6.yml rename to spec/fixtures/vcr/google_search/top_ads_6.yml diff --git a/spec/services/google/client_service_spec.rb b/spec/services/google/client_service_spec.rb index 82458b01..bb1c8491 100644 --- a/spec/services/google/client_service_spec.rb +++ b/spec/services/google/client_service_spec.rb @@ -4,13 +4,13 @@ RSpec.describe Google::ClientService, type: :service do context 'when querying a simple keyword' do - it 'returns an HTTParty Response', vcr: 'google_search' do + it 'returns an HTTParty Response', vcr: 'google_search/base' do result = described_class.new(keyword: FFaker::Lorem.word).call expect(result).to be_an_instance_of(HTTParty::Response) end - it 'queries Google Search', vcr: 'google_search' do + it 'queries Google Search', vcr: 'google_search/base' do path = described_class.new(keyword: FFaker::Lorem.word).call.request.path expect(path.to_s).to start_with(described_class::BASE_SEARCH_URL) @@ -18,13 +18,13 @@ end context 'when google returns an HTTP error' do - it 'returns false', vcr: 'google_warn' do + it 'returns false', vcr: 'google_search/too_many_requests' do result = described_class.new(keyword: FFaker::Lorem.word).call expect(result).to eq(false) end - it 'logs a warning with the escaped keyword', vcr: 'google_warn' do + it 'logs a warning with the escaped keyword', vcr: 'google_search/too_many_requests' do allow(Rails.logger).to receive(:warn) word = FFaker::Lorem.word diff --git a/spec/services/google/parser_service_spec.rb b/spec/services/google/parser_service_spec.rb index 79a33e6b..ed9b6894 100644 --- a/spec/services/google/parser_service_spec.rb +++ b/spec/services/google/parser_service_spec.rb @@ -4,7 +4,7 @@ RSpec.describe Google::ParserService, type: :service do context 'when parsing a page having 1 top ad' do - it 'counts exactly 1 top ad', vcr: 'google_search_top_ads_1' do + it 'counts exactly 1 top ad', vcr: 'google_search/top_ads_1' do result = Google::ClientService.new(keyword: 'squarespace').call expect(described_class.new(html_response: result).call[:ads_top_count]).to eq(1) @@ -12,37 +12,37 @@ end context 'when parsing a page having 3 top ads, 3 bottom ads and 14 non ad links' do - it 'counts exactly 3 top ads', vcr: 'google_search_top_ads_6' do + it 'counts exactly 3 top ads', vcr: 'google_search/top_ads_6' do result = Google::ClientService.new(keyword: 'vpn').call expect(described_class.new(html_response: result).call[:ads_top_count]).to eq(3) end - it 'counts exactly 6 ads in total', vcr: 'google_search_top_ads_6' do + it 'counts exactly 6 ads in total', vcr: 'google_search/top_ads_6' do result = Google::ClientService.new(keyword: 'vpn').call expect(described_class.new(html_response: result).call[:ads_page_count]).to eq(6) end - it 'finds exactly the 3 top ads urls', vcr: 'google_search_top_ads_6' do + it 'finds exactly the 3 top ads urls', vcr: 'google_search/top_ads_6' do result = Google::ClientService.new(keyword: 'vpn').call expect(described_class.new(html_response: result).call[: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 ad results', vcr: 'google_search_top_ads_6' do + it 'counts exactly 14 non ad results', vcr: 'google_search/top_ads_6' do result = Google::ClientService.new(keyword: 'vpn').call expect(described_class.new(html_response: result).call[:non_ads_result_count]).to eq(14) end - it 'gets 14 results', vcr: 'google_search_top_ads_6' do + it 'gets 14 results', vcr: 'google_search/top_ads_6' do result = Google::ClientService.new(keyword: 'vpn').call expect(described_class.new(html_response: result).call[:non_ads_url].count).to eq(14) end - it 'gets exactly 113 links', vcr: 'google_search_top_ads_6' do + it 'gets exactly 113 links', vcr: 'google_search/top_ads_6' do # Counted from cassette html raw code result = Google::ClientService.new(keyword: 'vpn').call