diff options
author | Kouhei Sutou <kou@clear-code.com> | 2019-12-11 14:02:33 +0900 |
---|---|---|
committer | Sutou Kouhei <kou@clear-code.com> | 2019-12-11 16:17:54 +0900 |
commit | 27f5e98aaee329219d4ffdd52f4da876c5e84f22 (patch) | |
tree | 54b2c123eed6d909e510379725ce73f972f8976a /lib/bundler | |
parent | bada03dd6d4d15828fb5b2cf7f744948e88a69a3 (diff) | |
download | bundler-27f5e98aaee329219d4ffdd52f4da876c5e84f22.tar.gz |
bundler gem: Support test-unit as a testing framework
Diffstat (limited to 'lib/bundler')
-rw-r--r-- | lib/bundler/cli.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/gem.rb | 21 | ||||
-rw-r--r-- | lib/bundler/templates/newgem/Rakefile.tt | 7 | ||||
-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.tt | 13 | ||||
-rw-r--r-- | lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt | 4 |
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" |