1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Change generated namespaced test class name in minitest

* `foo` => `TestFoo`
* `foo_bar` => `TestFooBar`
* `foo-bar` => `Foo::TestBar`

https://github.com/rubygems/rubygems/commit/353cdd61c3
This commit is contained in:
Yusuke Nakamura 2022-01-19 17:52:27 +09:00 committed by git
parent 26e0450ba9
commit 7353f950c3
3 changed files with 4 additions and 2 deletions

View file

@ -38,6 +38,7 @@ module Bundler
namespaced_path = name.tr("-", "/")
constant_name = name.gsub(/-[_-]*(?![_-]|$)/) { "::" }.gsub(/([_-]+|(::)|^)(.|$)/) { $2.to_s + $3.upcase }
constant_array = constant_name.split("::")
minitest_constant_name = constant_array.clone.tap {|a| a[-1] = "Test#{a[-1]}" }.join("::") # Foo::Bar => Foo::TestBar
use_git = Bundler.git_present? && options[:git]
@ -69,6 +70,7 @@ module Bundler
:git => use_git,
:github_username => github_username.empty? ? "[USERNAME]" : github_username,
:required_ruby_version => required_ruby_version,
:minitest_constant_name => minitest_constant_name,
}
ensure_safe_gem_name(name, constant_array)

View file

@ -2,7 +2,7 @@
require "test_helper"
class Test<%= config[:constant_name].gsub('::', '') %> < Minitest::Test
class <%= config[:minitest_constant_name] %> < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::<%= config[:constant_name] %>::VERSION
end

View file

@ -1369,7 +1369,7 @@ RSpec.describe "bundle gem" do
let(:minitest_test_file_path) { "test/test/test_gem.rb" }
let(:minitest_test_class_name) { "class TestTestGem < Minitest::Test" }
let(:minitest_test_class_name) { "class Test::TestGem < Minitest::Test" }
it "nests constants so they work" do
bundle "gem #{gem_name}"