From 532a9c05f3c7c5c5e760ef712ce78a8d1d686891 Mon Sep 17 00:00:00 2001 From: Shojiro Yanagisawa Date: Sun, 15 Oct 2023 14:41:26 +0900 Subject: [PATCH] Support Faraday v1 and v2 --- .github/workflows/rspec.yml | 11 ++++++++++- CHANGELOG.md | 2 ++ Gemfile | 8 ++++++++ lib/qiita.rb | 2 +- qiita.gemspec | 5 ++--- spec/qiita/client_spec.rb | 8 ++++++++ 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index b072daa..bd31580 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -6,13 +6,22 @@ on: jobs: rspec: + name: Faraday ${{ matrix.faraday }} runs-on: ubuntu-latest + strategy: + matrix: + faraday: + - ~> 0.17 + - ~> 1.0 + - ~> 2.0 + env: + FARADAY_VERSION: ${{ matrix.faraday }} steps: - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: ruby-version: '3.0.0' bundler-cache: true - - run: gem install bundler -v '< 2.0' + - run: gem install bundler - run: bundle install - run: bundle exec rake spec diff --git a/CHANGELOG.md b/CHANGELOG.md index d2c42af..0f02744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Unreleased +- Support Faraday v1 and v2 + ## v1.4.0 - Migrate CI/CD platform from Travis CI to GitHub Actions diff --git a/Gemfile b/Gemfile index c4081c2..28c9956 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,12 @@ source 'https://rubygems.org' +# Support Faraday 0.x, 1.x and 2.x +faraday_version = ENV.fetch('FARADAY_VERSION', '~> 2.0') +gem 'faraday', faraday_version + +if faraday_version.start_with?(/~> (0|1)/) + gem 'faraday_middleware' +end + # Specify your gem's dependencies in qiita.gemspec gemspec diff --git a/lib/qiita.rb b/lib/qiita.rb index 8688311..4441d90 100644 --- a/lib/qiita.rb +++ b/lib/qiita.rb @@ -2,7 +2,7 @@ require "active_support/core_ext/string/inflections" require "active_support/core_ext/string/strip" require "faraday" -require "faraday_middleware" +require "faraday_middleware" if Faraday::VERSION.start_with?(/0|1/) require "json" require "rack/utils" require "rainbow" diff --git a/qiita.gemspec b/qiita.gemspec index a1845e0..08702a1 100644 --- a/qiita.gemspec +++ b/qiita.gemspec @@ -16,8 +16,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_dependency "activesupport" - spec.add_dependency "faraday", "~> 0.9" - spec.add_dependency "faraday_middleware" + spec.add_dependency "faraday", ">= 0.17", "< 3.0" spec.add_dependency "rack" spec.add_dependency "rainbow" spec.add_dependency "rouge" @@ -27,5 +26,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "pry" spec.add_development_dependency "rake" spec.add_development_dependency "rspec" - spec.add_development_dependency "webmock", "1.20.4" + spec.add_development_dependency "webmock", "~> 3" end diff --git a/spec/qiita/client_spec.rb b/spec/qiita/client_spec.rb index 2f94279..0e01792 100644 --- a/spec/qiita/client_spec.rb +++ b/spec/qiita/client_spec.rb @@ -341,6 +341,10 @@ def stub_api_request 204 end + let(:response_hash) do + nil + end + include_examples "valid condition" include_examples "sends request with JSON-encoded body" end @@ -362,6 +366,10 @@ def stub_api_request 204 end + let(:response_hash) do + nil + end + include_examples "valid condition" include_examples "sends request with URL query" end