Skip to content

use VCR for spec that is calling remote server #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions async-http-faraday.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler"
spec.add_development_dependency "rspec", "~> 3.6"
spec.add_development_dependency "rake"
spec.add_development_dependency "vcr"
end
12 changes: 8 additions & 4 deletions spec/async/http/faraday/adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

require 'async'

require 'vcr_helper'

RSpec.describe Async::HTTP::Faraday::Adapter do
include_context Async::RSpec::Reactor

Expand Down Expand Up @@ -66,11 +68,13 @@ def get_response(url, path)
end
end

it "can get remote resource" do
it 'can get remote resource' do
Async do
response = get_response('http://www.google.com', '/search?q=cats')

expect(response).to be_success
VCR.use_cassette('remote') do
response = get_response('http://www.google.com', '/search?q=cats')

expect(response).to be_success
end
end
end

Expand Down
46 changes: 46 additions & 0 deletions spec/cassettes/remote.yml

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions spec/vcr_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'vcr'

VCR.configure do |config|
config.cassette_library_dir = 'spec/cassettes'
config.hook_into :faraday
config.ignore_localhost = true
end

# support Faraday::Adapter#close until PR https://github.com/vcr/vcr/pull/793 is merged
class VCR::Middleware::Faraday
def close
@app.close
end
end