Skip to content
Newer
Older
100644 289 lines (216 sloc) 7.53 KB
7516317 @zenspider Updated url section, switched to github for repo/home url, and cleane…
zenspider authored Jun 27, 2011
1 = minitest/{unit,spec,mock,benchmark}
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored Oct 9, 2008
2
7516317 @zenspider Updated url section, switched to github for repo/home url, and cleane…
zenspider authored Jun 27, 2011
3 home :: https://github.com/seattlerb/minitest
36d0657 @zenspider prepped for release
zenspider authored Sep 13, 2011
4 rdoc :: http://docs.seattlerb.org/minitest
8704fe6 @zenspider + Added link to vim bundle. (sunaku)
zenspider authored Oct 5, 2011
5 vim :: https://github.com/sunaku/vim-ruby-minitest
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored Oct 9, 2008
6
7 == DESCRIPTION:
8
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored Nov 4, 2010
9 minitest provides a complete suite of testing facilities supporting
10 TDD, BDD, mocking, and benchmarking.
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored Oct 9, 2008
11
62e882c @zenspider Added some choice quotes to the readme
zenspider authored Sep 8, 2011
12 "I had a class with Jim Weirich on testing last week and we were
13 allowed to choose our testing frameworks. Kirk Haines and I were
14 paired up and we cracked open the code for a few test
15 frameworks...
16
17 I MUST say that mintiest is *very* readable / understandable
18 compared to the 'other two' options we looked at. Nicely done and
19 thank you for helping us keep our mental sanity."
20
21 -- Wayne E. Seguin
22
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored Nov 4, 2010
23 minitest/unit is a small and incredibly fast unit testing framework.
24 It provides a rich set of assertions to make your tests clean and
25 readable.
26
27 minitest/spec is a functionally complete spec engine. It hooks onto
28 minitest/unit and seamlessly bridges test assertions over to spec
29 expectations.
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored Oct 9, 2008
30
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
31 minitest/benchmark is an awesome way to assert the performance of your
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored Nov 4, 2010
32 algorithms in a repeatable manner. Now you can assert that your newb
33 co-worker doesn't replace your linear algorithm with an exponential
34 one!
35
36 minitest/mock by Steven Baker, is a beautifully tiny mock object
37 framework.
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
38
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored Nov 4, 2010
39 minitest/pride shows pride in testing and adds coloring to your test
7516317 @zenspider Updated url section, switched to github for repo/home url, and cleane…
zenspider authored Jun 27, 2011
40 output. I guess it is an example of how to write IO pipes too. :P
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored Oct 9, 2008
41
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored Nov 4, 2010
42 minitest/unit is meant to have a clean implementation for language
43 implementors that need a minimal set of methods to bootstrap a working
44 test suite. For example, there is no magic involved for test-case
45 discovery.
b8f07dd @zenspider Updated history and readme for release
zenspider authored Oct 9, 2008
46
62e882c @zenspider Added some choice quotes to the readme
zenspider authored Sep 8, 2011
47 "Again, I can’t praise enough the idea of a testing/specing
48 framework that I can actually read in full in one sitting!"
49
50 -- Piotr Szotkowski
51
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored Oct 9, 2008
52 == FEATURES/PROBLEMS:
53
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
54 * minitest/autorun - the easy and explicit way to run all your tests.
ea1ef6f @zenspider more readme enhancements
zenspider authored Oct 26, 2010
55 * minitest/unit - a very fast, simple, and clean test system.
56 * minitest/spec - a very fast, simple, and clean spec system.
57 * minitest/mock - a simple and clean mock system.
58 * minitest/benchmark - an awesome way to assert your algorithm's performance.
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored Nov 4, 2010
59 * minitest/pride - show your pride in testing!
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored Oct 9, 2008
60 * Incredibly small and fast runner, but no bells and whistles.
61
c1fcbe0 @zenspider Added clarification doco
zenspider authored Mar 2, 2009
62 == RATIONALE:
63
64 See design_rationale.rb to see how specs and tests work in minitest.
65
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 1, 2010
66 == SYNOPSIS:
67
68 Given that you'd like to test the following class:
69
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
70 class Meme
71 def i_can_has_cheezburger?
72 "OHAI!"
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
73 end
74
8761009 @zenspider Got the meme right -- "*Will* it blend?" not "Does it blend?" -- shee…
zenspider authored Apr 5, 2011
75 def will_it_blend?
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
76 "YES!"
77 end
78 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
79
80 === Unit tests
81
fe4dac2 @zenspider more rdoc improvements via tenderlove
zenspider authored Nov 4, 2010
82 require 'minitest/autorun'
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
83
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
84 class TestMeme < MiniTest::Unit::TestCase
85 def setup
86 @meme = Meme.new
87 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
88
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
89 def test_that_kitty_can_eat
90 assert_equal "OHAI!", @meme.i_can_has_cheezburger?
91 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
92
8761009 @zenspider Got the meme right -- "*Will* it blend?" not "Does it blend?" -- shee…
zenspider authored Apr 6, 2011
93 def test_that_it_will_not_blend
94 refute_match /^no/i, @meme.will_it_blend?
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
95 end
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
96 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
97
98 === Specs
99
fe4dac2 @zenspider more rdoc improvements via tenderlove
zenspider authored Nov 4, 2010
100 require 'minitest/autorun'
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
101
102 describe Meme do
103 before do
104 @meme = Meme.new
105 end
106
107 describe "when asked about cheeseburgers" do
ea1ef6f @zenspider more readme enhancements
zenspider authored Oct 26, 2010
108 it "must respond positively" do
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
109 @meme.i_can_has_cheezburger?.must_equal "OHAI!"
110 end
111 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
112
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
113 describe "when asked about blending possibilities" do
114 it "won't say no" do
8761009 @zenspider Got the meme right -- "*Will* it blend?" not "Does it blend?" -- shee…
zenspider authored Apr 6, 2011
115 @meme.will_it_blend?.wont_match /^no/i
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
116 end
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
117 end
118 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
119
24d4120 @zenspider Add link for minitest-matchers (wojtekmach)
zenspider authored Nov 29, 2011
120 For matchers support check out:
121 https://github.com/zenspider/minitest-matchers
122
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
123 === Benchmarks
124
125 Add benchmarks to your regular unit tests. If the unit tests fail, the
126 benchmarks won't run.
127
128 # optionally run benchmarks, good for CI-only work!
129 require 'minitest/benchmark' if ENV["BENCH"]
130
131 class TestMeme < MiniTest::Unit::TestCase
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored Nov 4, 2010
132 # Override self.bench_range or default range is [1, 10, 100, 1_000, 10_000]
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
133 def bench_my_algorithm
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored Nov 4, 2010
134 assert_performance_linear 0.9999 do |n| # n is a range value
5bf6342 @zenspider - Clarified the documentation of minitest/benchmark (eregon)
zenspider authored Oct 21, 2011
135 @obj.my_algorithm(n)
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
136 end
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
137 end
138 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
139
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
140 Or add them to your specs. If you make benchmarks optional, you'll
141 need to wrap your benchmarks in a conditional since the methods won't
142 be defined.
143
144 describe Meme do
145 if ENV["BENCH"] then
146 bench_performance_linear "my_algorithm", 0.9999 do |n|
147 100.times do
148 @obj.my_algorithm(n)
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
149 end
150 end
151 end
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
152 end
153
154 outputs something like:
155
156 # Running benchmarks:
157
158 TestBlah 100 1000 10000
159 bench_my_algorithm 0.006167 0.079279 0.786993
160 bench_other_algorithm 0.061679 0.792797 7.869932
161
162 Output is tab-delimited to make it easy to paste into a spreadsheet.
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
163
164 === Mocks
165
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
166 class MemeAsker
167 def initialize(meme)
168 @meme = meme
169 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
170
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
171 def ask(question)
172 method = question.tr(" ","_") + "?"
173 @meme.send(method)
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
174 end
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
175 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
176
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
177 require 'minitest/autorun'
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
178
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
179 describe MemeAsker do
180 before do
181 @meme = MiniTest::Mock.new
182 @meme_asker = MemeAsker.new @meme
183 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
184
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
185 describe "#ask" do
186 describe "when passed an unpunctuated question" do
187 it "should invoke the appropriate predicate method on the meme" do
8761009 @zenspider Got the meme right -- "*Will* it blend?" not "Does it blend?" -- shee…
zenspider authored Apr 6, 2011
188 @meme.expect :will_it_blend?, :return_value
189 @meme_asker.ask "will it blend"
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
190 @meme.verify
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
191 end
192 end
193 end
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
194 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored Apr 2, 2010
195
6023c87 @zenspider + MiniTest::Unit.runner=(runner) provides an easy way of creating cus…
zenspider authored Apr 6, 2011
196 === Customizable Test Runner Types:
197
198 MiniTest::Unit.runner=(runner) provides an easy way of creating custom
199 test runners for specialized needs. Justin Weiss provides the
200 following real-world example to create an alternative to regular
201 fixture loading:
202
203 class MiniTestWithHooks::Unit < MiniTest::Unit
204 def before_suites
205 end
206
207 def after_suites
208 end
209
210 def _run_suites(suites, type)
211 begin
212 before_suites
213 super(suites, type)
214 ensure
215 after_suites
216 end
217 end
218
219 def _run_suite(suite, type)
220 begin
221 suite.before_suite
222 super(suite, type)
223 ensure
224 suite.after_suite
225 end
226 end
227 end
228
229 module MiniTestWithTransactions
230 class Unit < MiniTestWithHooks::Unit
231 include TestSetupHelper
232
233 def before_suites
234 super
235 setup_nested_transactions
236 # load any data we want available for all tests
237 end
238
239 def after_suites
240 teardown_nested_transactions
241 super
242 end
243 end
244 end
245
246 MiniTest::Unit.runner = MiniTestWithTransactions::Unit.new
247
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored Oct 9, 2008
248 == REQUIREMENTS:
249
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
250 * Ruby 1.8, maybe even 1.6 or lower. No magic is involved.
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored Oct 9, 2008
251
252 == INSTALL:
253
ea1ef6f @zenspider more readme enhancements
zenspider authored Oct 26, 2010
254 sudo gem install minitest
255
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
256 On 1.9, you already have it. To get newer candy you can still install
ea1ef6f @zenspider more readme enhancements
zenspider authored Oct 26, 2010
257 the gem, but you'll need to activate the gem explicitly to use it:
772913b @zenspider Updated doco
zenspider authored Oct 21, 2010
258
ea1ef6f @zenspider more readme enhancements
zenspider authored Oct 26, 2010
259 require 'rubygems'
260 gem 'minitest' # ensures you're using the gem, and not the built in MT
261 require 'minitest/autorun'
262
263 # ... usual testing stuffs ...
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored Oct 9, 2008
264
265 == LICENSE:
266
267 (The MIT License)
268
7516317 @zenspider Updated url section, switched to github for repo/home url, and cleane…
zenspider authored Jun 27, 2011
269 Copyright (c) Ryan Davis, seattle.rb
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored Oct 9, 2008
270
271 Permission is hereby granted, free of charge, to any person obtaining
272 a copy of this software and associated documentation files (the
273 'Software'), to deal in the Software without restriction, including
274 without limitation the rights to use, copy, modify, merge, publish,
275 distribute, sublicense, and/or sell copies of the Software, and to
276 permit persons to whom the Software is furnished to do so, subject to
277 the following conditions:
278
279 The above copyright notice and this permission notice shall be
280 included in all copies or substantial portions of the Software.
281
282 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
283 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
284 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
285 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
286 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
287 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
288 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.