Skip to content

Commit

Permalink
Merge pull request #5 from Invoca/NON_PRODUCTION-add_yield_block_to_a…
Browse files Browse the repository at this point in the history
…ppraisal_matrix

NON-PRODUCTION pass current version to block as kwargs
  • Loading branch information
ttstarck authored Jul 16, 2024
2 parents 8a84c20 + 7316228 commit 605489c
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
/pkg/
/spec/reports/
/tmp/
.idea/

# rspec failure tracking
.rspec_status

# appraisal
gemfiles/*.lock
.rubocop-https*
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.6
3.0.6
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 - 2024-07-16
### 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`:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
appraisal-matrix (0.2.0)
appraisal-matrix (0.3.0)
appraisal (~> 2.2)

GEM
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:|
# activesupport <Gem::Version>
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.
Expand Down
12 changes: 11 additions & 1 deletion lib/appraisal/matrix/extensions/appraisal_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
# [
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/appraisal/matrix/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Appraisal
module Matrix
VERSION = "0.2.0"
VERSION = "0.3.0"
end
end
90 changes: 85 additions & 5 deletions spec/appraisal/matrix/extensions/appraisal_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 < Gem::Version.new("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
Expand Down Expand Up @@ -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 < Gem::Version.new("7") && sidekiq < Gem::Version.new("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

0 comments on commit 605489c

Please sign in to comment.