Skip to content

Commit 707738e

Browse files
authored
Make VCR CI compatible with Faraday 1 and 2 (#1024)
1 parent 95a9192 commit 707738e

File tree

7 files changed

+47
-14
lines changed

7 files changed

+47
-14
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ on:
88

99
jobs:
1010
cucumber:
11-
name: "Cucumber / ${{ matrix.ruby-version }}"
11+
name: "Cucumber / Ruby ${{ matrix.ruby-version }} / Faraday ${{ matrix.faraday }}"
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
1515
ruby-version: ["3.2", "3.1", "3.0", "2.7"]
16+
faraday: ["1.0", "2.0"]
17+
env:
18+
FARADAY_VERSION: ${{ matrix.faraday }}
1619
steps:
1720
- uses: actions/checkout@v4
1821
- run: ./script/install-apt-deps.sh
@@ -23,11 +26,14 @@ jobs:
2326
- name: cucumber
2427
run: ./script/fail_if_warnings cucumber features/
2528
rspec:
26-
name: "RSpec / ${{ matrix.ruby-version }}"
29+
name: "RSpec / Ruby ${{ matrix.ruby-version }} / Faraday ${{ matrix.faraday }}"
2730
runs-on: ubuntu-latest
2831
strategy:
2932
matrix:
3033
ruby-version: ["3.2", "3.1", "3.0", "2.7"]
34+
faraday: ["1.0", "2.0"]
35+
env:
36+
FARADAY_VERSION: ${{ matrix.faraday }}
3137
steps:
3238
- uses: actions/checkout@v4
3339
- run: ./script/install-apt-deps.sh

Gemfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ gem "cucumber", "~> 9.0"
1212
gem "curb", "~> 1.0.1"
1313
gem "em-http-request"
1414
gem "excon", ">= 0.62.0"
15-
gem "faraday", "~> 1.0"
15+
16+
if ENV['FARADAY_VERSION'] == '1.0'
17+
gem "faraday", "~> 1.0"
18+
else
19+
gem "faraday", "~> 2.0"
20+
gem "faraday-typhoeus"
21+
gem "faraday-patron", '~> 2.0'
22+
gem 'faraday-multipart'
23+
end
24+
1625
gem "hashdiff", ">= 1.0.0.beta1", "< 2.0.0"
1726
gem "httpclient"
1827
gem "json"

features/configuration/hook_into.feature

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,14 @@ Feature: hook_into
8888
require 'excon'
8989
require 'faraday'
9090
require 'vcr'
91-
<extra_require>
91+
92+
if '<faraday_adapter>' == 'typhoeus'
93+
if Faraday::VERSION > '2.0'
94+
require "faraday/typhoeus"
95+
else
96+
require 'typhoeus/adapters/faraday'
97+
end
98+
end
9299
93100
VCR.configure { |c| c.ignore_localhost = true }
94101
@@ -160,6 +167,6 @@ Feature: hook_into
160167
| Faraday 2: Hello faraday |
161168

162169
Examples:
163-
| hook_into | faraday_adapter | extra_require |
164-
| :webmock | net_http | |
165-
| :webmock | typhoeus | require 'typhoeus/adapters/faraday' |
170+
| hook_into | faraday_adapter |
171+
| :webmock | net_http |
172+
| :webmock | typhoeus |

features/middleware/faraday.feature

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ Feature: Faraday middleware
2121
2222
require 'faraday'
2323
require 'vcr'
24-
<extra_require>
24+
25+
if '<adapter>' == 'typhoeus'
26+
if Faraday::VERSION > '2.0'
27+
require "faraday/typhoeus"
28+
else
29+
require 'typhoeus/adapters/faraday'
30+
end
31+
end
2532
2633
VCR.configure do |c|
2734
c.default_cassette_options = { :serialize_with => :syck }
@@ -50,7 +57,6 @@ Feature: Faraday middleware
5057
And the file "cassettes/example.yml" should contain "Hello foo 1"
5158

5259
Examples:
53-
| adapter | extra_require |
54-
| net_http | |
55-
| typhoeus | require 'typhoeus/adapters/faraday' |
56-
60+
| adapter |
61+
| net_http |
62+
| typhoeus |

lib/vcr/middleware/faraday.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'faraday'
2+
require 'faraday/multipart'
23
require 'vcr/util/version_checker'
34
require 'vcr/request_handler'
45

spec/lib/vcr/middleware/faraday_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

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

2626
expect(VCR).to receive(:record_http_interaction) do |i|
2727
expect(i.request.headers['Content-Type'].first).to include("multipart")

spec/support/http_library_adapters.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,12 @@ def normalize_request_headers(headers)
209209
end
210210
end
211211

212+
require 'faraday'
213+
212214
%w[ net_http typhoeus patron ].each do |_faraday_adapter|
213-
if _faraday_adapter == 'typhoeus' &&
215+
if Faraday::VERSION > '2.0'
216+
require "faraday/#{_faraday_adapter}"
217+
elsif _faraday_adapter == 'typhoeus' &&
214218
defined?(::Typhoeus::VERSION) &&
215219
::Typhoeus::VERSION.to_f >= 0.5
216220
require 'typhoeus/adapters/faraday'

0 commit comments

Comments
 (0)