From f75bd9bb8bf1764de613ab1b601d21c46b1d4681 Mon Sep 17 00:00:00 2001 From: Frank Lam Date: Fri, 24 Apr 2020 16:00:59 +0800 Subject: [rubygems/rubygems] Fix bundle gem ignoring global gem.test config * bundle gem previously ignored gem.test when passed empty -t flag, defaulting to RSpec * bundle gem will now ask user for test framework when passed empty -t flag and gem.test is set to false, but will not overwrite gem.test * thor option parsing for String types falls back to human name for nil, so setting lazy_default to nil won't work * https://github.com/erikhuda/thor/blob/c5161501e0cfac7a8c5b838a9c6084c275f03c0d/lib/thor/parser/options.rb#L224 Default to Bundler.settings["gem.test"] for empty --test Add shared examples for test framework to newgem spec Add examples for empty --test flag to newgem spec Simplify conditional for prompting test framework Follow naming conventions for bundler settings Add more descriptive test framework help text for bundle gem Update man pages for bundler https://github.com/rubygems/rubygems/commit/ab0785a09f --- lib/bundler/cli.rb | 2 +- lib/bundler/cli/gem.rb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 3d5194d61f..ec3044ee5b 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -573,7 +573,7 @@ module Bundler method_option :git, :type => :boolean, :default => true, :desc => "Initialize a git repo inside your library." method_option :mit, :type => :boolean, :desc => "Generate an MIT license file. Set a default with `bundle config set gem.mit true`." method_option :rubocop, :type => :boolean, :desc => "Add rubocop to the generated Rakefile and gemspec. Set a default with `bundle config set gem.rubocop true`." - method_option :test, :type => :string, :lazy_default => "rspec", :aliases => "-t", :banner => "rspec", + method_option :test, :type => :string, :lazy_default => Bundler.settings["gem.test"] || "", :aliases => "-t", :banner => "Use the specified test framework for your library", :desc => "Generate a test directory for your library, either rspec, minitest or test-unit. Set a default with `bundle config set gem.test rspec`." def gem(name) end diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb index 3fd67d9a88..7fe76adf4c 100644 --- a/lib/bundler/cli/gem.rb +++ b/lib/bundler/cli/gem.rb @@ -213,10 +213,12 @@ module Bundler def ask_and_set_test_framework test_framework = options[:test] || Bundler.settings["gem.test"] - if test_framework.nil? + if test_framework.to_s.empty? Bundler.ui.confirm "Do you want to generate tests with your gem?" - result = Bundler.ui.ask "Type 'rspec', 'minitest' or 'test-unit' to generate those test files now and " \ - "in the future. rspec/minitest/test-unit/(none):" + result = Bundler.ui.ask "Type 'rspec', 'minitest' or 'test-unit' to generate those test files now. \n" \ + "If Bundler is configured to not generate test files, your choice will only be applied to this instance. \n" \ + "Otherwise, future bundle gem calls will use your choice, so -t is not needed if your choice will be the same. \n" \ + "This setting can be changed anytime with bundle config gem.test . rspec/minitest/test-unit/(none):" if result =~ /rspec|minitest|test-unit/ test_framework = result else -- cgit v1.2.3