Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 330 lines (254 sloc) 10.287 kB
7516317 @zenspider Updated url section, switched to github for repo/home url, and cleane…
zenspider authored
1 = minitest/{unit,spec,mock,benchmark}
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
2
7516317 @zenspider Updated url section, switched to github for repo/home url, and cleane…
zenspider authored
3 home :: https://github.com/seattlerb/minitest
36d0657 @zenspider prepped for release
zenspider authored
4 rdoc :: http://docs.seattlerb.org/minitest
8704fe6 @zenspider + Added link to vim bundle. (sunaku)
zenspider authored
5 vim :: https://github.com/sunaku/vim-ruby-minitest
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
6
7 == DESCRIPTION:
8
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
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
11
62e882c @zenspider Added some choice quotes to the readme
zenspider authored
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
dbcc15f @zenspider typo
zenspider authored
17 I MUST say that minitest is *very* readable / understandable
62e882c @zenspider Added some choice quotes to the readme
zenspider authored
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
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
30
772913b @zenspider Updated doco
zenspider authored
31 minitest/benchmark is an awesome way to assert the performance of your
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
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
38
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
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
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
41
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
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
46
dfb1768 @zenspider stupid unicode...
zenspider authored
47 "Again, I can't praise enough the idea of a testing/specing
62e882c @zenspider Added some choice quotes to the readme
zenspider authored
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
52 == FEATURES/PROBLEMS:
53
772913b @zenspider Updated doco
zenspider authored
54 * minitest/autorun - the easy and explicit way to run all your tests.
ea1ef6f @zenspider more readme enhancements
zenspider authored
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
59 * minitest/pride - show your pride in testing!
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
60 * Incredibly small and fast runner, but no bells and whistles.
61
c1fcbe0 @zenspider Added clarification doco
zenspider authored
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
66 == SYNOPSIS:
67
68 Given that you'd like to test the following class:
69
772913b @zenspider Updated doco
zenspider authored
70 class Meme
71 def i_can_has_cheezburger?
72 "OHAI!"
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
73 end
74
8761009 @zenspider Got the meme right -- "*Will* it blend?" not "Does it blend?" -- shee…
zenspider authored
75 def will_it_blend?
772913b @zenspider Updated doco
zenspider authored
76 "YES!"
77 end
78 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
79
80 === Unit tests
81
fe4dac2 @zenspider more rdoc improvements via tenderlove
zenspider authored
82 require 'minitest/autorun'
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
83
772913b @zenspider Updated doco
zenspider authored
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
88
772913b @zenspider Updated doco
zenspider authored
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
92
8761009 @zenspider Got the meme right -- "*Will* it blend?" not "Does it blend?" -- shee…
zenspider authored
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
95 end
772913b @zenspider Updated doco
zenspider authored
96 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
97
98 === Specs
99
fe4dac2 @zenspider more rdoc improvements via tenderlove
zenspider authored
100 require 'minitest/autorun'
772913b @zenspider Updated doco
zenspider authored
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
108 it "must respond positively" do
772913b @zenspider Updated doco
zenspider authored
109 @meme.i_can_has_cheezburger?.must_equal "OHAI!"
110 end
111 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
112
772913b @zenspider Updated doco
zenspider authored
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
115 @meme.will_it_blend?.wont_match /^no/i
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
116 end
772913b @zenspider Updated doco
zenspider authored
117 end
118 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
119
24d4120 @zenspider Add link for minitest-matchers (wojtekmach)
zenspider authored
120 For matchers support check out:
a8dd067 @zenspider minor cleanup
zenspider authored
121
24d4120 @zenspider Add link for minitest-matchers (wojtekmach)
zenspider authored
122 https://github.com/zenspider/minitest-matchers
123
772913b @zenspider Updated doco
zenspider authored
124 === Benchmarks
125
126 Add benchmarks to your regular unit tests. If the unit tests fail, the
127 benchmarks won't run.
128
129 # optionally run benchmarks, good for CI-only work!
130 require 'minitest/benchmark' if ENV["BENCH"]
131
132 class TestMeme < MiniTest::Unit::TestCase
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
133 # Override self.bench_range or default range is [1, 10, 100, 1_000, 10_000]
772913b @zenspider Updated doco
zenspider authored
134 def bench_my_algorithm
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
135 assert_performance_linear 0.9999 do |n| # n is a range value
5bf6342 @zenspider - Clarified the documentation of minitest/benchmark (eregon)
zenspider authored
136 @obj.my_algorithm(n)
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
137 end
772913b @zenspider Updated doco
zenspider authored
138 end
139 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
140
772913b @zenspider Updated doco
zenspider authored
141 Or add them to your specs. If you make benchmarks optional, you'll
142 need to wrap your benchmarks in a conditional since the methods won't
143 be defined.
144
145 describe Meme do
146 if ENV["BENCH"] then
147 bench_performance_linear "my_algorithm", 0.9999 do |n|
148 100.times do
149 @obj.my_algorithm(n)
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
150 end
151 end
152 end
772913b @zenspider Updated doco
zenspider authored
153 end
154
155 outputs something like:
156
157 # Running benchmarks:
158
159 TestBlah 100 1000 10000
160 bench_my_algorithm 0.006167 0.079279 0.786993
161 bench_other_algorithm 0.061679 0.792797 7.869932
162
163 Output is tab-delimited to make it easy to paste into a spreadsheet.
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
164
165 === Mocks
166
772913b @zenspider Updated doco
zenspider authored
167 class MemeAsker
168 def initialize(meme)
169 @meme = meme
170 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
171
772913b @zenspider Updated doco
zenspider authored
172 def ask(question)
173 method = question.tr(" ","_") + "?"
c0dc789 @zenspider - Fixed MiniTest::Mock example in the readme. (conradwt)
zenspider authored
174 @meme.__send__(method)
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
175 end
772913b @zenspider Updated doco
zenspider authored
176 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
177
772913b @zenspider Updated doco
zenspider authored
178 require 'minitest/autorun'
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
179
772913b @zenspider Updated doco
zenspider authored
180 describe MemeAsker do
181 before do
182 @meme = MiniTest::Mock.new
183 @meme_asker = MemeAsker.new @meme
184 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
185
772913b @zenspider Updated doco
zenspider authored
186 describe "#ask" do
187 describe "when passed an unpunctuated question" do
188 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
189 @meme.expect :will_it_blend?, :return_value
190 @meme_asker.ask "will it blend"
772913b @zenspider Updated doco
zenspider authored
191 @meme.verify
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
192 end
193 end
194 end
772913b @zenspider Updated doco
zenspider authored
195 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
196
6023c87 @zenspider + MiniTest::Unit.runner=(runner) provides an easy way of creating cus…
zenspider authored
197 === Customizable Test Runner Types:
198
199 MiniTest::Unit.runner=(runner) provides an easy way of creating custom
200 test runners for specialized needs. Justin Weiss provides the
201 following real-world example to create an alternative to regular
202 fixture loading:
203
204 class MiniTestWithHooks::Unit < MiniTest::Unit
205 def before_suites
206 end
207
208 def after_suites
209 end
210
211 def _run_suites(suites, type)
212 begin
213 before_suites
214 super(suites, type)
215 ensure
216 after_suites
217 end
218 end
219
220 def _run_suite(suite, type)
221 begin
222 suite.before_suite
223 super(suite, type)
224 ensure
225 suite.after_suite
226 end
227 end
228 end
229
230 module MiniTestWithTransactions
231 class Unit < MiniTestWithHooks::Unit
232 include TestSetupHelper
233
234 def before_suites
235 super
236 setup_nested_transactions
237 # load any data we want available for all tests
238 end
239
240 def after_suites
241 teardown_nested_transactions
242 super
243 end
244 end
245 end
246
247 MiniTest::Unit.runner = MiniTestWithTransactions::Unit.new
248
338dcd5 @zenspider + Updated known extensions
zenspider authored
249 == Known Extensions:
250
251 minitest-capistrano :: Assertions and expectations for testing Capistrano recipes
252 minitest-capybara :: Capybara matchers support for minitest unit and spec
253 minitest-chef-handler :: Run Minitest suites as Chef report handlers
254 minitest-ci :: CI reporter plugin for MiniTest.
255 minitest-colorize :: Colorize MiniTest output and show failing tests instantly.
256 minitest-context :: Defines contexts for code reuse in MiniTest
257 specs that share common expectations.
258 minitest-debugger :: Wraps assert so failed assertions drop into
259 the ruby debugger.
260 minitest-display :: Patches MiniTest to allow for an easily configurable output.
261 minitest-emoji :: Print out emoji for your test passes, fails, and skips.
262 minitest-excludes :: Clean API for excluding certain tests you
263 don't want to run under certain conditions.
264 minitest-firemock :: Makes your MiniTest mocks more resilient.
265 minitest-growl :: Test notifier for minitest via growl.
266 minitest-instrument :: Instrument ActiveSupport::Notifications when
267 test method is executed
268 minitest-instrument-db :: Store information about speed of test
269 execution provided by minitest-instrument in database
270 minitest-libnotify :: Test notifier for minitest via libnotify.
271 minitest-macruby :: Provides extensions to minitest for macruby UI testing.
272 minitest-matchers :: Adds support for RSpec-style matchers to minitest.
bdb850b @zenspider Add minitest-metadata to known extensions. (wojtekmach)
zenspider authored
273 minitest-metadata :: Annotate tests with metadata (key-value).
338dcd5 @zenspider + Updated known extensions
zenspider authored
274 minitest-mongoid :: Mongoid assertion matchers for MiniTest
275 minitest-must_not :: Provides must_not as an alias for wont in MiniTest
276 minitest-predicates :: Adds support for .predicate? methods
277 minitest-pry :: A minitest plugin to drop into pry on assertion failure.
278 minitest-rails :: MiniTest integration for Rails 3.1.
279 minitest-reporters :: Create customizable MiniTest output formats
280 minitest-rg :: redgreen minitest
281 minitest-spec-magic :: Minitest::Spec extensions for Rails and beyond
282 minitest-tags :: add tags for minitest
283 minitest-wscolor :: Yet another test colorizer.
284 minitest_owrapper :: Get tests results as a TestResult object.
285 minitest_should :: Shoulda style syntax for minitest test::unit.
286 minitest_tu_shim :: minitest_tu_shim bridges between test/unit and minitest.
aa5563f @zenspider Added mongoid-minitest to list of known extensions
zenspider authored
287 mongoid-minitest :: MiniTest matchers for Mongoid.
338dcd5 @zenspider + Updated known extensions
zenspider authored
288
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
289 == REQUIREMENTS:
290
772913b @zenspider Updated doco
zenspider authored
291 * 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
292
293 == INSTALL:
294
ea1ef6f @zenspider more readme enhancements
zenspider authored
295 sudo gem install minitest
296
772913b @zenspider Updated doco
zenspider authored
297 On 1.9, you already have it. To get newer candy you can still install
ea1ef6f @zenspider more readme enhancements
zenspider authored
298 the gem, but you'll need to activate the gem explicitly to use it:
772913b @zenspider Updated doco
zenspider authored
299
ea1ef6f @zenspider more readme enhancements
zenspider authored
300 require 'rubygems'
301 gem 'minitest' # ensures you're using the gem, and not the built in MT
302 require 'minitest/autorun'
303
304 # ... usual testing stuffs ...
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
305
306 == LICENSE:
307
308 (The MIT License)
309
7516317 @zenspider Updated url section, switched to github for repo/home url, and cleane…
zenspider authored
310 Copyright (c) Ryan Davis, seattle.rb
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
311
312 Permission is hereby granted, free of charge, to any person obtaining
313 a copy of this software and associated documentation files (the
314 'Software'), to deal in the Software without restriction, including
315 without limitation the rights to use, copy, modify, merge, publish,
316 distribute, sublicense, and/or sell copies of the Software, and to
317 permit persons to whom the Software is furnished to do so, subject to
318 the following conditions:
319
320 The above copyright notice and this permission notice shall be
321 included in all copies or substantial portions of the Software.
322
323 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
324 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
325 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
326 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
327 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
328 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
329 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.