-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_service_spec.rb
52 lines (37 loc) · 2.01 KB
/
parser_service_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true
require 'rails_helper'
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
result = Google::ClientService.new(keyword: 'squarespace').call
expect(described_class.new(html_response: result).call[:ads_top_count]).to eq(1)
end
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
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
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
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
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
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
# Counted from cassette html raw code
result = Google::ClientService.new(keyword: 'vpn').call
expect(described_class.new(html_response: result).call[:total_link_count]).to eq(113)
end
end
end