diff options
author | TangRufus <[email protected]> | 2025-05-30 01:49:44 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2025-06-03 08:04:04 +0900 |
commit | 04a396409d19ed1ae40a663663bf3108c3ac844f (patch) | |
tree | 5d1507a924c6280c2cd105441eb3838ddb0365bf | |
parent | b34959b497c274563b0e148eb9408c715647048a (diff) |
[rubygems/rubygems] Refactor `spec.files` ignore list generation
https://github.com/rubygems/rubygems/commit/c11539f325
-rw-r--r-- | lib/bundler/cli/gem.rb | 7 | ||||
-rw-r--r-- | lib/bundler/templates/newgem/newgem.gemspec.tt | 2 | ||||
-rw-r--r-- | spec/bundler/commands/newgem_spec.rb | 14 |
3 files changed, 15 insertions, 8 deletions
diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb index b75ec9bc0f..bc441e5b8b 100644 --- a/lib/bundler/cli/gem.rb +++ b/lib/bundler/cli/gem.rb @@ -74,6 +74,7 @@ module Bundler required_ruby_version: required_ruby_version, rust_builder_required_rubygems_version: rust_builder_required_rubygems_version, minitest_constant_name: minitest_constant_name, + ignore_files: %w[bin/ test/ spec/ features/ .git appveyor Gemfile], } ensure_safe_gem_name(name, constant_array) @@ -135,13 +136,13 @@ module Bundler case config[:ci] when "github" templates.merge!("github/workflows/main.yml.tt" => ".github/workflows/main.yml") - config[:ci_config_path] = ".github " + config[:ignore_files] << ".github" when "gitlab" templates.merge!("gitlab-ci.yml.tt" => ".gitlab-ci.yml") - config[:ci_config_path] = ".gitlab-ci.yml " + config[:ignore_files] << ".gitlab-ci.yml" when "circle" templates.merge!("circleci/config.yml.tt" => ".circleci/config.yml") - config[:ci_config_path] = ".circleci " + config[:ignore_files] << ".circleci" end if ask_and_set(:mit, "Do you want to license your code permissively under the MIT license?", diff --git a/lib/bundler/templates/newgem/newgem.gemspec.tt b/lib/bundler/templates/newgem/newgem.gemspec.tt index ced300f379..2f068a4225 100644 --- a/lib/bundler/templates/newgem/newgem.gemspec.tt +++ b/lib/bundler/templates/newgem/newgem.gemspec.tt @@ -31,7 +31,7 @@ Gem::Specification.new do |spec| spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls| ls.readlines("\x0", chomp: true).reject do |f| (f == gemspec) || - f.start_with?(*%w[bin/ test/ spec/ features/ .git <%= config[:ci_config_path] %>appveyor Gemfile]) + f.start_with?(*%w[<%= config[:ignore_files].join(" ") %>]) end end spec.bindir = "exe" diff --git a/spec/bundler/commands/newgem_spec.rb b/spec/bundler/commands/newgem_spec.rb index f7a68e1ea5..5560734198 100644 --- a/spec/bundler/commands/newgem_spec.rb +++ b/spec/bundler/commands/newgem_spec.rb @@ -22,6 +22,13 @@ RSpec.describe "bundle gem" do bundle "exec standardrb --debug", dir: bundled_app(gem_name) end + def assert_ignore_list_includes(path) + generated = bundled_app("#{gem_name}/#{gem_name}.gemspec").read + matched = generated.match(/^\s+f\.start_with\?\(\*%w\[(?<ignored>.*)\]\)$/) + ignored = matched[:ignored]&.split(" ") + expect(ignored).to include(path) + end + let(:generated_gemspec) { Bundler.load_gemspec_uncached(bundled_app(gem_name).join("#{gem_name}.gemspec")) } let(:gem_name) { "mygem" } @@ -1022,8 +1029,7 @@ RSpec.describe "bundle gem" do it "includes .github into ignore list" do bundle "gem #{gem_name} --ci=github" - - expect(bundled_app("#{gem_name}/#{gem_name}.gemspec").read).to include(".git .github appveyor") + assert_ignore_list_includes ".github" end end @@ -1037,7 +1043,7 @@ RSpec.describe "bundle gem" do it "includes .gitlab-ci.yml into ignore list" do bundle "gem #{gem_name} --ci=gitlab" - expect(bundled_app("#{gem_name}/#{gem_name}.gemspec").read).to include(".git .gitlab-ci.yml appveyor") + assert_ignore_list_includes ".gitlab-ci.yml" end end @@ -1051,7 +1057,7 @@ RSpec.describe "bundle gem" do it "includes .circleci into ignore list" do bundle "gem #{gem_name} --ci=circle" - expect(bundled_app("#{gem_name}/#{gem_name}.gemspec").read).to include(".git .circleci appveyor") + assert_ignore_list_includes ".circleci" end end |