mattly-minitest 1.4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +15 -0
- data/History.txt +175 -0
- data/Manifest.txt +13 -0
- data/README.txt +60 -0
- data/Rakefile +42 -0
- data/design_rationale.rb +52 -0
- data/lib/minitest/autorun.rb +5 -0
- data/lib/minitest/mock.rb +31 -0
- data/lib/minitest/spec.rb +125 -0
- data/lib/minitest/unit.rb +530 -0
- data/test/test_mini_mock.rb +77 -0
- data/test/test_mini_spec.rb +202 -0
- data/test/test_mini_test.rb +980 -0
- metadata +69 -0
data/.autotest
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
Autotest.add_hook :initialize do |at|
|
6
|
+
at.extra_class_map["MiniSpec"] = "test/test_mini_spec.rb"
|
7
|
+
at.extra_class_map["TestMiniTestTestCase"] = "test/test_mini_test.rb"
|
8
|
+
|
9
|
+
at.add_exception 'coverage.info'
|
10
|
+
at.add_exception 'coverage'
|
11
|
+
end
|
12
|
+
|
13
|
+
# require 'autotest/rcov'
|
14
|
+
# Autotest::RCov.command = 'rcov_info'
|
15
|
+
|
data/History.txt
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
=== 1.4.2 / 2009-06-25
|
2
|
+
|
3
|
+
* 1 bug fix:
|
4
|
+
|
5
|
+
* Fixed info handler for systems that don't have siginfo.
|
6
|
+
|
7
|
+
=== 1.4.1 / 2009-06-23
|
8
|
+
|
9
|
+
* 1 major enhancement:
|
10
|
+
|
11
|
+
* Handle ^C and other fatal exceptions by failing
|
12
|
+
|
13
|
+
* 1 minor enhancement:
|
14
|
+
|
15
|
+
* Added something to catch mixed use of test/unit and minitest if $DEBUG
|
16
|
+
|
17
|
+
* 1 bug fix:
|
18
|
+
|
19
|
+
* Added SIGINFO handler for finding slow tests without verbose
|
20
|
+
|
21
|
+
=== 1.4.0 / 2009-06-18
|
22
|
+
|
23
|
+
* 5 minor enhancement:
|
24
|
+
|
25
|
+
* Added clarification doco.
|
26
|
+
* Added specs and mocks to autorun.
|
27
|
+
* Changed spec test class creation to be non-destructive.
|
28
|
+
* Updated rakefile for new hoe capabilities.
|
29
|
+
* describes are nestable (via subclass). before/after/def inherits, specs don't.
|
30
|
+
|
31
|
+
* 3 bug fixes:
|
32
|
+
|
33
|
+
* Fixed location on must/wont.
|
34
|
+
* Switched to __name__ to avoid common ivar name.
|
35
|
+
* Fixed indentation in test file (1.9).
|
36
|
+
|
37
|
+
=== 1.3.1 / 2009-01-20
|
38
|
+
|
39
|
+
* 1 minor enhancement:
|
40
|
+
|
41
|
+
* Added miniunit/autorun.rb as replacement for test/unit.rb's autorun.
|
42
|
+
|
43
|
+
* 16 bug fixes:
|
44
|
+
|
45
|
+
* 1.9 test fixes.
|
46
|
+
* Bug fixes from nobu and akira for really odd scenarios. They run ruby funny.
|
47
|
+
* Fixed (assert|refute)_match's argument order.
|
48
|
+
* Fixed LocalJumpError in autorun if exception thrown before at_exit.
|
49
|
+
* Fixed assert_in_delta (should be >=, not >).
|
50
|
+
* Fixed assert_raises to match Modules.
|
51
|
+
* Fixed capture_io to not dup IOs.
|
52
|
+
* Fixed indentation of capture_io for ruby 1.9 warning.
|
53
|
+
* Fixed location to deal better with custom assertions and load paths. (Yuki)
|
54
|
+
* Fixed order of (must|wont)_include in MiniTest::Spec.
|
55
|
+
* Fixed skip's backtrace.
|
56
|
+
* Got arg order wrong in *_match in tests, message wrong as a result.
|
57
|
+
* Made describe private. For some reason I thought that an attribute of Kernel.
|
58
|
+
* Removed disable_autorun method, added autorun.rb instead.
|
59
|
+
* assert_match escapes if passed string for pattern.
|
60
|
+
* instance_of? is different from ===, use instance_of.
|
61
|
+
|
62
|
+
=== 1.3.0 / 2008-10-09
|
63
|
+
|
64
|
+
* 2 major enhancements:
|
65
|
+
|
66
|
+
* renamed to minitest and pulled out test/unit compatibility.
|
67
|
+
* mini/test.rb is now minitest/unit.rb, everything else maps directly.
|
68
|
+
|
69
|
+
* 12 minor enhancements:
|
70
|
+
|
71
|
+
* assert_match now checks that act can call =~ and converts exp to a
|
72
|
+
regexp only if needed.
|
73
|
+
* Added assert_send... seems useless to me tho.
|
74
|
+
* message now forces to string... ruby-core likes to pass classes and arrays :(
|
75
|
+
* Added -v handling and switched to @verbose from $DEBUG.
|
76
|
+
* Verbose output now includes test class name and adds a sortable running time!
|
77
|
+
* Switched message generation into procs for message deferment.
|
78
|
+
* Added skip and renamed fail to flunk.
|
79
|
+
* Improved output failure messages for assert_instance_of, assert_kind_of
|
80
|
+
* Improved output for assert_respond_to, assert_same.
|
81
|
+
* at_exit now exits false instead of errors+failures.
|
82
|
+
* Made the tests happier and more readable imhfo.
|
83
|
+
* Switched index(s) == 0 to rindex(s, 0) on nobu's suggestion. Faster.
|
84
|
+
|
85
|
+
* 5 bug fixes:
|
86
|
+
|
87
|
+
* 1.9: Added encoding normalization in mu_pp.
|
88
|
+
* 1.9: Fixed backtrace filtering (BTs are expanded now)
|
89
|
+
* Added back exception_details to assert_raises. DOH.
|
90
|
+
* Fixed shadowed variable in mock.rb
|
91
|
+
* Fixed stupid muscle memory message bug in assert_send.
|
92
|
+
|
93
|
+
=== 1.2.1 / 2008-06-10
|
94
|
+
|
95
|
+
* 7 minor enhancements:
|
96
|
+
|
97
|
+
* Added deprecations everywhere in test/unit.
|
98
|
+
* Added test_order to TestCase. :random on mini, :sorted on test/unit (for now).
|
99
|
+
* Big cleanup in test/unit for rails. Thanks Jeremy Kemper!
|
100
|
+
* Minor readability cleanup.
|
101
|
+
* Pushed setup/run/teardown down to testcase allowing specialized testcases.
|
102
|
+
* Removed pp. Tests run 2x faster. :/
|
103
|
+
* Renamed deprecation methods and moved to test/unit/deprecate.rb.
|
104
|
+
|
105
|
+
=== 1.2.0 / 2008-06-09
|
106
|
+
|
107
|
+
* 2 major enhancements:
|
108
|
+
|
109
|
+
* Added Mini::Spec.
|
110
|
+
* Added Mini::Mock. Thanks Steven Baker!!
|
111
|
+
|
112
|
+
* 23 minor enhancements:
|
113
|
+
|
114
|
+
* Added bin/use_miniunit to make it easy to test out miniunit.
|
115
|
+
* Added -n filtering, thanks to Phil Hagelberg!
|
116
|
+
* Added args argument to #run, takes ARGV from at_exit.
|
117
|
+
* Added test name output if $DEBUG.
|
118
|
+
* Added a refute (was deny) for every assert.
|
119
|
+
* Added capture_io and a bunch of nice assertions from zentest.
|
120
|
+
* Added deprecation mechanism for assert_no/not methods to test/unit/assertions.
|
121
|
+
* Added pp output when available.
|
122
|
+
* Added tests for all assertions. Pretty much maxed out coverage.
|
123
|
+
* Added tests to verify consistency and good naming.
|
124
|
+
* Aliased and deprecated all ugly assertions.
|
125
|
+
* Cleaned out test/unit. Moved autorun there.
|
126
|
+
* Code cleanup to make extensions easier. Thanks Chad!
|
127
|
+
* Got spec args reversed in all but a couple assertions. Much more readable.
|
128
|
+
* Improved error messages across the board. Adds your message to the default.
|
129
|
+
* Moved into Mini namespace, renamed to Mini::Test and Mini::Spec.
|
130
|
+
* Pulled the assertions into their own module...
|
131
|
+
* Removed as much code as I could while still maintaining full functionality.
|
132
|
+
* Moved filter_backtrace into MiniTest.
|
133
|
+
* Removed MiniTest::Unit::run. Unnecessary.
|
134
|
+
* Removed location_of_failure. Unnecessary.
|
135
|
+
* Rewrote test/unit's filter_backtrace. Flog from 37.0 to 18.1
|
136
|
+
* Removed assert_send. Google says it is never used.
|
137
|
+
* Renamed MiniTest::Unit.autotest to #run.
|
138
|
+
* Renamed deny to refute.
|
139
|
+
* Rewrote some ugly/confusing default assertion messages.
|
140
|
+
* assert_in_delta now defaults to 0.001 precision. Makes specs prettier.
|
141
|
+
|
142
|
+
* 9 bug fixes:
|
143
|
+
|
144
|
+
* Fixed assert_raises to raise outside of the inner-begin/rescue.
|
145
|
+
* Fixed for ruby 1.9 and rubinius.
|
146
|
+
* No longer exits 0 if exception in code PRE-test run causes early exit.
|
147
|
+
* Removed implementors method list from mini/test.rb - too stale.
|
148
|
+
* assert_nothing_raised takes a class as an arg. wtf? STUPID
|
149
|
+
* ".EF" output is now unbuffered.
|
150
|
+
* Bunch of changes to get working with rails... UGH.
|
151
|
+
* Added stupid hacks to deal with rails not requiring their dependencies.
|
152
|
+
* Now bitch loudly if someone defines one of my classes instead of requiring.
|
153
|
+
* Fixed infect method to work better on 1.9.
|
154
|
+
* Fixed all shadowed variable warnings in 1.9.
|
155
|
+
|
156
|
+
=== 1.1.0 / 2007-11-08
|
157
|
+
|
158
|
+
* 4 major enhancements:
|
159
|
+
|
160
|
+
* Finished writing all missing assertions.
|
161
|
+
* Output matches original test/unit.
|
162
|
+
* Documented every method needed by language implementor.
|
163
|
+
* Fully switched over to self-testing setup.
|
164
|
+
|
165
|
+
* 2 minor enhancements:
|
166
|
+
|
167
|
+
* Added deny (assert ! test), our favorite extension to test/unit.
|
168
|
+
* Added .autotest and fairly complete unit tests. (thanks Chad for help here)
|
169
|
+
|
170
|
+
=== 1.0.0 / 2006-10-30
|
171
|
+
|
172
|
+
* 1 major enhancement
|
173
|
+
|
174
|
+
* Birthday!
|
175
|
+
|
data/Manifest.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
.autotest
|
2
|
+
History.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
design_rationale.rb
|
7
|
+
lib/minitest/autorun.rb
|
8
|
+
lib/minitest/mock.rb
|
9
|
+
lib/minitest/spec.rb
|
10
|
+
lib/minitest/unit.rb
|
11
|
+
test/test_mini_mock.rb
|
12
|
+
test/test_mini_spec.rb
|
13
|
+
test/test_mini_test.rb
|
data/README.txt
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
= minitest/{unit,spec,mock}
|
2
|
+
|
3
|
+
* http://rubyforge.org/projects/bfts
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
minitest/unit is a small and fast replacement for ruby's huge and slow
|
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
|
+
(This package was called miniunit once upon a time)
|
17
|
+
|
18
|
+
== FEATURES/PROBLEMS:
|
19
|
+
|
20
|
+
* Contains minitest/unit - a simple and clean test system (301 lines!).
|
21
|
+
* Contains minitest/spec - a simple and clean spec system (52 lines!).
|
22
|
+
* Contains minitest/mock - a simple and clean mock system (35 lines!).
|
23
|
+
* Incredibly small and fast runner, but no bells and whistles.
|
24
|
+
|
25
|
+
== RATIONALE:
|
26
|
+
|
27
|
+
See design_rationale.rb to see how specs and tests work in minitest.
|
28
|
+
|
29
|
+
== REQUIREMENTS:
|
30
|
+
|
31
|
+
+ Ruby 1.8, maybe even 1.6 or lower. No magic is involved.
|
32
|
+
|
33
|
+
== INSTALL:
|
34
|
+
|
35
|
+
+ sudo gem install minitest
|
36
|
+
|
37
|
+
== LICENSE:
|
38
|
+
|
39
|
+
(The MIT License)
|
40
|
+
|
41
|
+
Copyright (c) Ryan Davis, Seattle.rb
|
42
|
+
|
43
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
44
|
+
a copy of this software and associated documentation files (the
|
45
|
+
'Software'), to deal in the Software without restriction, including
|
46
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
47
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
48
|
+
permit persons to whom the Software is furnished to do so, subject to
|
49
|
+
the following conditions:
|
50
|
+
|
51
|
+
The above copyright notice and this permission notice shall be
|
52
|
+
included in all copies or substantial portions of the Software.
|
53
|
+
|
54
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
55
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
56
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
57
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
58
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
59
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
60
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
$TESTING_MINIUNIT = true
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'hoe'
|
7
|
+
|
8
|
+
Hoe.plugin :seattlerb
|
9
|
+
|
10
|
+
Hoe.spec 'minitest' do
|
11
|
+
developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
|
12
|
+
|
13
|
+
self.rubyforge_name = "bfts"
|
14
|
+
end
|
15
|
+
|
16
|
+
def loc dir
|
17
|
+
system "find #{dir} -name \\*.rb | xargs wc -l | tail -1"
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "stupid line count"
|
21
|
+
task :dickwag do
|
22
|
+
puts
|
23
|
+
puts "miniunit"
|
24
|
+
puts
|
25
|
+
print " lib loc"; loc "lib"
|
26
|
+
print " test loc"; loc "test"
|
27
|
+
print " totl loc"; loc "lib test"
|
28
|
+
print " flog = "; system "flog -s lib"
|
29
|
+
|
30
|
+
puts
|
31
|
+
puts "test/unit"
|
32
|
+
puts
|
33
|
+
Dir.chdir File.expand_path("~/Work/svn/ruby/ruby_1_8") do
|
34
|
+
print " lib loc"; loc "lib/test"
|
35
|
+
print " test loc"; loc "test/testunit"
|
36
|
+
print " totl loc"; loc "lib/test test/testunit"
|
37
|
+
print " flog = "; system "flog -s lib/test"
|
38
|
+
end
|
39
|
+
puts
|
40
|
+
end
|
41
|
+
|
42
|
+
# vim: syntax=Ruby
|
data/design_rationale.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Specs: # Equivalent Unit Tests:
|
2
|
+
###############################################################################
|
3
|
+
describe Thingy do # class TestThingy < MiniTest::Unit::TestCase
|
4
|
+
before do # def setup
|
5
|
+
do_some_setup # super
|
6
|
+
end # do_some_setup
|
7
|
+
# end
|
8
|
+
it "should do the first thing" do #
|
9
|
+
1.must_equal 1 # def test_first_thing
|
10
|
+
end # assert_equal 1, 1
|
11
|
+
# end
|
12
|
+
describe SubThingy do # end
|
13
|
+
before do #
|
14
|
+
do_more_setup # class TestSubThingy < TestThingy
|
15
|
+
end # def setup
|
16
|
+
# super
|
17
|
+
it "should do the second thing" do # do_more_setup
|
18
|
+
2.must_equal 2 # end
|
19
|
+
end #
|
20
|
+
end # def test_second_thing
|
21
|
+
end # assert_equal 2, 2
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
###############################################################################
|
25
|
+
# runs 2 specs # runs 3 tests
|
26
|
+
###############################################################################
|
27
|
+
# The specs generate:
|
28
|
+
|
29
|
+
class ThingySpec < MiniTest::Spec
|
30
|
+
def setup
|
31
|
+
super
|
32
|
+
do_some_setup
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_do_the_first_thing
|
36
|
+
assert_equal 1, 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class SubThingySpec < ThingySpec
|
41
|
+
def setup
|
42
|
+
super
|
43
|
+
do_more_setup
|
44
|
+
end
|
45
|
+
|
46
|
+
# because only setup/teardown is inherited, not specs
|
47
|
+
remove_method :test_should_do_the_first_thing
|
48
|
+
|
49
|
+
def test_should_do_the_second_thing
|
50
|
+
assert_equal 2, 2
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class MockExpectationError < StandardError; end
|
2
|
+
|
3
|
+
module MiniTest
|
4
|
+
class Mock
|
5
|
+
def initialize
|
6
|
+
@expected_calls = {}
|
7
|
+
@actual_calls = Hash.new {|h,k| h[k] = [] }
|
8
|
+
end
|
9
|
+
|
10
|
+
def expect(name, retval, args=[])
|
11
|
+
n, r, a = name, retval, args # for the closure below
|
12
|
+
@expected_calls[name] = { :retval => retval, :args => args }
|
13
|
+
self.class.__send__(:define_method, name) { |*x|
|
14
|
+
raise ArgumentError unless @expected_calls[n][:args].size == x.size
|
15
|
+
@actual_calls[n] << { :retval => r, :args => x }
|
16
|
+
retval
|
17
|
+
}
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def verify
|
22
|
+
@expected_calls.each_key do |name|
|
23
|
+
expected = @expected_calls[name]
|
24
|
+
msg = "expected #{name}, #{expected.inspect}"
|
25
|
+
raise MockExpectationError, msg unless
|
26
|
+
@actual_calls.has_key? name and @actual_calls[name].include?(expected)
|
27
|
+
end
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
require 'minitest/unit'
|
4
|
+
|
5
|
+
class Module
|
6
|
+
def infect_with_assertions pos_prefix, neg_prefix, skip_re, map = {}
|
7
|
+
MiniTest::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 MiniTest::Spec.current.#{meth}(*args, &self) if Proc === self
|
26
|
+
return MiniTest::Spec.current.#{meth}(args.first, self) if args.size == 1
|
27
|
+
return MiniTest::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
|
+
stack = MiniTest::Spec.describe_stack
|
53
|
+
prev = MiniTest::Spec.description_stack.join(' ')
|
54
|
+
name = "#{prev} #{desc}".split(/\W+/).map { |s| s.capitalize }.join + "Spec"
|
55
|
+
cls = Object.class_eval "class #{name} < #{stack.last}; end; #{name}"
|
56
|
+
|
57
|
+
cls.nuke_test_methods!
|
58
|
+
|
59
|
+
stack.push cls
|
60
|
+
MiniTest::Spec.description_stack.push desc
|
61
|
+
cls.class_eval(&block)
|
62
|
+
MiniTest::Spec.description_stack.pop
|
63
|
+
stack.pop
|
64
|
+
end
|
65
|
+
private :describe
|
66
|
+
end
|
67
|
+
|
68
|
+
class MiniTest::Spec < MiniTest::Unit::TestCase
|
69
|
+
@@describe_stack = [MiniTest::Spec]
|
70
|
+
def self.describe_stack
|
71
|
+
@@describe_stack
|
72
|
+
end
|
73
|
+
|
74
|
+
@@description_stack = []
|
75
|
+
def self.description_stack
|
76
|
+
@@description_stack
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.current
|
80
|
+
@@current_spec
|
81
|
+
end
|
82
|
+
|
83
|
+
def initialize name
|
84
|
+
super
|
85
|
+
@@current_spec = self
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.nuke_test_methods!
|
89
|
+
self.public_instance_methods.grep(/^test_/).each do |name|
|
90
|
+
send :undef_method, name rescue nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.define_inheritable_method name, &block
|
95
|
+
super_method = self.superclass.instance_method name
|
96
|
+
|
97
|
+
define_method name do
|
98
|
+
super_method.bind(self).call if super_method # regular super() warns
|
99
|
+
instance_eval(&block)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.before(type = :each, &block)
|
104
|
+
raise "unsupported before type: #{type}" unless type == :each
|
105
|
+
define_inheritable_method :setup, &block
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.after(type = :each, &block)
|
109
|
+
raise "unsupported after type: #{type}" unless type == :each
|
110
|
+
define_inheritable_method :teardown, &block
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.it desc, &block
|
114
|
+
define_method "test_#{description_stack.join(' ').gsub(/\W+/, '_')}_#{desc.gsub(/\W+/, '_').downcase}", &block
|
115
|
+
end
|
116
|
+
|
117
|
+
# beacuse test names are really just comments, and therefore a code smell
|
118
|
+
def self.expect(desc=nil, &block)
|
119
|
+
@minitest_expection_counter ||= 0; @minitest_expectation_counter += 1
|
120
|
+
desc ||= "[#{@minitest_expection_counter}]"
|
121
|
+
name = ["test_", description_stack, desc].flatten.join('_')
|
122
|
+
define_method name, &block
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|