Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 17bc421

Browse files
committed
Branched miniunit into minitest w/o test/unit compatibility
[git-p4: depot-paths = "//src/minitest/dev/": change = 4312]
0 parents  commit 17bc421

12 files changed

Lines changed: 1929 additions & 0 deletions

File tree

.autotest

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- ruby -*-
2+
3+
Autotest.add_hook :initialize do |at|
4+
at.extra_class_map["MiniSpec"] = "test/test_mini_spec.rb"
5+
at.extra_class_map["TestMiniTestTestCase"] = "test/test_mini_test.rb"
6+
7+
at.add_exception 'coverage.info'
8+
at.add_exception 'coverage'
9+
end
10+
11+
require 'autotest/rcov'
12+
Autotest::RCov.command = 'rcov_info'
13+

History.txt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
=== 1.2.1 / 2008-06-10
2+
3+
* 7 minor enhancements:
4+
5+
* Added deprecations everywhere in test/unit.
6+
* Added test_order to TestCase. :random on mini, :sorted on test/unit (for now).
7+
* Big cleanup in test/unit for rails. Thanks Jeremy Kemper!
8+
* Minor readability cleanup.
9+
* Pushed setup/run/teardown down to testcase allowing specialized testcases.
10+
* Removed pp. Tests run 2x faster. :/
11+
* Renamed deprecation methods and moved to test/unit/deprecate.rb.
12+
13+
=== 1.2.0 / 2008-06-09
14+
15+
* 2 major enhancements:
16+
17+
* Added Mini::Spec.
18+
* Added Mini::Mock. Thanks Steven Baker!!
19+
20+
* 23 minor enhancements:
21+
22+
* Added bin/use_miniunit to make it easy to test out miniunit.
23+
* Added -n filtering, thanks to Phil Hagelberg!
24+
* Added args argument to #run, takes ARGV from at_exit.
25+
* Added test name output if $DEBUG.
26+
* Added a refute (was deny) for every assert.
27+
* Added capture_io and a bunch of nice assertions from zentest.
28+
* Added deprecation mechanism for assert_no/not methods to test/unit/assertions.
29+
* Added pp output when available.
30+
* Added tests for all assertions. Pretty much maxed out coverage.
31+
* Added tests to verify consistency and good naming.
32+
* Aliased and deprecated all ugly assertions.
33+
* Cleaned out test/unit. Moved autorun there.
34+
* Code cleanup to make extensions easier. Thanks Chad!
35+
* Got spec args reversed in all but a couple assertions. Much more readable.
36+
* Improved error messages across the board. Adds your message to the default.
37+
* Moved into Mini namespace, renamed to Mini::Test and Mini::Spec.
38+
* Pulled the assertions into their own module...
39+
* Removed as much code as I could while still maintaining full functionality.
40+
* Moved filter_backtrace into MiniTest.
41+
* Removed MiniTest::Unit::run. Unnecessary.
42+
* Removed location_of_failure. Unnecessary.
43+
* Rewrote test/unit's filter_backtrace. Flog from 37.0 to 18.1
44+
* Removed assert_send. Google says it is never used.
45+
* Renamed MiniTest::Unit.autotest to #run.
46+
* Renamed deny to refute.
47+
* Rewrote some ugly/confusing default assertion messages.
48+
* assert_in_delta now defaults to 0.001 precision. Makes specs prettier.
49+
50+
* 9 bug fixes:
51+
52+
* Fixed assert_raises to raise outside of the inner-begin/rescue.
53+
* Fixed for ruby 1.9 and rubinius.
54+
* No longer exits 0 if exception in code PRE-test run causes early exit.
55+
* Removed implementors method list from mini/test.rb - too stale.
56+
* assert_nothing_raised takes a class as an arg. wtf? STUPID
57+
* ".EF" output is now unbuffered.
58+
* Bunch of changes to get working with rails... UGH.
59+
* Added stupid hacks to deal with rails not requiring their dependencies.
60+
* Now bitch loudly if someone defines one of my classes instead of requiring.
61+
* Fixed infect method to work better on 1.9.
62+
* Fixed all shadowed variable warnings in 1.9.
63+
64+
=== 1.1.0 / 2007-11-08
65+
66+
* 4 major enhancements:
67+
68+
* Finished writing all missing assertions.
69+
* Output matches original test/unit.
70+
* Documented every method needed by language implementor.
71+
* Fully switched over to self-testing setup.
72+
73+
* 2 minor enhancements:
74+
75+
* Added deny (assert ! test), our favorite extension to test/unit.
76+
* Added .autotest and fairly complete unit tests. (thanks Chad for help here)
77+
78+
=== 1.0.0 / 2006-10-30
79+
80+
* 1 major enhancement
81+
82+
* Birthday!
83+

