summaryrefslogtreecommitdiff
path: root/spec/bundler/commands/newgem_spec.rb
diff options
context:
space:
mode:
authorFrank Lam <ryzingsun11@yahoo.com>2020-04-24 16:00:59 +0800
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-06-05 07:32:42 +0900
commitf75bd9bb8bf1764de613ab1b601d21c46b1d4681 (patch)
tree31db6e7252257250600af76b93991d008d31a65d /spec/bundler/commands/newgem_spec.rb
parent603edfcaa0aa6ea6660d045194769046d24a59aa (diff)
downloadruby-f75bd9bb8bf1764de613ab1b601d21c46b1d4681.tar.gz
[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
Diffstat (limited to 'spec/bundler/commands/newgem_spec.rb')
-rw-r--r--spec/bundler/commands/newgem_spec.rb71
1 files changed, 59 insertions, 12 deletions
diff --git a/spec/bundler/commands/newgem_spec.rb b/spec/bundler/commands/newgem_spec.rb
index 1dc51de9e7..fcefa4d15e 100644
--- a/spec/bundler/commands/newgem_spec.rb
+++ b/spec/bundler/commands/newgem_spec.rb
@@ -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 "defaults to rspec" do
+ 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
- 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}/)
+ 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_behaves_like "test framework is absent"
end
context "--edit option" do