From 3233f4a247558206acc917240592d4920741e085 Mon Sep 17 00:00:00 2001 From: Tristan Starck Date: Mon, 15 Jul 2024 16:46:14 -0700 Subject: [PATCH 1/5] pass current version to block as kwargs --- .gitignore | 2 + CHANGELOG.md | 4 + Gemfile.lock | 2 +- README.md | 12 +++ .../matrix/extensions/appraisal_file.rb | 12 ++- lib/appraisal/matrix/version.rb | 2 +- .../matrix/extensions/appraisal_file_spec.rb | 90 +++++++++++++++++-- 7 files changed, 116 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 2297067..8c44e5a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,9 +6,11 @@ /pkg/ /spec/reports/ /tmp/ +.idea/ # rspec failure tracking .rspec_status # appraisal gemfiles/*.lock +.rubocop-https* diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cb64c3..a2b897c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.3.0 - Unreleased +### Changed +- Changed the block passed to `appraisal_matrix` to be called with the versions of gems for the current matrix entry. + ## 0.2.0 - 2024-07-09 ### Added - Support special request options for `appraisal_matrix`: diff --git a/Gemfile.lock b/Gemfile.lock index 29c4817..ece43ac 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - appraisal-matrix (0.2.0) + appraisal-matrix (0.3.0) appraisal (~> 2.2) GEM diff --git a/README.md b/README.md index 8a4715e..c6c535f 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,18 @@ appraisal_matrix(activesupport: "6.1") do end ``` +#### Block arguments +If you would like to setup conditional logic based off of the versions of the gems in the matrix, you can pass a block with arguments to `appraisal_matrix`. + +```ruby +appraisal_matrix(activesupport: "6.1") do |activesupport:, sidekiq:| + # activesupport + if activesupport < "7" + remove_gem 'test_after_commit' + end +end +``` + ### Appraising more than one Gem You can also pass more than one gem to `appraisal_matrix` to create a matrix of all combinations of the specified gems. diff --git a/lib/appraisal/matrix/extensions/appraisal_file.rb b/lib/appraisal/matrix/extensions/appraisal_file.rb index f4f7127..25ca092 100644 --- a/lib/appraisal/matrix/extensions/appraisal_file.rb +++ b/lib/appraisal/matrix/extensions/appraisal_file.rb @@ -33,6 +33,13 @@ def versions # appraisal_matrix(rails: "6.0") do # gem "sqlite3", "~> 2.5" # end + # appraisal_matrix(rails: "6.0", sidekiq: "5.0") do |rails:, sidekiq:| + # if rails < "7" + # # do something... + # else + # # do something else... + # end + # end def appraisal_matrix(**kwargs, &block) # names_and_versions_to_test # [ @@ -76,7 +83,10 @@ def appraisal_matrix(**kwargs, &block) appraisal_spec.each do |gem_name, version| gem gem_name, "~> #{version}.0" end - instance_eval(&block) if block + if block + block_args = appraisal_spec.to_h { |gem_name, version| [gem_name.to_sym, Gem::Version.new(version)] } + instance_exec(**block_args, &block) + end end end end diff --git a/lib/appraisal/matrix/version.rb b/lib/appraisal/matrix/version.rb index 6b0e693..62405dc 100644 --- a/lib/appraisal/matrix/version.rb +++ b/lib/appraisal/matrix/version.rb @@ -2,6 +2,6 @@ module Appraisal module Matrix - VERSION = "0.2.0" + VERSION = "0.3.0" end end diff --git a/spec/appraisal/matrix/extensions/appraisal_file_spec.rb b/spec/appraisal/matrix/extensions/appraisal_file_spec.rb index 2e698ec..f4e565a 100644 --- a/spec/appraisal/matrix/extensions/appraisal_file_spec.rb +++ b/spec/appraisal/matrix/extensions/appraisal_file_spec.rb @@ -92,23 +92,57 @@ let(:desired_gems) { { rails: "6.1" } } it_behaves_like "a matrix of appraisals" + end + + context "with a block to pass into each appraisal" do + subject(:run_matrix) do + appraisal_matrix(**desired_gems) { gem "sqlite3", "~> 2.5" } + end + let(:desired_gems) { { rails: "6.1" } } + + it "yields the block to each appraisal" do + expect(self).to receive(:appraise).with("rails-6_1").and_yield do |block_scope| + expect(block_scope).to receive(:gem).with(:rails, "~> 6.1.0") + expect(block_scope).to receive(:gem).with("sqlite3", "~> 2.5") + end + expect(self).to receive(:appraise).with("rails-7_0").and_yield do |block_scope| + expect(block_scope).to receive(:gem).with(:rails, "~> 7.0.0") + expect(block_scope).to receive(:gem).with("sqlite3", "~> 2.5") + end + expect(self).to receive(:appraise).with("rails-7_1").and_yield do |block_scope| + expect(block_scope).to receive(:gem).with(:rails, "~> 7.1.0") + expect(block_scope).to receive(:gem).with("sqlite3", "~> 2.5") + end + + run_matrix + end - context "with a block to pass into each appraisal" do - it "yields the block to each appraisal" do + context "with a block with arguments" do + subject(:run_matrix) do + appraisal_matrix(**desired_gems) do |rails:| + if rails < "7" + gem "sqlite3", "< 2" + else + gem "sqlite3", "~> 2.5" + end + end + end + + it "yields the block with the versions to each appraisal" do expect(self).to receive(:appraise).with("rails-6_1").and_yield do |block_scope| expect(block_scope).to receive(:gem).with(:rails, "~> 6.1.0") - expect(block_scope).to receive(:gem).with("sqlite3", "~> 2.5") + expect(block_scope).to receive(:gem).with("sqlite3", "< 2") end expect(self).to receive(:appraise).with("rails-7_0").and_yield do |block_scope| expect(block_scope).to receive(:gem).with(:rails, "~> 7.0.0") expect(block_scope).to receive(:gem).with("sqlite3", "~> 2.5") end - expect(self).to receive(:appraise).with("rails-7_1").and_yield do |block_scope| + expect(self).to receive(:appraise).with("rails-7_1").and_yield do |block_scope, versions| expect(block_scope).to receive(:gem).with(:rails, "~> 7.1.0") expect(block_scope).to receive(:gem).with("sqlite3", "~> 2.5") end - appraisal_matrix(**desired_gems) { gem "sqlite3", "~> 2.5" } + run_matrix end end end @@ -168,6 +202,52 @@ end subject end + + context "with a block" do + subject(:run_matrix) do + appraisal_matrix(**desired_gems) do |rails:, sidekiq:| + if rails < "7" && sidekiq < "6" + gem "sqlite3", "< 2" + else + gem "sqlite3", "~> 2.5" + end + end + end + + it "yields the block with the versions to each appraisal" do + expect(self).to receive(:appraise).with("rails-6_1-sidekiq-5_0").and_yield do |block_scope| + expect(block_scope).to receive(:gem).with(:rails, "~> 6.1.0") + expect(block_scope).to receive(:gem).with(:sidekiq, "~> 5.0.0") + expect(block_scope).to receive(:gem).with("sqlite3", "< 2") + end + expect(self).to receive(:appraise).with("rails-6_1-sidekiq-6_0").and_yield do |block_scope| + expect(block_scope).to receive(:gem).with(:rails, "~> 6.1.0") + expect(block_scope).to receive(:gem).with(:sidekiq, "~> 6.0.0") + expect(block_scope).to receive(:gem).with("sqlite3", "~> 2.5") + end + expect(self).to receive(:appraise).with("rails-7_0-sidekiq-5_0").and_yield do |block_scope| + expect(block_scope).to receive(:gem).with(:rails, "~> 7.0.0") + expect(block_scope).to receive(:gem).with(:sidekiq, "~> 5.0.0") + expect(block_scope).to receive(:gem).with("sqlite3", "~> 2.5") + end + expect(self).to receive(:appraise).with("rails-7_0-sidekiq-6_0").and_yield do |block_scope| + expect(block_scope).to receive(:gem).with(:rails, "~> 7.0.0") + expect(block_scope).to receive(:gem).with(:sidekiq, "~> 6.0.0") + expect(block_scope).to receive(:gem).with("sqlite3", "~> 2.5") + end + expect(self).to receive(:appraise).with("rails-7_1-sidekiq-5_0").and_yield do |block_scope| + expect(block_scope).to receive(:gem).with(:rails, "~> 7.1.0") + expect(block_scope).to receive(:gem).with(:sidekiq, "~> 5.0.0") + expect(block_scope).to receive(:gem).with("sqlite3", "~> 2.5") + end + expect(self).to receive(:appraise).with("rails-7_1-sidekiq-6_0").and_yield do |block_scope| + expect(block_scope).to receive(:gem).with(:rails, "~> 7.1.0") + expect(block_scope).to receive(:gem).with(:sidekiq, "~> 6.0.0") + expect(block_scope).to receive(:gem).with("sqlite3", "~> 2.5") + end + run_matrix + end + end end end end From 11f6ecfbb70af1b44f6fb73fef4b7821d119defd Mon Sep 17 00:00:00 2001 From: Tristan Starck Date: Mon, 15 Jul 2024 16:49:27 -0700 Subject: [PATCH 2/5] fix issues with appraisal file spec --- .ruby-version | 2 +- spec/appraisal/matrix/extensions/appraisal_file_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.ruby-version b/.ruby-version index 9cec716..818bd47 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.6 +3.0.6 diff --git a/spec/appraisal/matrix/extensions/appraisal_file_spec.rb b/spec/appraisal/matrix/extensions/appraisal_file_spec.rb index f4e565a..1888252 100644 --- a/spec/appraisal/matrix/extensions/appraisal_file_spec.rb +++ b/spec/appraisal/matrix/extensions/appraisal_file_spec.rb @@ -120,7 +120,7 @@ context "with a block with arguments" do subject(:run_matrix) do appraisal_matrix(**desired_gems) do |rails:| - if rails < "7" + if rails < Gem::Version.new("7") gem "sqlite3", "< 2" else gem "sqlite3", "~> 2.5" @@ -206,7 +206,7 @@ context "with a block" do subject(:run_matrix) do appraisal_matrix(**desired_gems) do |rails:, sidekiq:| - if rails < "7" && sidekiq < "6" + if rails < Gem::Version.new("7") && sidekiq < Gem::Version.new("6") gem "sqlite3", "< 2" else gem "sqlite3", "~> 2.5" From 478b72ffb911287b22ced2168316e86e16e163ef Mon Sep 17 00:00:00 2001 From: Tristan Starck Date: Mon, 15 Jul 2024 16:56:53 -0700 Subject: [PATCH 3/5] set pre-release version --- Gemfile.lock | 2 +- lib/appraisal/matrix/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ece43ac..948fa61 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - appraisal-matrix (0.3.0) + appraisal-matrix (0.3.0.pre.tstarck.1) appraisal (~> 2.2) GEM diff --git a/lib/appraisal/matrix/version.rb b/lib/appraisal/matrix/version.rb index 62405dc..1ec933a 100644 --- a/lib/appraisal/matrix/version.rb +++ b/lib/appraisal/matrix/version.rb @@ -2,6 +2,6 @@ module Appraisal module Matrix - VERSION = "0.3.0" + VERSION = "0.3.0.pre.tstarck.1" end end From cb77116ab32c752e8677ebc4dd59717eabb0c338 Mon Sep 17 00:00:00 2001 From: Tristan Starck Date: Mon, 15 Jul 2024 17:04:32 -0700 Subject: [PATCH 4/5] Update README.md Co-authored-by: Drew Caddell --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6c535f..25e0457 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ end If you would like to setup conditional logic based off of the versions of the gems in the matrix, you can pass a block with arguments to `appraisal_matrix`. ```ruby -appraisal_matrix(activesupport: "6.1") do |activesupport:, sidekiq:| +appraisal_matrix(activesupport: "6.1") do |activesupport:| # activesupport if activesupport < "7" remove_gem 'test_after_commit' From 73162282e19ffc9d415e1e0b4340c37b2f193c08 Mon Sep 17 00:00:00 2001 From: Tristan Starck Date: Tue, 16 Jul 2024 08:41:50 -0700 Subject: [PATCH 5/5] prepare for full release --- CHANGELOG.md | 2 +- Gemfile.lock | 2 +- lib/appraisal/matrix/version.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2b897c..b0b30c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## 0.3.0 - Unreleased +## 0.3.0 - 2024-07-16 ### Changed - Changed the block passed to `appraisal_matrix` to be called with the versions of gems for the current matrix entry. diff --git a/Gemfile.lock b/Gemfile.lock index 948fa61..ece43ac 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - appraisal-matrix (0.3.0.pre.tstarck.1) + appraisal-matrix (0.3.0) appraisal (~> 2.2) GEM diff --git a/lib/appraisal/matrix/version.rb b/lib/appraisal/matrix/version.rb index 1ec933a..62405dc 100644 --- a/lib/appraisal/matrix/version.rb +++ b/lib/appraisal/matrix/version.rb @@ -2,6 +2,6 @@ module Appraisal module Matrix - VERSION = "0.3.0.pre.tstarck.1" + VERSION = "0.3.0" end end