summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2020-01-08 07:16:22 +0000
committerBundlerbot <bot@bundler.io>2020-01-08 07:16:22 +0000
commitd9ea09defd07e9957ae782ab7960ebea92515c3c (patch)
tree32000371c0ec6735dd59fdf8392d36562a46885e
parentf6961998894804a957e5dd919d213566b418d5db (diff)
parent27f5e98aaee329219d4ffdd52f4da876c5e84f22 (diff)
downloadbundler-d9ea09defd07e9957ae782ab7960ebea92515c3c.tar.gz
Merge #5521
5521: bundler gem: Support test-unit as a testing framework r=hsbt a=kou Co-authored-by: Kouhei Sutou <kou@clear-code.com>
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/cli/gem.rb21
-rw-r--r--lib/bundler/templates/newgem/Rakefile.tt7
-rw-r--r--lib/bundler/templates/newgem/test/minitest/newgem_test.rb.tt (renamed from lib/bundler/templates/newgem/test/newgem_test.rb.tt)0
-rw-r--r--lib/bundler/templates/newgem/test/minitest/test_helper.rb.tt (renamed from lib/bundler/templates/newgem/test/test_helper.rb.tt)0
-rw-r--r--lib/bundler/templates/newgem/test/test-unit/newgem_test.rb.tt13
-rw-r--r--lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt4
-rw-r--r--man/bundle-gem.14
-rw-r--r--man/bundle-gem.1.txt16
-rw-r--r--man/bundle-gem.ronn12
-rw-r--r--spec/commands/newgem_spec.rb65
11 files changed, 113 insertions, 31 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 8afa649874..6f7ff90dc2 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -569,7 +569,7 @@ module Bundler
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",
- :desc => "Generate a test directory for your library, either rspec or minitest. Set a default with `bundle config set gem.test rspec`."
+ :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 403005a6bd..00b3bc55a6 100644
--- a/lib/bundler/cli/gem.rb
+++ b/lib/bundler/cli/gem.rb
@@ -12,6 +12,7 @@ module Bundler
TEST_FRAMEWORK_VERSIONS = {
"rspec" => "3.0",
"minitest" => "5.0",
+ "test-unit" => "3.0",
}.freeze
attr_reader :options, :gem_name, :thor, :name, :target
@@ -92,16 +93,22 @@ module Bundler
"spec/spec_helper.rb.tt" => "spec/spec_helper.rb",
"spec/newgem_spec.rb.tt" => "spec/#{namespaced_path}_spec.rb"
)
+ config[:test_task] = :spec
when "minitest"
templates.merge!(
- "test/test_helper.rb.tt" => "test/test_helper.rb",
- "test/newgem_test.rb.tt" => "test/#{namespaced_path}_test.rb"
+ "test/minitest/test_helper.rb.tt" => "test/test_helper.rb",
+ "test/minitest/newgem_test.rb.tt" => "test/#{namespaced_path}_test.rb"
)
+ config[:test_task] = :test
+ when "test-unit"
+ templates.merge!(
+ "test/test-unit/test_helper.rb.tt" => "test/test_helper.rb",
+ "test/test-unit/newgem_test.rb.tt" => "test/#{namespaced_path}_test.rb"
+ )
+ config[:test_task] = :test
end
end
- config[:test_task] = config[:test] == "minitest" ? :test : :spec
-
if ask_and_set(:mit, "Do you want to license your code permissively under the MIT license?",
"This means that any other developer or company will be legally allowed to use your code " \
"for free as long as they admit you created it. You can read more about the MIT license " \
@@ -208,9 +215,9 @@ module Bundler
if test_framework.nil?
Bundler.ui.confirm "Do you want to generate tests with your gem?"
- result = Bundler.ui.ask "Type 'rspec' or 'minitest' to generate those test files now and " \
- "in the future. rspec/minitest/(none):"
- if result =~ /rspec|minitest/
+ 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):"
+ if result =~ /rspec|minitest|test-unit/
test_framework = result
else
test_framework = false
diff --git a/lib/bundler/templates/newgem/Rakefile.tt b/lib/bundler/templates/newgem/Rakefile.tt
index 1262457c72..af7729c04e 100644
--- a/lib/bundler/templates/newgem/Rakefile.tt
+++ b/lib/bundler/templates/newgem/Rakefile.tt
@@ -1,6 +1,7 @@
require "bundler/gem_tasks"
-<% default_task_names = [config[:test_task]] -%>
-<% if config[:test] == "minitest" -%>
+<% default_task_names = [config[:test_task]].compact -%>
+<% case config[:test] -%>
+<% when "minitest", "test-unit" -%>
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
@@ -9,7 +10,7 @@ Rake::TestTask.new(:test) do |t|
t.test_files = FileList["test/**/*_test.rb"]
end
-<% elsif config[:test] == "rspec" -%>
+<% when "rspec" -%>
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
diff --git a/lib/bundler/templates/newgem/test/newgem_test.rb.tt b/lib/bundler/templates/newgem/test/minitest/newgem_test.rb.tt
index f2af9f90e0..f2af9f90e0 100644
--- a/lib/bundler/templates/newgem/test/newgem_test.rb.tt
+++ b/lib/bundler/templates/newgem/test/minitest/newgem_test.rb.tt
diff --git a/lib/bundler/templates/newgem/test/test_helper.rb.tt b/lib/bundler/templates/newgem/test/minitest/test_helper.rb.tt
index 7d7db165ec..7d7db165ec 100644
--- a/lib/bundler/templates/newgem/test/test_helper.rb.tt
+++ b/lib/bundler/templates/newgem/test/minitest/test_helper.rb.tt
diff --git a/lib/bundler/templates/newgem/test/test-unit/newgem_test.rb.tt b/lib/bundler/templates/newgem/test/test-unit/newgem_test.rb.tt
new file mode 100644
index 0000000000..e653993006
--- /dev/null
+++ b/lib/bundler/templates/newgem/test/test-unit/newgem_test.rb.tt
@@ -0,0 +1,13 @@
+require "test_helper"
+
+class <%= config[:constant_name] %>Test < Test::Unit::TestCase
+ test "VERSION" do
+ assert do
+ ::<%= config[:constant_name] %>.const_defined?(:VERSION)
+ end
+ end
+
+ test "something useful" do
+ assert_equal("expected", "actual")
+ end
+end
diff --git a/lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt b/lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt
new file mode 100644
index 0000000000..461ee391a5
--- /dev/null
+++ b/lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt
@@ -0,0 +1,4 @@
+$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
+require "<%= config[:namespaced_path] %>"
+
+require "test-unit"
diff --git a/man/bundle-gem.1 b/man/bundle-gem.1
index baed185e70..df53a11d21 100644
--- a/man/bundle-gem.1
+++ b/man/bundle-gem.1
@@ -64,8 +64,8 @@ Add an MIT license to a \fBLICENSE\.txt\fR file in the root of the generated pro
Do not create a \fBLICENSE\.txt\fR (overrides \fB\-\-mit\fR specified in the global config)\.
.
.TP
-\fB\-t\fR, \fB\-\-test=minitest\fR, \fB\-\-test=rspec\fR
-Specify the test framework that Bundler should use when generating the project\. Acceptable values are \fBminitest\fR and \fBrspec\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\.
+\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\.
.
.TP
\fB\-e\fR, \fB\-\-edit[=EDITOR]\fR
diff --git a/man/bundle-gem.1.txt b/man/bundle-gem.1.txt
index 554bb1a41b..18ce2ba465 100644
--- a/man/bundle-gem.1.txt
+++ b/man/bundle-gem.1.txt
@@ -65,15 +65,15 @@ OPTIONS
Do not create a LICENSE.txt (overrides --mit specified in the
global config).
- -t, --test=minitest, --test=rspec
+ -t, --test=minitest, --test=rspec, --test=test-unit
Specify the test framework that Bundler should use when generat-
- ing the project. Acceptable values are minitest and rspec. 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 bun-
- dle gem use. If no option is specified, the default testing
- framework is RSpec.
+ ing the project. Acceptable values are minitest, rspec and
+ test-unit. The GEM_NAME.gemspec will be configured and a skele-
+ ton test/spec directory will be created based on this option. If
+ this option is unspecified, an interactive prompt will be dis-
+ played 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.
-e, --edit[=EDITOR]
Open the resulting GEM_NAME.gemspec in EDITOR, or the default
diff --git a/man/bundle-gem.ronn b/man/bundle-gem.ronn
index cf3d037df2..1dba9ed607 100644
--- a/man/bundle-gem.ronn
+++ b/man/bundle-gem.ronn
@@ -60,13 +60,13 @@ configuration file using the following names:
Do not create a `LICENSE.txt` (overrides `--mit` specified in the global
config).
-* `-t`, `--test=minitest`, `--test=rspec`:
+* `-t`, `--test=minitest`, `--test=rspec`, `--test=test-unit`:
Specify the test framework that Bundler should use when generating the
- project. Acceptable values are `minitest` and `rspec`. 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.
+ 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.
* `-e`, `--edit[=EDITOR]`:
diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb
index 7cad5c04a4..0bdf8ecba8 100644
--- a/spec/commands/newgem_spec.rb
+++ b/spec/commands/newgem_spec.rb
@@ -419,7 +419,7 @@ RSpec.describe "bundle gem" do
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/minitest_helper.rb")).to_not exist
+ expect(bundled_app("#{gem_name}/test/test_helper.rb")).to_not exist
end
end
@@ -502,7 +502,7 @@ RSpec.describe "bundle gem" do
expect(bundled_app("#{gem_name}/test/test_helper.rb").read).to include(%(require "#{require_path}"))
end
- it "requires 'minitest_helper'" do
+ it "requires 'test_helper'" do
expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include(%(require "test_helper"))
end
@@ -535,6 +535,63 @@ RSpec.describe "bundle gem" do
end
end
+ context "--test parameter set to test-unit" do
+ before do
+ bundle "gem #{gem_name} --test=test-unit"
+ end
+
+ it "depends on a specific version of test-unit" do
+ Dir.chdir(bundled_app(gem_name)) do
+ builder = Bundler::Dsl.new
+ builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
+ builder.dependencies
+ test_unit_dep = builder.dependencies.find {|d| d.name == "test-unit" }
+ expect(test_unit_dep).to be_specific
+ end
+ end
+
+ it "builds spec skeleton" 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 "requires the main file" do
+ expect(bundled_app("#{gem_name}/test/test_helper.rb").read).to include(%(require "#{require_path}"))
+ end
+
+ it "requires 'test_helper'" do
+ expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include(%(require "test_helper"))
+ end
+
+ 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
+ end
+
+ context "gem.test setting set to test-unit" do
+ before do
+ bundle "config set gem.test test-unit"
+ bundle "gem #{gem_name}"
+ end
+
+ it "creates a default rake task to run the test suite" do
+ rakefile = strip_whitespace <<-RAKEFILE
+ require "bundler/gem_tasks"
+ require "rake/testtask"
+
+ Rake::TestTask.new(:test) do |t|
+ t.libs << "test"
+ t.libs << "lib"
+ t.test_files = FileList["test/**/*_test.rb"]
+ end
+
+ task :default => :test
+ RAKEFILE
+
+ expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)
+ end
+ end
+
context "--test with no arguments" do
before do
bundle! "gem #{gem_name} --test"
@@ -542,7 +599,7 @@ RSpec.describe "bundle gem" do
it "defaults to rspec" do
expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to exist
- expect(bundled_app("#{gem_name}/test/minitest_helper.rb")).to_not 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
@@ -655,7 +712,7 @@ RSpec.describe "bundle gem" do
ext.lib_dir = "lib/#{gem_name}"
end
- task :default => [:clobber, :compile, :spec]
+ task :default => [:clobber, :compile]
RAKEFILE
expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)