-
Notifications
You must be signed in to change notification settings - Fork 23
Use bundle-locked gem versions in child contexts #819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7de4f8e
cb18f36
4d09d43
6527bef
3ff18da
7120179
e6f5729
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| PATH | ||
| remote: . | ||
| specs: | ||
| spoom (1.7.9) | ||
| spoom (1.7.10) | ||
| erubi (>= 1.10.0) | ||
| prism (>= 0.28.0) | ||
| rbi (>= 0.3.3) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # typed: strict | ||
| # frozen_string_literal: true | ||
|
|
||
| module Spoom | ||
| module BundlerHelper | ||
| extend T::Sig | ||
|
|
||
| class << self | ||
| # Generate a gem requirement for the given gem name, using that gem's version in the "real" current bundle. | ||
| # | ||
| # This ensures that any child Spoom::Contexts use predictable gem versions, | ||
| # without having to manually specify them and bump them to stay in sync with Spoom's real Gemfile. | ||
| # | ||
| # Given `"foo"`, returns a string like 'gem "foo", "= 1.2.3"', suitable for inserting into a Gemfile. | ||
| #: (String) -> String | ||
| def gem_requirement_from_real_bundle(gem_name) | ||
| specs = Bundler.load.gems[gem_name] | ||
|
|
||
| if specs.nil? || specs.empty? | ||
| raise "Did not find gem #{gem_name.inspect} in the current bundle" | ||
| elsif specs.count > 1 | ||
| raise <<~MSG | ||
| Found multiple versions of #{gem_name.inspect} in the current bundle: | ||
| #{specs.sort_by(&:version).map { |spec| " - #{spec.name} #{spec.version}" }.join("\n")} | ||
| MSG | ||
| else | ||
| spec = specs.first | ||
| %(gem "#{spec.name}", "= #{spec.version}") | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,5 +2,5 @@ | |
| # frozen_string_literal: true | ||
|
|
||
| module Spoom | ||
| VERSION = "1.7.9" | ||
| VERSION = "1.7.10" | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # typed: true | ||
| # frozen_string_literal: true | ||
|
|
||
| require "test_helper" | ||
|
|
||
| module Spoom | ||
| class BundlerHelperTest < Minitest::Test | ||
| def test_gem_requirement_from_real_bundle_returns_gem_requirement_string | ||
| gem_from_spoom_bundle = "tapioca" | ||
| gem_requirement = BundlerHelper.gem_requirement_from_real_bundle(gem_from_spoom_bundle) | ||
|
|
||
| assert_match(/^gem "#{gem_from_spoom_bundle}", "= .+"$/, gem_requirement) | ||
| end | ||
|
|
||
| def test_raises_if_gem_not_found_in_bundle | ||
| assert_raises(RuntimeError) do | ||
| BundlerHelper.gem_requirement_from_real_bundle("not-real") | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ def test_context_run_srb_from_bundle | |
| context.write_gemfile!(<<~GEMFILE) | ||
| source "https://rubygems.org" | ||
|
|
||
| gem "sorbet" | ||
| #{Spoom::BundlerHelper.gem_requirement_from_real_bundle("sorbet")} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we really care which version of Sorbet gets installed in these tests?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so either, but I'd rather not have to worry about it. |
||
| GEMFILE | ||
| context.bundle("config set --local path $GEM_HOME") | ||
| context.bundle_install! | ||
|
|
@@ -67,7 +67,7 @@ def test_context_run_srb_from_path | |
| context.write_gemfile!(<<~GEMFILE) | ||
| source "https://rubygems.org" | ||
|
|
||
| gem "sorbet" | ||
| #{Spoom::BundlerHelper.gem_requirement_from_real_bundle("sorbet")} | ||
| GEMFILE | ||
| context.bundle_install! | ||
|
|
||
|
|
@@ -163,7 +163,7 @@ def test_context_srb_version_return_version_string | |
| context.write_gemfile!(<<~GEMFILE) | ||
| source "https://rubygems.org" | ||
|
|
||
| gem "sorbet" | ||
| #{Spoom::BundlerHelper.gem_requirement_from_real_bundle("sorbet")} | ||
| GEMFILE | ||
| context.bundle_install! | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,8 +51,8 @@ def test_deadcode_plugins_with_sorbet | |
| plugins = plugins_classes_for_gemfile(<<~GEMFILE) | ||
| source "https://rubygems.org" | ||
|
|
||
| gem "sorbet" | ||
| gem "sorbet-runtime" | ||
| #{Spoom::BundlerHelper.gem_requirement_from_real_bundle("sorbet")} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, I don't think we really care about which version we use |
||
| #{Spoom::BundlerHelper.gem_requirement_from_real_bundle("sorbet-runtime")} | ||
| GEMFILE | ||
|
|
||
| assert_equal( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this explanation be clear to someone who didn't already understand what's going on here?