Skip to content

Commit

Permalink
Output deprecated warning for test framework that has test declarativ…
Browse files Browse the repository at this point in the history
…e style.

test-unit has the style from v 2.3.0.
  • Loading branch information
junaruga committed May 22, 2017
1 parent c5c7c6e commit d839c37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -35,6 +35,4 @@ matrix:
allow_failures:
- rvm: ruby-head
- rvm: jruby
# TODO fix this.
- gemfile: gemfiles/Gemfile.unit-test
fast_finish: true
5 changes: 5 additions & 0 deletions lib/test_declarative.rb
Expand Up @@ -4,6 +4,11 @@
targets << Minitest::Test if defined?(Minitest::Test)

targets.each do |target|
if target.respond_to? :test
warn "test_declarative is deprecated for #{target}"
next
end

target.class_eval do
def test(name, &block)
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
Expand Down
21 changes: 11 additions & 10 deletions test/test_declarative_test.rb
Expand Up @@ -7,35 +7,31 @@ def gemfile_name
File.basename(gemfile)
end

gemfile = gemfile_name
case gemfile
GEMFILE = gemfile_name
case GEMFILE
when 'Gemfile'
# Minitest >= 5
require 'minitest/autorun'
TEST_CASE = Minitest::Test
RUNNER = Minitest::Unit
MINITEST_5 = true
when 'Gemfile.minitest4'
# Minitest < 5
require 'minitest/autorun'
TEST_CASE = MiniTest::Unit::TestCase
RUNNER = MiniTest::Unit
MINITEST_5 = false
when 'Gemfile.unit-test'
# Latest test-unit
require 'test-unit'
require 'test/unit/testresult'
TEST_CASE = Test::Unit::TestCase
RUNNER = Test::Unit::TestResult
MINITEST_5 = false
when 'Gemfile.empty'
# Test for stdlib minitest.
# test-unit and minitest were removed from stdlib at Ruby 2.2.
# https://bugs.ruby-lang.org/issues/9711
require 'minitest/autorun'
TEST_CASE = MiniTest::Unit::TestCase
RUNNER = MiniTest::Unit
MINITEST_5 = false
else
raise "Unknown gemfile: #{gemfile}"
end
Expand All @@ -50,11 +46,16 @@ def test_responds_to_test
def test_adds_a_test_method
called = false
TEST_CASE.test('some test') { called = true }
case MINITEST_5
when false
TEST_CASE.new(:test_some_test).run(RUNNER.new) {}
when true
case GEMFILE
when 'Gemfile'
TEST_CASE.new(:test_some_test).run {}
when 'Gemfile.unit-test'
# This module does not inherit unit test.
# It has already implemented from test unit v2.3.0.
# Run original test unit just in case.
TEST_CASE.new("test: some test").run(RUNNER.new) {}
else
TEST_CASE.new(:test_some_test).run(RUNNER.new) {}
end
assert called
end
Expand Down

0 comments on commit d839c37

Please sign in to comment.