Skip to content

Commit 9fae5b8

Browse files
committed
improve minitest adapter
1 parent 9a05931 commit 9fae5b8

14 files changed

+244
-43
lines changed

Gemfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ group :development, :test do
66
gem "rvm"
77
gem "bundler"
88
gem "rake"
9-
gem "minitest", "~> 1.7.2"
10-
gem "test-unit", "~> 2.1.1"
9+
gem "minitest", "~> 1.7.2" # built in to ruby distro
1110
end
1211

1312
platforms :jruby do

Gemfile-minitest1

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec :name => "wrong"
4+
5+
group :development, :test do
6+
gem "rvm"
7+
gem "bundler"
8+
gem "rake"
9+
gem "minitest", "~> 5.0"
10+
end
11+
12+
platforms :jruby do
13+
gem "jruby-openssl" # to silence annoying warning
14+
end

Gemfile-minitest1.lock

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
PATH
2+
remote: .
3+
specs:
4+
wrong (0.7.1)
5+
diff-lcs (~> 1.2.5)
6+
predicated (~> 0.2.6)
7+
ruby2ruby (>= 2.0.1)
8+
ruby_parser (>= 3.0.1)
9+
sexp_processor (>= 4.0)
10+
11+
GEM
12+
remote: https://rubygems.org/
13+
specs:
14+
diff-lcs (1.2.5)
15+
minitest (5.4.3)
16+
predicated (0.2.6)
17+
rake (10.3.2)
18+
ruby2ruby (2.1.3)
19+
ruby_parser (~> 3.1)
20+
sexp_processor (~> 4.0)
21+
ruby_parser (3.6.3)
22+
sexp_processor (~> 4.1)
23+
rvm (1.11.3.9)
24+
sexp_processor (4.4.4)
25+
26+
PLATFORMS
27+
ruby
28+
29+
DEPENDENCIES
30+
bundler
31+
jruby-openssl
32+
minitest (~> 5.0)
33+
rake
34+
rvm
35+
wrong!

Gemfile-minitest5

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec :name => "wrong"
4+
5+
group :development, :test do
6+
gem "rvm"
7+
gem "bundler"
8+
gem "rake"
9+
gem "minitest", "~> 5.0"
10+
end
11+
12+
platforms :jruby do
13+
gem "jruby-openssl" # to silence annoying warning
14+
end

Gemfile-minitest5.lock

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
PATH
2+
remote: .
3+
specs:
4+
wrong (0.7.1)
5+
diff-lcs (~> 1.2.5)
6+
predicated (~> 0.2.6)
7+
ruby2ruby (>= 2.0.1)
8+
ruby_parser (>= 3.0.1)
9+
sexp_processor (>= 4.0)
10+
11+
GEM
12+
remote: https://rubygems.org/
13+
specs:
14+
diff-lcs (1.2.5)
15+
minitest (5.4.3)
16+
predicated (0.2.6)
17+
rake (10.3.2)
18+
ruby2ruby (2.1.3)
19+
ruby_parser (~> 3.1)
20+
sexp_processor (~> 4.0)
21+
ruby_parser (3.6.3)
22+
sexp_processor (~> 4.1)
23+
rvm (1.11.3.9)
24+
sexp_processor (4.4.4)
25+
26+
PLATFORMS
27+
ruby
28+
29+
DEPENDENCIES
30+
bundler
31+
jruby-openssl
32+
minitest (~> 5.0)
33+
rake
34+
rvm
35+
wrong!

Gemfile-testunit

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec :name => "wrong"
4+
5+
group :development, :test do
6+
gem "rvm"
7+
gem "bundler"
8+
gem "rake"
9+
gem "test-unit", "~> 3.0"
10+
end
11+
12+
platforms :jruby do
13+
gem "jruby-openssl" # to silence annoying warning
14+
end

Gemfile-testunit.lock

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
PATH
2+
remote: .
3+
specs:
4+
wrong (0.7.1)
5+
diff-lcs (~> 1.2.5)
6+
predicated (~> 0.2.6)
7+
ruby2ruby (>= 2.0.1)
8+
ruby_parser (>= 3.0.1)
9+
sexp_processor (>= 4.0)
10+
11+
GEM
12+
remote: https://rubygems.org/
13+
specs:
14+
diff-lcs (1.2.5)
15+
power_assert (0.2.2)
16+
predicated (0.2.6)
17+
rake (10.3.2)
18+
ruby2ruby (2.1.3)
19+
ruby_parser (~> 3.1)
20+
sexp_processor (~> 4.0)
21+
ruby_parser (3.6.3)
22+
sexp_processor (~> 4.1)
23+
rvm (1.11.3.9)
24+
sexp_processor (4.4.4)
25+
test-unit (3.0.7)
26+
power_assert
27+
28+
PLATFORMS
29+
ruby
30+
31+
DEPENDENCIES
32+
bundler
33+
jruby-openssl
34+
rake
35+
rvm
36+
test-unit (~> 3.0)
37+
wrong!

Rakefile

+22-10
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ Bundler.setup
55
task :default => :test
66

77
def separate
8-
Dir["./test/adapters/*_test.rb"] + [
8+
Dir["./test/adapters/*_test.rb"] +
9+
[
910
"./test/message/test_context_test.rb",
1011
"./test/assert_advanced_test.rb",
11-
]
12+
]
1213
end
1314

1415
def sys cmd
@@ -20,16 +21,23 @@ end
2021

2122
desc 'run all tests (in current ruby)'
2223
task :test do
23-
all_passed = separate.collect do |test_file|
24+
return_values = separate.collect do |test_file|
2425
puts "\n>> Separately running #{test_file} under #{ENV['RUBY_VERSION']}..."
25-
Bundler.with_clean_env do
26-
sys("ruby #{test_file}")
27-
end
28-
end.uniq == [true]
29-
if !all_passed
30-
at_exit { exit false }
26+
sys("ruby #{test_file}")
3127
end
3228