Manifest.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.autotest
2+
History.txt
3+
Manifest.txt
4+
README.txt
5+
Rakefile
6+
bin/use_miniunit
7+
lib/mini/mock.rb
8+
lib/mini/spec.rb
9+
lib/mini/test.rb
10+
lib/test/unit.rb
11+
lib/test/unit/assertions.rb
12+
lib/test/unit/deprecate.rb
13+
lib/test/unit/error.rb
14+
lib/test/unit/testcase.rb
15+
test/test_mini_mock.rb
16+
test/test_mini_spec.rb
17+
test/test_mini_test.rb

README.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
= mini/{test,spec,mock}
2+
3+
* http://rubyforge.org/projects/bfts
4+
5+
== DESCRIPTION:
6+
7+
mini/test is a completely minimial drop-in replacement for ruby's
8+
test/unit. This is meant to be clean and easy to use both as a regular
9+
test writer and for language implementors that need a minimal set of
10+
methods to bootstrap a working unit test suite.
11+
12+
mini/spec is a functionally complete spec engine.
13+
14+
mini/mock, by Steven Baker, is a beautifully tiny mock object framework.
15+
16+
== FEATURES/PROBLEMS:
17+
18+
* Contains mini/test - a simple and clean test system (301 lines!).
19+
* Contains mini/spec - a simple and clean spec system (52 lines!).
20+
* Contains mini/mock - a simple and clean mock system (35 lines!).
21+
* Fully test/unit compatible assertions.
22+
* Allows test/unit to be required, firing up an autorunner.
23+
* Incredibly small and fast runner, but no bells and whistles.
24+
* Incompatible at the runner level.
25+
26+
== REQUIREMENTS:
27+
28+
+ Ruby 1.8, maybe even 1.6 or lower. No magic is involved.
29+
30+
== INSTALL:
31+
32+
+ sudo gem install miniunit
33+
34+
== LICENSE:
35+
36+
(The MIT License)
37+
38+
Copyright (c) Ryan Davis, Seattle.rb
39+
40+
Permission is hereby granted, free of charge, to any person obtaining
41+
a copy of this software and associated documentation files (the
42+
'Software'), to deal in the Software without restriction, including
43+
without limitation the rights to use, copy, modify, merge, publish,
44+
distribute, sublicense, and/or sell copies of the Software, and to
45+
permit persons to whom the Software is furnished to do so, subject to
46+
the following conditions:
47+
48+
The above copyright notice and this permission notice shall be
49+
included in all copies or substantial portions of the Software.
50+
51+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
52+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
53+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
54+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
55+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
56+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
57+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Rakefile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# -*- ruby -*-
2+
3+
$TESTING_MINIUNIT = true
4+
5+
require 'rubygems'
6+
require 'hoe'
7+
require './lib/mini/test.rb'
8+
9+
Hoe.new('miniunit', Mini::Test::VERSION) do |miniunit|
10+
miniunit.rubyforge_name = "bfts"
11+
12+
miniunit.developer('Ryan Davis', '[email protected]')
13+
end
14+
15+
begin
16+
require 'rcov/rcovtask'
17+
Rcov::RcovTask.new do |t|
18+
t.verbose = true
19+
t.rcov_opts << "--include-file lib/test"
20+
t.rcov_opts << "--no-color"
21+
end
22+
23+
task :rcov_info do
24+
pattern = ENV['PATTERN'] || "test/test_*.rb"
25+
ruby "-Ilib -S rcov --text-report --include-file lib/test --save coverage.info #{pattern}"
26+
end
27+
28+
task :rcov_overlay do
29+
rcov, eol = Marshal.load(File.read("coverage.info")).last[ENV["FILE"]], 1
30+
puts rcov[:lines].zip(rcov[:coverage]).map { |line, coverage|
31+
bol, eol = eol, eol + line.length
32+
[bol, eol, "#ffcccc"] unless coverage
33+
}.compact.inspect
34+
end
35+
rescue LoadError
36+
# skip
37+
end
38+
39+
def loc dir
40+
system "find #{dir} -name \\*.rb | xargs wc -l | tail -1"
41+
end
42+
43+
desc "stupid line count"
44+
task :dickwag do
45+
puts
46+
puts "miniunit"
47+
puts
48+
print " lib loc"; loc "lib"
49+
print " test loc"; loc "test"
50+
print " totl loc"; loc "lib test"
51+
print " flog = "; system "flog -s lib"
52+
53+
puts
54+
puts "test/unit"
55+
puts
56+
Dir.chdir File.expand_path("~/Work/svn/ruby/ruby_1_8") do
57+
print " lib loc"; loc "lib/test"
58+
print " test loc"; loc "test/testunit"
59+
print " totl loc"; loc "lib/test test/testunit"
60+
print " flog = "; system "flog -s lib/test"
61+
end
62+
puts
63+
end
64+
65+
# vim: syntax=Ruby

