Skip to content

Commit

Permalink
[rubygems/rubygems] Update generated minitest file style
Browse files Browse the repository at this point in the history
foo     => test/test_foo.rb
foo-bar => test/foo/test_bar.rb
foo_bar => test/test_foo_bar.rb

rubygems/rubygems@c795e5d40d
  • Loading branch information
unasuke authored and matzbot committed Jan 19, 2022
1 parent 4e955b2 commit 4451313
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
10 changes: 9 additions & 1 deletion lib/bundler/cli/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,17 @@ def run
)
config[:test_task] = :spec
when "minitest"
# Generate path for minitest target file (FileList["test/**/test_*.rb"])
# foo => test/test_foo.rb
# foo-bar => test/foo/test_bar.rb
# foo_bar => test/test_foo_bar.rb
paths = namespaced_path.rpartition("/")
paths[2] = "test_#{paths[2]}"
minitest_namespaced_path = paths.join("")

templates.merge!(
"test/minitest/test_helper.rb.tt" => "test/test_helper.rb",
"test/minitest/test_newgem.rb.tt" => "test/test_#{underscored_name}.rb"
"test/minitest/test_newgem.rb.tt" => "test/#{minitest_namespaced_path}.rb"
)
config[:test_task] = :test
when "test-unit"
Expand Down
18 changes: 10 additions & 8 deletions spec/bundler/commands/newgem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def bundle_exec_standardrb

let(:require_path) { "mygem" }

let(:minitest_test_file_path) { "test/test_mygem.rb" }

before do
sys_exec("git config --global user.name 'Bundler User'")
sys_exec("git config --global user.email user@example.com")
Expand Down Expand Up @@ -696,22 +698,18 @@ def create_temporary_dir(dir)
end

context "gem.test setting set to rspec and --test is set to minitest" do
let(:underscored_require_path) { require_path.tr("/", "_") }

before do
bundle "config set gem.test rspec"
bundle "gem #{gem_name} --test=minitest"
end

it "builds spec skeleton" do
expect(bundled_app("#{gem_name}/test/test_#{underscored_require_path}.rb")).to exist
expect(bundled_app("#{gem_name}/#{minitest_test_file_path}")).to exist
expect(bundled_app("#{gem_name}/test/test_helper.rb")).to exist
end
end

context "--test parameter set to minitest" do
let(:underscored_require_path) { require_path.tr("/", "_") }

before do
bundle "gem #{gem_name} --test=minitest"
end
Expand All @@ -726,7 +724,7 @@ def create_temporary_dir(dir)
end

it "builds spec skeleton" do
expect(bundled_app("#{gem_name}/test/test_#{underscored_require_path}.rb")).to exist
expect(bundled_app("#{gem_name}/#{minitest_test_file_path}")).to exist
expect(bundled_app("#{gem_name}/test/test_helper.rb")).to exist
end

Expand All @@ -735,11 +733,11 @@ def create_temporary_dir(dir)
end

it "requires 'test_helper'" do
expect(bundled_app("#{gem_name}/test/test_#{underscored_require_path}.rb").read).to include(%(require "test_helper"))
expect(bundled_app("#{gem_name}/#{minitest_test_file_path}").read).to include(%(require "test_helper"))
end

it "creates a default test which fails" do
expect(bundled_app("#{gem_name}/test/test_#{underscored_require_path}.rb").read).to include("assert false")
expect(bundled_app("#{gem_name}/#{minitest_test_file_path}").read).to include("assert false")
end
end

Expand Down Expand Up @@ -1304,6 +1302,8 @@ def create_temporary_dir(dir)

let(:require_relative_path) { "test_gem" }

let(:minitest_test_file_path) { "test/test_test_gem.rb" }

let(:flags) { nil }

it "does not nest constants" do
Expand Down Expand Up @@ -1359,6 +1359,8 @@ def create_temporary_dir(dir)

let(:require_relative_path) { "gem" }

let(:minitest_test_file_path) { "test/test/test_gem.rb" }

it "nests constants so they work" do
bundle "gem #{gem_name}"
expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb").read).to match(/module Test\n module Gem/)
Expand Down

0 comments on commit 4451313

Please sign in to comment.