mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[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 *c5161501e0/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 bundlerab0785a09f
This commit is contained in:
parent
603edfcaa0
commit
f75bd9bb8b
Notes:
git
2020-06-05 07:33:55 +09:00
13 changed files with 365 additions and 292 deletions
|
@ -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
|
||||
|
|
|
@ -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 <value>. rspec/minitest/test-unit/(none):"
|
||||
if result =~ /rspec|minitest|test-unit/
|
||||
test_framework = result
|
||||
else
|
||||
|
|
|
@ -65,7 +65,16 @@ Do not create a \fBLICENSE\.txt\fR (overrides \fB\-\-mit\fR specified in the glo
|
|||
.
|
||||
.TP
|
||||
\fB\-t\fR, \fB\-\-test=minitest\fR, \fB\-\-test=rspec\fR, \fB\-\-test=test\-unit\fR
|
||||
Specify the test framework that Bundler should use when generating the project\. Acceptable values are \fBminitest\fR, \fBrspec\fR and \fBtest\-unit\fR\. The \fBGEM_NAME\.gemspec\fR will be configured and a skeleton test/spec directory will be created based on this option\. If this option is unspecified, an interactive prompt will be displayed and the answer will be saved in Bundler\'s global config for future \fBbundle gem\fR use\. If no option is specified, the default testing framework is RSpec\.
|
||||
Specify the test framework that Bundler should use when generating the project\. Acceptable values are \fBminitest\fR, \fBrspec\fR and \fBtest\-unit\fR\. The \fBGEM_NAME\.gemspec\fR will be configured and a skeleton test/spec directory will be created based on this option\. Given no option is specified:
|
||||
.
|
||||
.IP
|
||||
When Bundler is configured to generate tests, this defaults to Bundler\'s global config setting \fBgem\.test\fR\.
|
||||
.
|
||||
.IP
|
||||
When Bundler is configured to not generate tests, an interactive prompt will be displayed and the answer will be used for the current rubygem project\.
|
||||
.
|
||||
.IP
|
||||
When Bundler is unconfigured, an interactive prompt will be displayed and the answer will be saved in Bundler\'s global config for future \fBbundle gem\fR use\.
|
||||
.
|
||||
.TP
|
||||
\fB\-e\fR, \fB\-\-edit[=EDITOR]\fR
|
||||
|
|
|
@ -70,10 +70,18 @@ OPTIONS
|
|||
generating the project. Acceptable values are minitest, rspec
|
||||
and test-unit. The GEM_NAME.gemspec will be configured and a
|
||||
skeleton test/spec directory will be created based on this
|
||||
option. If this option is unspecified, an interactive prompt
|
||||
will be displayed and the answer will be saved in Bundler's
|
||||
global config for future bundle gem use. If no option is
|
||||
specified, the default testing framework is RSpec.
|
||||
option. Given no option is specified:
|
||||
|
||||
When Bundler is configured to generate tests, this defaults to
|
||||
Bundler's global config setting gem.test.
|
||||
|
||||
When Bundler is configured to not generate tests, an interactive
|
||||
prompt will be displayed and the answer will be used for the
|
||||
current rubygem project.
|
||||
|
||||
When Bundler is unconfigured, an interactive prompt will be
|
||||
displayed and the answer will be saved in Bundler's global
|
||||
config for future bundle gem use.
|
||||
|
||||
-e, --edit[=EDITOR]
|
||||
Open the resulting GEM_NAME.gemspec in EDITOR, or the default
|
||||
|
|
|
@ -64,10 +64,17 @@ configuration file using the following names:
|
|||
Specify the test framework that Bundler should use when generating the
|
||||
project. Acceptable values are `minitest`, `rspec` and `test-unit`. The
|
||||
`GEM_NAME.gemspec` will be configured and a skeleton test/spec directory will
|
||||
be created based on this option. If this option is unspecified, an interactive
|
||||
prompt will be displayed and the answer will be saved in Bundler's global
|
||||
config for future `bundle gem` use.
|
||||
If no option is specified, the default testing framework is RSpec.
|
||||
be created based on this option. Given no option is specified:
|
||||
|
||||
When Bundler is configured to generate tests, this defaults to Bundler's
|
||||
global config setting `gem.test`.
|
||||
|
||||
When Bundler is configured to not generate tests, an interactive prompt will
|
||||
be displayed and the answer will be used for the current rubygem project.
|
||||
|
||||
When Bundler is unconfigured, an interactive prompt will be displayed and
|
||||
the answer will be saved in Bundler's global config for future `bundle gem`
|
||||
use.
|
||||
|
||||
* `-e`, `--edit[=EDITOR]`:
|
||||
Open the resulting GEM_NAME.gemspec in EDITOR, or the default editor if not
|
||||
|
|
|
@ -194,6 +194,26 @@ RSpec.describe "bundle gem" do
|
|||
end
|
||||
end
|
||||
|
||||
shared_examples_for "test framework is present" do
|
||||
it "creates a .travis.yml file to test the library against the current Ruby version on Travis CI" do
|
||||
expect(bundled_app("#{gem_name}/.travis.yml").read).to match(/- #{RUBY_VERSION}/)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for "test framework is absent" do
|
||||
it "does not create any test framework files" do
|
||||
expect(bundled_app("#{gem_name}/.rspec")).to_not exist
|
||||
expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb")).to_not exist
|
||||
expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to_not exist
|
||||
expect(bundled_app("#{gem_name}/test/#{require_path}.rb")).to_not exist
|
||||
expect(bundled_app("#{gem_name}/test/test_helper.rb")).to_not exist
|
||||
end
|
||||
|
||||
it "does not create a .travis.yml file" do
|
||||
expect(bundled_app("#{gem_name}/.travis.yml")).to_not exist
|
||||
end
|
||||
end
|
||||
|
||||
context "README.md", :readline do
|
||||
context "git config github.user present" do
|
||||
before do
|
||||
|
@ -408,13 +428,7 @@ RSpec.describe "bundle gem" do
|
|||
bundle! "gem #{gem_name}"
|
||||
end
|
||||
|
||||
it "doesn't create any spec/test file" do
|
||||
expect(bundled_app("#{gem_name}/.rspec")).to_not exist
|
||||
expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb")).to_not exist
|
||||
expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to_not exist
|
||||
expect(bundled_app("#{gem_name}/test/#{require_path}.rb")).to_not exist
|
||||
expect(bundled_app("#{gem_name}/test/test_helper.rb")).to_not exist
|
||||
end
|
||||
it_behaves_like "test framework is absent"
|
||||
end
|
||||
|
||||
context "--test parameter set to rspec" do
|
||||
|
@ -444,6 +458,8 @@ RSpec.describe "bundle gem" do
|
|||
it "creates a default test which fails" do
|
||||
expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb").read).to include("expect(false).to eq(true)")
|
||||
end
|
||||
|
||||
it_behaves_like "test framework is present"
|
||||
end
|
||||
|
||||
context "gem.test setting set to rspec" do
|
||||
|
@ -457,6 +473,8 @@ RSpec.describe "bundle gem" do
|
|||
expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb")).to exist
|
||||
expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to exist
|
||||
end
|
||||
|
||||
it_behaves_like "test framework is present"
|
||||
end
|
||||
|
||||
context "gem.test setting set to rspec and --test is set to minitest" do
|
||||
|
@ -469,6 +487,8 @@ RSpec.describe "bundle gem" do
|
|||
expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb")).to exist
|
||||
expect(bundled_app("#{gem_name}/test/test_helper.rb")).to exist
|
||||
end
|
||||
|
||||
it_behaves_like "test framework is present"
|
||||
end
|
||||
|
||||
context "--test parameter set to minitest" do
|
||||
|
@ -501,6 +521,8 @@ RSpec.describe "bundle gem" do
|
|||
it "creates a default test which fails" do
|
||||
expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include("assert false")
|
||||
end
|
||||
|
||||
it_behaves_like "test framework is present"
|
||||
end
|
||||
|
||||
context "gem.test setting set to minitest" do
|
||||
|
@ -525,6 +547,8 @@ RSpec.describe "bundle gem" do
|
|||
|
||||
expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)
|
||||
end
|
||||
|
||||
it_behaves_like "test framework is present"
|
||||
end
|
||||
|
||||
context "--test parameter set to test-unit" do
|
||||
|
@ -557,6 +581,8 @@ RSpec.describe "bundle gem" do
|
|||
it "creates a default test which fails" do
|
||||
expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include("assert_equal(\"expected\", \"actual\")")
|
||||
end
|
||||
|
||||
it_behaves_like "test framework is present"
|
||||
end
|
||||
|
||||
context "gem.test setting set to test-unit" do
|
||||
|
@ -581,21 +607,42 @@ RSpec.describe "bundle gem" do
|
|||
|
||||
expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)
|
||||
end
|
||||
|
||||
it_behaves_like "test framework is present"
|
||||
end
|
||||
|
||||
context "--test with no arguments" do
|
||||
context "gem.test set to rspec and --test with no arguments" do
|
||||
before do
|
||||
bundle "config set gem.test rspec"
|
||||
bundle! "gem #{gem_name} --test"
|
||||
end
|
||||
|
||||
it "builds spec skeleton" do
|
||||
expect(bundled_app("#{gem_name}/.rspec")).to exist
|
||||
expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb")).to exist
|
||||
expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to exist
|
||||
end
|
||||
|
||||
it_behaves_like "test framework is present"
|
||||
end
|
||||
|
||||
context "gem.test setting set to false and --test with no arguments" do
|
||||
before do
|
||||
bundle "config set gem.test false"
|
||||
end
|
||||
|
||||
it "asks to generate test files" do
|
||||
result = bundle! "gem #{gem_name} --test"
|
||||
expect(result).to match("Do you want to generate tests with your gem?")
|
||||
end
|
||||
end
|
||||
|
||||
context "gem.test setting not set and --test with no arguments" do
|
||||
before do
|
||||
bundle! "gem #{gem_name} --test"
|
||||
end
|
||||
|
||||
it "defaults to rspec" do
|
||||
expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to exist
|
||||
expect(bundled_app("#{gem_name}/test/test_helper.rb")).to_not exist
|
||||
end
|
||||
|
||||
it "creates a .travis.yml file to test the library against the current Ruby version on Travis CI" do
|
||||
expect(bundled_app("#{gem_name}/.travis.yml").read).to match(/- #{RUBY_VERSION}/)
|
||||
end
|
||||
it_behaves_like "test framework is absent"
|
||||
end
|
||||
|
||||
context "--edit option" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue