Skip to content

Commit

Permalink
Create minitest file to underscored path in "bundle gem" command
Browse files Browse the repository at this point in the history
...with dashed gem name

In "bundle gem" command with dashed name gem (e.g. foo-bar) generates
`test/test_foo/bar.rb`, but this file contains undefined class `TestFoo`
and moreover, does not include in "bundle exec rake test" target.

Therefore, intentially the first test after gem created is fail, but in
case of gem name contains dash character is not.

The change doings...
(when "bundle gem foo-bar" called)

* create `test/test_foo_bar.rb`
* define `TestFooBar` class in `test/test_foo_bar.rb`
  • Loading branch information
unasuke committed Jan 10, 2022
1 parent a9f9341 commit 5d9a69f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bundler/lib/bundler/cli/gem.rb
Expand Up @@ -106,7 +106,7 @@ def run
when "minitest"
templates.merge!(
"test/minitest/test_helper.rb.tt" => "test/test_helper.rb",
"test/minitest/test_newgem.rb.tt" => "test/test_#{namespaced_path}.rb"
"test/minitest/test_newgem.rb.tt" => "test/test_#{underscored_name}.rb"
)
config[:test_task] = :test
when "test-unit"
Expand Down
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class Test<%= config[:constant_name] %> < Minitest::Test
class Test<%= config[:constant_name].gsub('::', '') %> < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::<%= config[:constant_name] %>::VERSION
end
Expand Down
12 changes: 8 additions & 4 deletions bundler/spec/commands/newgem_spec.rb
Expand Up @@ -696,18 +696,22 @@ 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_#{require_path}.rb")).to exist
expect(bundled_app("#{gem_name}/test/test_#{underscored_require_path}.rb")).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 @@ -722,7 +726,7 @@ def create_temporary_dir(dir)
end

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

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

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

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

Expand Down

0 comments on commit 5d9a69f

Please sign in to comment.