summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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
7 files changed, 36 insertions, 11 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 86c9da6b99..523eb77168 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"