Skip to content

Commit

Permalink
Make VCR CI compatible with Faraday 1 and 2 (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehjr committed Jul 21, 2024
1 parent 95a9192 commit 707738e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 14 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ on:

jobs:
cucumber:
name: "Cucumber / ${{ matrix.ruby-version }}"
name: "Cucumber / Ruby ${{ matrix.ruby-version }} / Faraday ${{ matrix.faraday }}"
runs-on: ubuntu-latest
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 All @@ -23,11 +26,14 @@ jobs:
- name: cucumber
run: ./script/fail_if_warnings cucumber features/
rspec:
name: "RSpec / ${{ matrix.ruby-version }}"
name: "RSpec / Ruby ${{ matrix.ruby-version }} / Faraday ${{ matrix.faraday }}"
runs-on: ubuntu-latest
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
15 changes: 11 additions & 4 deletions features/configuration/hook_into.feature
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ Feature: hook_into
require 'excon'
require 'faraday'
require 'vcr'
<extra_require>
if '<faraday_adapter>' == 'typhoeus'
if Faraday::VERSION > '2.0'
require "faraday/typhoeus"
else
require 'typhoeus/adapters/faraday'
end
end
VCR.configure { |c| c.ignore_localhost = true }
Expand Down Expand Up @@ -160,6 +167,6 @@ Feature: hook_into
| Faraday 2: Hello faraday |

Examples:
| hook_into | faraday_adapter | extra_require |
| :webmock | net_http | |
| :webmock | typhoeus | require 'typhoeus/adapters/faraday' |
| hook_into | faraday_adapter |
| :webmock | net_http |
| :webmock | typhoeus |
16 changes: 11 additions & 5 deletions features/middleware/faraday.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ Feature: Faraday middleware
require 'faraday'
require 'vcr'
<extra_require>
if '<adapter>' == 'typhoeus'
if Faraday::VERSION > '2.0'
require "faraday/typhoeus"
else
require 'typhoeus/adapters/faraday'
end
end
VCR.configure do |c|
c.default_cassette_options = { :serialize_with => :syck }
Expand Down Expand Up @@ -50,7 +57,6 @@ Feature: Faraday middleware
And the file "cassettes/example.yml" should contain "Hello foo 1"

Examples:
| adapter | extra_require |
| net_http | |
| typhoeus | require 'typhoeus/adapters/faraday' |

| adapter |
| net_http |
| typhoeus |
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 707738e

Please sign in to comment.