Skip to content

Commit

Permalink
Make VCR CI compatible with Faraday 1 and 2
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehjr committed Jul 21, 2024
1 parent c3734f2 commit defc082
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
strategy:
matrix:
ruby-version: ["3.2", "3.1", "3.0", "2.7"]
faraday: ["1.0", "2.0"]
env:
FARADAY_VERSION: ${{ matrix.faraday }}
steps:
- uses: actions/checkout@v4
- run: ./script/install-apt-deps.sh
Expand Down
11 changes: 10 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ gem "cucumber", "~> 9.0"
gem "curb", "~> 1.0.1"
gem "em-http-request"
gem "excon", ">= 0.62.0"
gem "faraday", "~> 1.0"

if ENV['FARADAY_VERSION'] == '1.0'
gem "faraday", "~> 1.0"
else
gem "faraday", "~> 2.0"
gem "faraday-typhoeus"
gem "faraday-patron", '~> 2.0'
gem 'faraday-multipart'
end

gem "hashdiff", ">= 1.0.0.beta1", "< 2.0.0"
gem "httpclient"
gem "json"
Expand Down
1 change: 1 addition & 0 deletions lib/vcr/middleware/faraday.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'faraday'
require 'faraday/multipart'
require 'vcr/util/version_checker'
require 'vcr/request_handler'

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/vcr/middleware/faraday_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

def self.test_recording
it 'records the request body correctly' do
payload = { :file => Faraday::UploadIO.new(__FILE__, 'text/plain') }
payload = { :file => Faraday::FilePart.new(__FILE__, 'text/plain') }

expect(VCR).to receive(:record_http_interaction) do |i|
expect(i.request.headers['Content-Type'].first).to include("multipart")
Expand Down
6 changes: 5 additions & 1 deletion spec/support/http_library_adapters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,12 @@ def normalize_request_headers(headers)
end
end

require 'faraday'

%w[ net_http typhoeus patron ].each do |_faraday_adapter|
if _faraday_adapter == 'typhoeus' &&
if Faraday::VERSION > '2.0'
require "faraday/#{_faraday_adapter}"
elsif _faraday_adapter == 'typhoeus' &&
defined?(::Typhoeus::VERSION) &&
::Typhoeus::VERSION.to_f >= 0.5
require 'typhoeus/adapters/faraday'
Expand Down

0 comments on commit defc082

Please sign in to comment.