Skip to content

Commit

Permalink
[#6] Add tests using VCR to replay a google search query
Browse files Browse the repository at this point in the history
  • Loading branch information
malparty committed Jun 14, 2021
1 parent 21d617b commit 5027fb4
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 1 deletion.
112 changes: 112 additions & 0 deletions spec/fixtures/vcr/google_search.yml

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions spec/services/google_service/client_service_spec.rb
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe GoogleService::ClientService, type: :service do
context 'when querying a simple keyword' do
it 'returns an HTTParty Response' do
result = nil
VCR.use_cassette('google_search') do
result = described_class.query(FFaker::Lorem.word)
end

expect(result).to be_an_instance_of(HTTParty::Response)
end

it 'queries Google Search' do
path = nil
VCR.use_cassette('google_search') do
path = described_class.query(FFaker::Lorem.word).request.path
end

expect(path.to_s).to start_with('https://www.google.com/search')
end
end
end
2 changes: 1 addition & 1 deletion spec/support/vcr.rb
Expand Up @@ -14,7 +14,7 @@
end

RSpec.configure do |config|
# You can pass a hash to the `vcr` tag to specifcy additional options:
# You can pass a hash to the `vcr` tag to specify additional options:
# vcr: { group: 'places/google/details', cassettes: %w(kfc red_planet)}
# vcr: { group: 'places/google/details', cassette: 'kfc'}
# vcr: { cassette: 'places/google/details', options: { decode_compressed_response: true } }
Expand Down

0 comments on commit 5027fb4

Please sign in to comment.