bin/use_miniunit

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'rbconfig'
4+
5+
use_miniunit = ARGV.shift
6+
sitelib = Config::CONFIG["sitelibdir"]
7+
projdir = File.dirname(File.dirname(File.expand_path(__FILE__)))
8+
minidir = File.join(projdir, "lib")
9+
10+
case use_miniunit
11+
when /^y/ then
12+
File.symlink File.join(minidir, "mini"), File.join(sitelib, "mini")
13+
File.symlink File.join(minidir, "test"), File.join(sitelib, "test")
14+
puts "Added links to #{sitelib}"
15+
when /^n/ then
16+
File.unlink File.join(sitelib, "mini")
17+
File.unlink File.join(sitelib, "test")
18+
puts "Removed links from #{sitelib}"
19+
else
20+
pgm = File.basename __FILE__
21+
puts "usage: #{pgm} (yes|no)"
22+
exit 1
23+
end

lib/mini/mock.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class MockExpectationError < StandardError; end
2+
3+
require 'mini/test'
4+
5+
class Mini::Mock
6+
def initialize
7+
@expected_calls = {}
8+
@actual_calls = Hash.new {|h,k| h[k] = [] }
9+
end
10+
11+
def expect(name, retval, args=[])
12+
n, r, a = name, retval, args # for the closure below
13+
@expected_calls[name] = { :retval => retval, :args => args }
14+
self.class.__send__(:define_method, name) { |*x|
15+
raise ArgumentError unless @expected_calls[n][:args].size == x.size
16+
@actual_calls[n] << { :retval => r, :args => x }
17+
retval
18+
}
19+
self
20+
end
21+
22+
def verify
23+
@expected_calls.each_key do |name|
24+
expected = @expected_calls[name]
25+
msg = "expected #{name}, #{expected.inspect}"
26+
raise MockExpectationError, msg unless
27+
@actual_calls.has_key? name and @actual_calls[name].include?(expected)
28+
end
29+
true
30+
end
31+
end

lib/mini/spec.rb

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/ruby -w
2+
3+
require 'mini/test'
4+
5+
class Module
6+
def infect_with_assertions pos_prefix, neg_prefix, skip_re, map = {}
7+
Mini::Assertions.public_instance_methods(false).each do |meth|
8+
meth = meth.to_s
9+
10+
new_name = case meth
11+
when /^assert/ then
12+
meth.sub(/^assert/, pos_prefix.to_s)
13+
when /^refute/ then
14+
meth.sub(/^refute/, neg_prefix.to_s)
15+
end
16+
next unless new_name
17+
next if new_name =~ skip_re
18+
19+
regexp, replacement = map.find { |re, _| new_name =~ re }
20+
new_name.sub! regexp, replacement if replacement
21+
22+
# warn "%-22p -> %p %p" % [meth, new_name, regexp]
23+
self.class_eval <<-EOM
24+
def #{new_name} *args, &block
25+
return Mini::Spec.current.#{meth}(*args, &self) if Proc === self
26+
return Mini::Spec.current.#{meth}(args.first, self) if args.size == 1
27+
return Mini::Spec.current.#{meth}(self, *args)
28+
end
29+
EOM
30+
end
31+
end
32+
end
33+
34+
Object.infect_with_assertions(:must, :wont,
35+
/^(must|wont)$|wont_(throw)|
36+
must_(block|not?_|nothing|raise$)/x,
37+
/(must_throw)s/ => '\1',
38+
/(?!not)_same/ => '_be_same_as',
39+
/_in_/ => '_be_within_',
40+
/_operator/ => '_be',
41+
/_includes/ => '_include',
42+
/(must|wont)_(.*_of|nil|empty)/ => '\1_be_\2',
43+
/must_raises/ => 'must_raise')
44+
45+
class Object
46+
alias :must_be_close_to :must_be_within_delta
47+
alias :wont_be_close_to :wont_be_within_delta
48+
end
49+
50+
module Kernel
51+
def describe desc, &block
52+
cls = Class.new(Mini::Spec)
53+
Object.const_set desc.to_s.split(/\W+/).map { |s| s.capitalize }.join, cls
54+
55+
cls.class_eval(&block)
56+
end
57+
end
58+
59+
class Mini::Spec < Mini::Test::TestCase
60+
def self.current
61+
@@current_spec
62+
end
63+
64+
def initialize name
65+
super
66+
@@current_spec = self
67+
end
68+
69+
def self.before(type = :each, &block)
70+
raise "unsupported before type: #{type}" unless type == :each
71+
define_method :setup, &block
72+
end
73+
74+
def self.after(type = :each, &block)
75+
raise "unsupported after type: #{type}" unless type == :each
76+
define_method :teardown, &block
77+
end
78+
79+
def self.it desc, &block
80+
define_method "test_#{desc.gsub(/\W+/, '_').downcase}", &block
81+
end
82+
end

0 commit comments

Comments
 (0)