Skip to content

Let gem build load the gemspec - #27

Merged
skunkworker merged 1 commit into
masterfrom
jb/2026-09-28_fix_gemspec_gem_build
Sep 28, 2026
Merged

skunkworker merged 1 commit into
masterfrom
jb/2026-09-28_fix_gemspec_gem_build

Conversation

@skunkworker

Copy link
Copy Markdown
Contributor

Summary

rake build and rake release fail on master. Both run gem build -V, and Rubygems cannot load the gemspec:

Invalid gemspec in [active_remote-cached.gemspec]: undefined local variable or method 'gem_files' for class Gem::Specification
ERROR:  Error loading gemspec. Aborting.

Rubygems evals the gemspec inside Gem::Specification. So the top-level def gem_files (from c130217) became an instance method on Gem::Specification, and the Gem::Specification.new block could not call it. The HOMEPAGE constant also went onto Gem::Specification.

Bundler evals the gemspec at the top level, so bundle install and rspec did not show the error.

Changes

  • gem_files and homepage are now local variables. Locals work with both loaders. The file list logic does not change.
  • A comment in the gemspec tells why it uses locals.
  • New spec/gemspec_spec.rb. It loads the gemspec with Gem::Specification.load in a new Ruby process without Bundler, and calls validate. It must use a new process, because Bundler already loaded the gemspec in the rspec process.
  • No version bump. VERSION stays 1.3.0.

Evidence

  • The new spec fails on the old gemspec with the same gem_files error, and passes with this change.
  • gem build -V active_remote-cached.gemspec succeeds.
  • Gem::Specification.load and Bundler.load_gemspec give the same name, version, and file list.
  • Full suite: 190 examples, 0 failures (Ruby 3.4.9, Rubygems 4.0.15). RuboCop: 19 files, no offenses.

🤖 Generated with Claude Code

gem build failed with "undefined local variable or method 'gem_files'
for class Gem::Specification". Rubygems evals the gemspec inside
Gem::Specification, so the top-level def became an instance method, and
the Gem::Specification.new block could not call it. Bundler evals the
gemspec at the top level, so bundle install and rspec did not show it.

gem_files and homepage are now locals, which work in both places.

The new spec loads the gemspec with Gem::Specification.load in a fresh
ruby without Bundler. It fails with the same error on the old gemspec.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@skunkworker
skunkworker merged commit 65715e8 into master Sep 28, 2026
20 checks passed
@skunkworker
skunkworker deleted the jb/2026-09-28_fix_gemspec_gem_build branch September 29, 2026 00:07
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.

1 participant