29+
return_values += [
30+
{"./test/adapters/minitest_test.rb" => "./Gemfile-minitest1"},
31+
{"./test/adapters/minitest_test.rb" => "./Gemfile-minitest5"},
32+
{"./test/adapters/test_unit_test.rb" => "./Gemfile-testunit"},
33+
].collect do |pair|
34+
test_file = pair.keys.first
35+
gemfile = pair.values.first
36+
puts "\n>> Separately running #{test_file} under #{gemfile} and #{ENV['RUBY_VERSION']}..."
37+
sys("BUNDLE_GEMFILE=#{gemfile} bundle exec ruby #{test_file}")
38+
end
39+
all_passed = return_values.uniq == [true]
40+
at_exit { exit false } unless all_passed
3341
Rake::Task[:test_most].invoke
3442
end
3543

@@ -69,13 +77,15 @@ namespace :rvm do
6977
'1.9.1-p378', # we can't use p429 or p431, see http://bugs.ruby-lang.org/issues/show/3584 and http://bugs.ruby-lang.org/issues/2404
7078
'1.9.2',
7179
'1.9.3',
80+
'2.0.0',
81+
'2.1.4',
7282
'jruby']
7383
@rubies_str = @rubies.join(', ')
7484

7585
def rvm
7686
@rvm_path ||= begin
7787
rvm = `which rvm`.strip
78-
raise 'rvm not available; go to http://rvm.beginrescueend.com' unless rvm
88+
raise 'rvm not available; go to http://rvm.io' unless rvm
7989
rvm
8090
end
8191
end
@@ -115,6 +125,8 @@ namespace :rvm do
115125
task :test do
116126
rvm_run "bundle exec rake test"
117127
rvm_run "ruby ./test/suite.rb"
128+
rvm_run ""
129+
118130
# todo: fail if any test failed
119131
# todo: figure out a way to run suite with jruby --1.9 (it's harder than you'd think)
120132
end

lib/wrong/adapters/minitest.rb

+47-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,61 @@
11
require "wrong/assert"
22
require "wrong/helpers"
33

4-
class MiniTest::Unit::TestCase
4+
module Wrong::MiniTestAdapter
55
include Wrong::Assert
66
include Wrong::Helpers
77

8-
def failure_class
9-
MiniTest::Assertion
8+
def self.minitest_version
9+
if defined?(MiniTest::VERSION)
10+
MiniTest::VERSION
11+
else
12+
MiniTest::Unit::VERSION
13+
end
14+
end
15+
16+
def self.minitest_base_class
17+
if minitest_version >= "5.0.0"
18+
MiniTest::Test
19+
else
20+
MiniTest::Unit::TestCase
21+
end
22+
end
23+
24+
def self.minitest_autorun
25+
require 'minitest/autorun'
26+
if minitest_version >= "5.0.0"
27+
MiniTest.autorun
28+
else
29+
MiniTest::Unit.autorun
30+
end
31+
end
32+
33+
def minitest_assertion_count
34+
if Wrong::MiniTestAdapter.minitest_version >= "5.0.0"
35+
self.assertions
36+
else
37+
self._assertions
38+
end
1039
end
1140

12-
if MiniTest::VERSION >= "5.0.6"
13-
alias_method :_assertions, :assertions
14-
alias_method :"_assertions=", :"assertions="
41+
def minitest_increment_assertions
42+
if Wrong::MiniTestAdapter.minitest_version >= "5.0.0"
43+
self.assertions += 1
44+
else
45+
self._assertions +=1
46+
end
47+
end
48+
49+
def failure_class
50+
MiniTest::Assertion
1551
end
1652

1753
def aver(valence, explanation = nil, depth = 0)
18-
self._assertions += 1 # increment minitest's assert count
54+
minitest_increment_assertions
1955
super(valence, explanation, depth + 1) # apparently this passes along the default block
2056
end
21-
57+
58+
$stderr.puts "Loading Wrong adapter for MiniTest #{minitest_version}"
2259
end
60+
61+
Wrong::MiniTestAdapter.minitest_base_class.include Wrong::MiniTestAdapter

lib/wrong/adapters/test_unit.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def wrong_adapter_failure(why)
1313
end
1414

1515
if Test::Unit.const_defined? :TEST_UNIT_IMPLEMENTATION
16-
wrong_adapter_failure "You are using MiniTest's compatibility layer, not the real Test::Unit."
16+
$stderr.puts "You are using MiniTest's compatibility layer, not the real Test::Unit."
1717
end
1818

1919
begin
@@ -24,6 +24,7 @@ def wrong_adapter_failure(why)
2424
require 'test/unit/failure'
2525
Test::Unit::TestResultFailureSupport # this class is only in 2.x, to catch mixups between 1.8's lib and gem versions
2626
rescue Exception => e
27+
p e
2728
wrong_adapter_failure "You are using an outdated version of Test::Unit."
2829
end
2930

lib/wrong/close_to.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'date'
2+
13
module Wrong
24
module CloseTo
35
def close_to?(other, tolerance = 0.001)
@@ -8,7 +10,7 @@ def close_to?(other, tolerance = 0.001)
810
end
911
end
1012
end
11-
Numeric.send :include, CloseTo
12-
Date.send :include, CloseTo
13-
Time.send :include, CloseTo
13+
::Numeric.send :include, CloseTo
14+
::Date.send :include, CloseTo
15+
::Time.send :include, CloseTo
1416
end

0 commit comments

Comments
 (0)