Skip to content

Conversation

@amomchilov
Copy link
Contributor

@amomchilov amomchilov commented Nov 19, 2025

@amomchilov amomchilov requested a review from a team as a code owner November 19, 2025 17:45
@amomchilov amomchilov force-pushed the Alex/use-bundled-gem-version branch 2 times, most recently from d4ea64d to 27c3fd1 Compare November 19, 2025 20:20
@amomchilov amomchilov requested a review from paracycle November 19, 2025 20:21
@amomchilov amomchilov requested a review from Morriar November 19, 2025 20:45
@amomchilov amomchilov force-pushed the Alex/use-bundled-gem-version branch from 27c3fd1 to b3fa636 Compare November 19, 2025 20:45
@amomchilov amomchilov enabled auto-merge November 19, 2025 20:45
@amomchilov amomchilov disabled auto-merge November 19, 2025 20:48
@amomchilov amomchilov changed the title Always use bundled Tapioca version Use bundle-locked gem versions in child contexts Nov 19, 2025
@amomchilov amomchilov force-pushed the Alex/use-bundled-gem-version branch from b3fa636 to fcfce11 Compare November 19, 2025 22:40
Comment on lines +9 to +12
# 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.
Copy link
Contributor Author

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?

@amomchilov amomchilov force-pushed the Alex/use-bundled-gem-version branch 2 times, most recently from b0b5104 to 519953f Compare November 19, 2025 22:46
source "https://rubygems.org"
gem "sorbet"
#{Spoom::BundlerHelper.gem_requirement_from_real_bundle("sorbet")}
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

gem "sorbet"
gem "sorbet-runtime"
#{Spoom::BundlerHelper.gem_requirement_from_real_bundle("sorbet")}
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Comment on lines 19 to 30
if 1 < specs.count
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
end

unless (spec = specs.first)
raise "Did not find gem #{gem_name.inspect} in the current bundle"
end

%(gem "#{spec.name}", "= #{spec.version}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is such a convoluted way to express something simple:

Suggested change
if 1 < specs.count
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
end
unless (spec = specs.first)
raise "Did not find gem #{gem_name.inspect} in the current bundle"
end
%(gem "#{spec.name}", "= #{spec.version}")
if specs.count < 1
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
%(gem "#{spec.name}", "= #{spec.version}")
end

Copy link
Contributor Author

@amomchilov amomchilov Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot spec = specs.first, but then that doesn't typecheck because it's nilable, so you need a #: !nil...

And it turns out about the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So something like this?

        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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, except it would need spec = specs.first #: !nil, which is worse. Turns out we don't need it, because Bundler.load is untyped 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would need spec = specs.first #: !nil, which is worse

Is it really now that it's a comment? Only the static checker has to do additional work, the runtime stays unchanged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a matter of personal taste, I prefer the if (x = a.first) to check a.count > 1 and get the first in a single shot. Won't someone think of the branches?! :D

Had to also run:

```sh
bundle exec spoom srb sigs export
```
RubyLSP highlights it better in this case, because it misinterprets the interpolated bits as Ruby comments (because of the leading `#`).
@amomchilov amomchilov force-pushed the Alex/use-bundled-gem-version branch from 519953f to 7120179 Compare November 19, 2025 23:50
@amomchilov amomchilov requested a review from Morriar November 20, 2025 15:56
@amomchilov amomchilov merged commit 6e2eacf into main Nov 21, 2025
8 checks passed
@amomchilov amomchilov deleted the Alex/use-bundled-gem-version branch November 21, 2025 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants