diff --git a/bundler/lib/bundler/templates/newgem/Gemfile.tt b/bundler/lib/bundler/templates/newgem/Gemfile.tt index b57050caf0a5..1d55fd7a90b8 100644 --- a/bundler/lib/bundler/templates/newgem/Gemfile.tt +++ b/bundler/lib/bundler/templates/newgem/Gemfile.tt @@ -7,11 +7,14 @@ gemspec gem "rake", "~> 13.0" <%- if config[:ext] -%> + gem "rake-compiler" <%- end -%> <%- if config[:test] -%> + gem "<%= config[:test] %>", "~> <%= config[:test_framework_version] %>" <%- end -%> <%- if config[:rubocop] -%> + gem "rubocop", "~> 0.80" <%- end -%> diff --git a/bundler/lib/bundler/templates/newgem/Rakefile.tt b/bundler/lib/bundler/templates/newgem/Rakefile.tt index 57222f8c5605..5393eb4e22bc 100644 --- a/bundler/lib/bundler/templates/newgem/Rakefile.tt +++ b/bundler/lib/bundler/templates/newgem/Rakefile.tt @@ -36,4 +36,8 @@ Rake::ExtensionTask.new("<%= config[:underscored_name] %>") do |ext| end <% end -%> -task default: <%= default_task_names.size == 1 ? default_task_names.first.inspect : default_task_names.inspect %> +<% if default_task_names.size == 1 -%> +task default: <%= default_task_names.first.inspect %> +<% else -%> +task default: %i[<%= default_task_names.join(" ") %>] +<% end -%> diff --git a/bundler/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt b/bundler/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt index 8cfc828f94f9..e918063ddf68 100644 --- a/bundler/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +++ b/bundler/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "mkmf" create_makefile(<%= config[:makefile_path].inspect %>) diff --git a/bundler/lib/bundler/templates/newgem/test/minitest/newgem_test.rb.tt b/bundler/lib/bundler/templates/newgem/test/minitest/newgem_test.rb.tt index f2af9f90e0ba..9e005d69a80b 100644 --- a/bundler/lib/bundler/templates/newgem/test/minitest/newgem_test.rb.tt +++ b/bundler/lib/bundler/templates/newgem/test/minitest/newgem_test.rb.tt @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class <%= config[:constant_name] %>Test < Minitest::Test diff --git a/bundler/lib/bundler/templates/newgem/test/minitest/test_helper.rb.tt b/bundler/lib/bundler/templates/newgem/test/minitest/test_helper.rb.tt index 7d7db165ecb6..e05c387bfae8 100644 --- a/bundler/lib/bundler/templates/newgem/test/minitest/test_helper.rb.tt +++ b/bundler/lib/bundler/templates/newgem/test/minitest/test_helper.rb.tt @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "<%= config[:namespaced_path] %>" diff --git a/bundler/lib/bundler/templates/newgem/test/test-unit/newgem_test.rb.tt b/bundler/lib/bundler/templates/newgem/test/test-unit/newgem_test.rb.tt index e653993006ae..5c61094e623a 100644 --- a/bundler/lib/bundler/templates/newgem/test/test-unit/newgem_test.rb.tt +++ b/bundler/lib/bundler/templates/newgem/test/test-unit/newgem_test.rb.tt @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class <%= config[:constant_name] %>Test < Test::Unit::TestCase diff --git a/bundler/lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt b/bundler/lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt index 461ee391a52d..6f633c60396a 100644 --- a/bundler/lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt +++ b/bundler/lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "<%= config[:namespaced_path] %>" diff --git a/bundler/spec/commands/newgem_spec.rb b/bundler/spec/commands/newgem_spec.rb index 16ce9def37f0..7dca5f518885 100644 --- a/bundler/spec/commands/newgem_spec.rb +++ b/bundler/spec/commands/newgem_spec.rb @@ -10,6 +10,15 @@ def gem_skeleton_assertions expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb")).to exist end + def bundle_exec_rubocop + prepare_gemspec(bundled_app(gem_name, "#{gem_name}.gemspec")) + rubocop_version = RUBY_VERSION > "2.4" ? "0.85.1" : "0.80.1" + gems = ["minitest", "rake", "rake-compiler", "rspec", "rubocop -v #{rubocop_version}", "test-unit"] + path = Bundler.feature_flag.default_install_uses_path? ? local_gem_path(:base => bundled_app(gem_name)) : system_gem_path + realworld_system_gems gems, :path => path + bundle "exec rubocop --config .rubocop.yml", :dir => bundled_app(gem_name) + end + let(:generated_gemspec) { Bundler.load_gemspec_uncached(bundled_app(gem_name).join("#{gem_name}.gemspec")) } let(:gem_name) { "mygem" } @@ -174,17 +183,6 @@ def gem_skeleton_assertions it "generates a default .rubocop.yml" do expect(bundled_app("#{gem_name}/.rubocop.yml")).to exist end - - it "runs rubocop inside the generated gem with no offenses" do - skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core? - prepare_gemspec(bundled_app(gem_name, "#{gem_name}.gemspec")) - rubocop_version = RUBY_VERSION > "2.4" ? "0.85.1" : "0.80.1" - gems = ["rake", "rubocop -v #{rubocop_version}"] - path = Bundler.feature_flag.default_install_uses_path? ? local_gem_path(:base => bundled_app(gem_name)) : system_gem_path - realworld_system_gems gems, :path => path - bundle "exec rubocop --config .rubocop.yml", :dir => bundled_app(gem_name) - expect(err).to be_empty - end end shared_examples_for "--no-rubocop flag" do @@ -214,6 +212,41 @@ def gem_skeleton_assertions end end + it "has no rubocop offenses when using --rubocop flag", :readline do + skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core? + bundle "gem #{gem_name} --rubocop" + bundle_exec_rubocop + expect(err).to be_empty + end + + it "has no rubocop offenses when using --ext and --rubocop flag", :readline do + skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core? + bundle "gem #{gem_name} --ext --rubocop" + bundle_exec_rubocop + expect(err).to be_empty + end + + it "has no rubocop offenses when using --ext, --test=minitest, and --rubocop flag", :readline do + skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core? + bundle "gem #{gem_name} --ext --test=minitest --rubocop" + bundle_exec_rubocop + expect(err).to be_empty + end + + it "has no rubocop offenses when using --ext, --test=rspec, and --rubocop flag", :readline do + skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core? + bundle "gem #{gem_name} --ext --test=rspec --rubocop" + bundle_exec_rubocop + expect(err).to be_empty + end + + it "has no rubocop offenses when using --ext, --ext=test-unit, and --rubocop flag", :readline do + skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core? + bundle "gem #{gem_name} --ext --test=test-unit --rubocop" + bundle_exec_rubocop + expect(err).to be_empty + end + shared_examples_for "CI config is absent" do it "does not create any CI files" do expect(bundled_app("#{gem_name}/.github/workflows/main.yml")).to_not exist @@ -914,7 +947,7 @@ def create_temporary_dir(dir) ext.lib_dir = "lib/#{gem_name}" end - task default: [:clobber, :compile] + task default: %i[clobber compile] RAKEFILE expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)