spec 5.0.14

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.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +34 -0
  3. data/.gitignore +3 -0
  4. data/History.txt +911 -0
  5. data/Manifest.txt +26 -0
  6. data/README.txt +497 -0
  7. data/Rakefile +214 -0
  8. data/design_rationale.rb +52 -0
  9. data/lib/hoe/minitest.rb +26 -0
  10. data/lib/minitest/assertions.rb +649 -0
  11. data/lib/minitest/autorun.rb +12 -0
  12. data/lib/minitest/benchmark.rb +423 -0
  13. data/lib/minitest/expectations.rb +268 -0
  14. data/lib/minitest/hell.rb +11 -0
  15. data/lib/minitest/mock.rb +220 -0
  16. data/lib/minitest/parallel_each.rb +120 -0
  17. data/lib/minitest/pride.rb +4 -0
  18. data/lib/minitest/pride_plugin.rb +143 -0
  19. data/lib/minitest/spec.rb +292 -0
  20. data/lib/minitest/test.rb +272 -0
  21. data/lib/minitest/unit.rb +45 -0
  22. data/lib/minitest.rb +839 -0
  23. data/lib/spec.rb +3 -0
  24. data/readme.md +7 -0
  25. data/release_notes.md +49 -0
  26. data/spec.gemspec +36 -0
  27. data/test/manual/appium.rb +14 -0
  28. data/test/manual/appium_after_last.rb +24 -0
  29. data/test/manual/appium_before_first.rb +23 -0
  30. data/test/manual/assert.rb +61 -0
  31. data/test/manual/before_first_0.rb +27 -0
  32. data/test/manual/before_first_1.rb +29 -0
  33. data/test/manual/debug.rb +37 -0
  34. data/test/manual/do_end.rb +31 -0
  35. data/test/manual/raise.rb +61 -0
  36. data/test/manual/run2.rb +74 -0
  37. data/test/manual/run3.rb +91 -0
  38. data/test/manual/setup.rb +13 -0
  39. data/test/manual/simple.rb +19 -0
  40. data/test/manual/simple2.rb +20 -0
  41. data/test/manual/t.rb +11 -0
  42. data/test/manual/trace.rb +19 -0
  43. data/test/manual/trace2.rb +15 -0
  44. data/test/minitest/metametameta.rb +78 -0
  45. data/test/minitest/test_helper.rb +20 -0
  46. data/test/minitest/test_minitest_benchmark.rb +131 -0
  47. data/test/minitest/test_minitest_mock.rb +490 -0
  48. data/test/minitest/test_minitest_reporter.rb +270 -0
  49. data/test/minitest/test_minitest_spec.rb +794 -0
  50. data/test/minitest/test_minitest_unit.rb +1846 -0
  51. metadata +147 -0
data/Manifest.txt ADDED
@@ -0,0 +1,26 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ design_rationale.rb
7
+ lib/hoe/minitest.rb
8
+ lib/minitest.rb
9
+ lib/minitest/assertions.rb
10
+ lib/minitest/autorun.rb
11
+ lib/minitest/benchmark.rb
12
+ lib/minitest/expectations.rb
13
+ lib/minitest/hell.rb
14
+ lib/minitest/mock.rb
15
+ lib/minitest/parallel_each.rb
16
+ lib/minitest/pride.rb
17
+ lib/minitest/pride_plugin.rb
18
+ lib/minitest/spec.rb
19
+ lib/minitest/test.rb
20
+ lib/minitest/unit.rb
21
+ test/minitest/metametameta.rb
22
+ test/minitest/test_minitest_benchmark.rb
23
+ test/minitest/test_minitest_mock.rb
24
+ test/minitest/test_minitest_reporter.rb
25
+ test/minitest/test_minitest_spec.rb
26
+ test/minitest/test_minitest_unit.rb
data/README.txt ADDED
@@ -0,0 +1,497 @@
1
+ = minitest/{unit,spec,mock,benchmark}
2
+
3
+ home :: https://github.com/seattlerb/minitest
4
+ rdoc :: http://docs.seattlerb.org/minitest
5
+ vim :: https://github.com/sunaku/vim-ruby-minitest
6
+
7
+ == DESCRIPTION:
8
+
9
+ minitest provides a complete suite of testing facilities supporting
10
+ TDD, BDD, mocking, and benchmarking.
11
+
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 minitest 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
+
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.
30
+
31
+ minitest/benchmark is an awesome way to assert the performance of your
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 (and stub)
37
+ object framework.
38
+
39
+ minitest/pride shows pride in testing and adds coloring to your test
40
+ output. I guess it is an example of how to write IO pipes too. :P
41
+
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.
46
+
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
+
52
+ Comparing to rspec:
53
+
54
+ rspec is a testing DSL. minitest is ruby.
55
+
56
+ -- Adam Hawkins, "Bow Before MiniTest"
57
+
58
+ minitest doesn't reinvent anything that ruby already provides, like:
59
+ classes, modules, inheritance, methods. This means you only have to
60
+ learn ruby to use minitest and all of your regular OO practices like
61
+ extract-method refactorings still apply.
62
+
63
+ == FEATURES/PROBLEMS:
64
+
65
+ * minitest/autorun - the easy and explicit way to run all your tests.
66
+ * minitest/unit - a very fast, simple, and clean test system.
67
+ * minitest/spec - a very fast, simple, and clean spec system.
68
+ * minitest/mock - a simple and clean mock/stub system.
69
+ * minitest/benchmark - an awesome way to assert your algorithm's performance.
70
+ * minitest/pride - show your pride in testing!
71
+ * Incredibly small and fast runner, but no bells and whistles.
72
+
73
+ == RATIONALE:
74
+
75
+ See design_rationale.rb to see how specs and tests work in minitest.
76
+
77
+ == SYNOPSIS:
78
+
79
+ Given that you'd like to test the following class:
80
+
81
+ class Meme
82
+ def i_can_has_cheezburger?
83
+ "OHAI!"
84
+ end
85
+
86
+ def will_it_blend?
87
+ "YES!"
88
+ end
89
+ end
90
+
91
+ === Unit tests
92
+
93
+ require "minitest/autorun"
94
+
95
+ class TestMeme < Minitest::Test
96
+ def setup
97
+ @meme = Meme.new
98
+ end
99
+
100
+ def test_that_kitty_can_eat
101
+ assert_equal "OHAI!", @meme.i_can_has_cheezburger?
102
+ end
103
+
104
+ def test_that_it_will_not_blend
105
+ refute_match /^no/i, @meme.will_it_blend?
106
+ end
107
+
108
+ def test_that_will_be_skipped
109
+ skip "test this later"
110
+ end
111
+ end
112
+
113
+ === Specs
114
+
115
+ require "minitest/autorun"
116
+
117
+ describe Meme do
118
+ before do
119
+ @meme = Meme.new
120
+ end
121
+
122
+ describe "when asked about cheeseburgers" do
123
+ it "must respond positively" do
124
+ @meme.i_can_has_cheezburger?.must_equal "OHAI!"
125
+ end
126
+ end
127
+
128
+ describe "when asked about blending possibilities" do
129
+ it "won't say no" do
130
+ @meme.will_it_blend?.wont_match /^no/i
131
+ end
132
+ end
133
+ end
134
+
135
+ For matchers support check out:
136
+
137
+ https://github.com/zenspider/minitest-matchers
138
+
139
+ === Benchmarks
140
+
141
+ Add benchmarks to your tests.
142
+
143
+ # optionally run benchmarks, good for CI-only work!
144
+ require "minitest/benchmark" if ENV["BENCH"]
145
+
146
+ class TestMeme < Minitest::Benchmark
147
+ # Override self.bench_range or default range is [1, 10, 100, 1_000, 10_000]
148
+ def bench_my_algorithm
149
+ assert_performance_linear 0.9999 do |n| # n is a range value
150
+ @obj.my_algorithm(n)
151
+ end
152
+ end
153
+ end
154
+
155
+ Or add them to your specs. If you make benchmarks optional, you'll
156
+ need to wrap your benchmarks in a conditional since the methods won't
157
+ be defined. In minitest 5, the describe name needs to match
158
+ /Bench(mark)?$/.
159
+
160
+ describe "Meme Benchmark" do
161
+ if ENV["BENCH"] then
162
+ bench_performance_linear "my_algorithm", 0.9999 do |n|
163
+ 100.times do
164
+ @obj.my_algorithm(n)
165
+ end
166
+ end
167
+ end
168
+ end
169
+
170
+ outputs something like:
171
+
172
+ # Running benchmarks:
173
+
174
+ TestBlah 100 1000 10000
175
+ bench_my_algorithm 0.006167 0.079279 0.786993
176
+ bench_other_algorithm 0.061679 0.792797 7.869932
177
+
178
+ Output is tab-delimited to make it easy to paste into a spreadsheet.
179
+
180
+ === Mocks
181
+
182
+ class MemeAsker
183
+ def initialize(meme)
184
+ @meme = meme
185
+ end
186
+
187
+ def ask(question)
188
+ method = question.tr(" ","_") + "?"
189
+ @meme.__send__(method)
190
+ end
191
+ end
192
+
193
+ require "minitest/autorun"
194
+
195
+ describe MemeAsker do
196
+ before do
197
+ @meme = Minitest::Mock.new
198
+ @meme_asker = MemeAsker.new @meme
199
+ end
200
+
201
+ describe "#ask" do
202
+ describe "when passed an unpunctuated question" do
203
+ it "should invoke the appropriate predicate method on the meme" do
204
+ @meme.expect :will_it_blend?, :return_value
205
+ @meme_asker.ask "will it blend"
206
+ @meme.verify
207
+ end
208
+ end
209
+ end
210
+ end
211
+
212
+ === Stubs
213
+
214
+ def test_stale_eh
215
+ obj_under_test = Something.new
216
+
217
+ refute obj_under_test.stale?
218
+
219
+ Time.stub :now, Time.at(0) do # stub goes away once the block is done
220
+ assert obj_under_test.stale?
221
+ end
222
+ end
223
+
224
+ A note on stubbing: In order to stub a method, the method must
225
+ actually exist prior to stubbing. Use a singleton method to create a
226
+ new non-existing method:
227
+
228
+ def obj_under_test.fake_method
229
+ ...
230
+ end
231
+
232
+ == Writing Extensions
233
+
234
+ To define a plugin, add a file named minitest/XXX_plugin.rb to your
235
+ project/gem. Minitest will find and require that file using
236
+ Gem.find_files. It will then try to call plugin_XXX_init during
237
+ startup. The option processor will also try to call plugin_XXX_options
238
+ passing the OptionParser instance and the current options hash. This
239
+ lets you register your own command-line options. Here's a totally
240
+ bogus example:
241
+
242
+ # minitest/bogus_plugin.rb:
243
+
244
+ module Minitest
245
+ def self.plugin_bogus_options(opts, options)
246
+ opts.on "--myci", "Report results to my CI" do
247
+ options[:myci] = true
248
+ options[:myci_addr] = get_myci_addr
249
+ options[:myci_port] = get_myci_port
250
+ end
251
+ end
252
+
253
+ def self.plugin_bogus_init(options)
254
+ self.reporter << MyCI.new(options) if options[:myci]
255
+ end
256
+ end
257
+
258
+ === Adding custom reporters
259
+
260
+ Minitest uses composite reporter to output test results using multiple
261
+ reporter instances. You can add new reporters to the composite during
262
+ the init_plugins phase. As we saw in +plugin_bonus_init+ above, you
263
+ simply add your reporter instance to the composite via +<<+.
264
+
265
+ +AbstractReporter+ defines the API for reporters. You may subclass it
266
+ and override any method you want to achieve your desired behavior.
267
+
268
+ start :: Called when the run has started.
269
+ record :: Called for each result, passed or otherwise.
270
+ report :: Called at the end of the run.
271
+ passed? :: Called to see if you detected any problems.
272
+
273
+ Using our example above, here is how we might implement MyCI:
274
+
275
+ # minitest/bogus_plugin.rb
276
+
277
+ module Minitest
278
+ class MyCI < AbstractReporter
279
+ attr_accessor :results, :addr, :port
280
+
281
+ def initialize options
282
+ self.results = []
283
+ self.addr = options[:myci_addr]
284
+ self.port = options[:myci_port]
285
+ end
286
+
287
+ def record result
288
+ self.results << result
289
+ end
290
+
291
+ def report
292
+ CI.connect(addr, port).send_results self.results
293
+ end
294
+ end
295
+ end
296
+
297
+ == FAQ
298
+
299
+ === How to test SimpleDelegates?
300
+
301
+ The following implementation and test:
302
+
303
+ class Worker < SimpleDelegator
304
+ def work
305
+ end
306
+ end
307
+
308
+ describe Worker do
309
+ before do
310
+ @worker = Worker.new(Object.new)
311
+ end
312
+
313
+ it "must respond to work" do
314
+ @worker.must_respond_to :work
315
+ end
316
+ end
317
+
318
+ outputs a failure:
319
+
320
+ 1) Failure:
321
+ Worker#test_0001_must respond to work [bug11.rb:16]:
322
+ Expected #<Object:0x007f9e7184f0a0> (Object) to respond to #work.
323
+
324
+ Worker is a SimpleDelegate which in 1.9+ is a subclass of BasicObject.
325
+ Expectations are put on Object (one level down) so the Worker
326
+ (SimpleDelegate) hits `method_missing` and delegates down to the
327
+ `Object.new` instance. That object doesn't respond to work so the test
328
+ fails.
329
+
330
+ You can bypass `SimpleDelegate#method_missing` by extending the worker
331
+ with `Minitest::Expectations`. You can either do that in your setup at
332
+ the instance level, like:
333
+
334
+ before do
335
+ @worker = Worker.new(Object.new)
336
+ @worker.extend Minitest::Expectations
337
+ end
338
+
339
+ or you can extend the Worker class (within the test file!), like:
340
+
341
+ class Worker
342
+ include ::Minitest::Expectations
343
+ end
344
+
345
+ === How to share code across test classes?
346
+
347
+ Use a module. That's exactly what they're for:
348
+
349
+ module UsefulStuff
350
+ def useful_method
351
+ # ...
352
+ end
353
+ end
354
+
355
+ describe Blah do
356
+ include UsefulStuff
357
+
358
+ def test_whatever
359
+ # useful_method available here
360
+ end
361
+ end
362
+
363
+ Remember, `describe` simply creates test classes. It's just ruby at
364
+ the end of the day and all your normal Good Ruby Rules (tm) apply. If
365
+ you want to extend your test using setup/teardown via a module, just
366
+ make sure you ALWAYS call super. before/after automatically call super
367
+ for you, so make sure you don't do it twice.
368
+
369
+ == Known Extensions:
370
+
371
+ capybara_minitest_spec :: Bridge between Capybara RSpec matchers and MiniTest::Spec expectations (e.g. page.must_have_content("Title")).
372
+ minispec-metadata :: Metadata for describe/it blocks
373
+ (e.g. `it "requires JS driver", js: true do`)
374
+ minitest-ansi :: Colorize minitest output with ANSI colors.
375
+ minitest-around :: Around block for minitest. An alternative to setup/teardown dance.
376
+ minitest-capistrano :: Assertions and expectations for testing Capistrano recipes
377
+ minitest-capybara :: Capybara matchers support for minitest unit and spec
378
+ minitest-chef-handler :: Run Minitest suites as Chef report handlers
379
+ minitest-ci :: CI reporter plugin for MiniTest.
380
+ minitest-colorize :: Colorize MiniTest output and show failing tests instantly.
381
+ minitest-context :: Defines contexts for code reuse in MiniTest
382
+ specs that share common expectations.
383
+ minitest-debugger :: Wraps assert so failed assertions drop into
384
+ the ruby debugger.
385
+ minitest-display :: Patches MiniTest to allow for an easily configurable output.
386
+ minitest-emoji :: Print out emoji for your test passes, fails, and skips.
387
+ minitest-english :: Semantically symmetric aliases for assertions and expectations.
388
+ minitest-excludes :: Clean API for excluding certain tests you
389
+ don't want to run under certain conditions.
390
+ minitest-filesystem :: Adds assertion and expectation to help testing filesystem contents.
391
+ minitest-firemock :: Makes your MiniTest mocks more resilient.
392
+ minitest-great_expectations :: Generally useful additions to minitest's assertions and expectations
393
+ minitest-growl :: Test notifier for minitest via growl.
394
+ minitest-implicit-subject :: Implicit declaration of the test subject.
395
+ minitest-instrument :: Instrument ActiveSupport::Notifications when
396
+ test method is executed
397
+ minitest-instrument-db :: Store information about speed of test
398
+ execution provided by minitest-instrument in database
399
+ minitest-libnotify :: Test notifier for minitest via libnotify.
400
+ minitest-line :: Run test at line number
401
+ minitest-macruby :: Provides extensions to minitest for macruby UI testing.
402
+ minitest-matchers :: Adds support for RSpec-style matchers to minitest.
403
+ minitest-metadata :: Annotate tests with metadata (key-value).
404
+ minitest-mongoid :: Mongoid assertion matchers for MiniTest
405
+ minitest-must_not :: Provides must_not as an alias for wont in MiniTest
406
+ minitest-nc :: Test notifier for minitest via Mountain Lion's Notification Center
407
+ minitest-predicates :: Adds support for .predicate? methods
408
+ minitest-rails :: MiniTest integration for Rails 3.x
409
+ minitest-rails-capybara :: Capybara integration for MiniTest::Rails
410
+ minitest-reporters :: Create customizable MiniTest output formats
411
+ minitest-should_syntax :: RSpec-style +x.should == y+ assertions for MiniTest
412
+ minitest-shouldify :: Adding all manner of shoulds to MiniTest (bad idea)
413
+ minitest-spec-context :: Provides rspec-ish context method to MiniTest::Spec
414
+ minitest-spec-expect :: Expect syntax for MiniTest::Spec - expect(sequences).to_include :celery_man
415
+ minitest-spec-magic :: Minitest::Spec extensions for Rails and beyond
416
+ minitest-spec-rails :: Drop in MiniTest::Spec superclass for ActiveSupport::TestCase.
417
+ minitest-stub-const :: Stub constants for the duration of a block
418
+ minitest-tags :: add tags for minitest
419
+ minitest-wscolor :: Yet another test colorizer.
420
+ minitest_owrapper :: Get tests results as a TestResult object.
421
+ minitest_should :: Shoulda style syntax for minitest test::unit.
422
+ minitest_tu_shim :: minitest_tu_shim bridges between test/unit and minitest.
423
+ mongoid-minitest :: MiniTest matchers for Mongoid.
424
+ pry-rescue :: A pry plugin w/ minitest support. See pry-rescue/minitest.rb.
425
+
426
+ == Unknown Extensions:
427
+
428
+ Authors... Please send me a pull request with a description of your minitest extension.
429
+
430
+ * assay-minitest
431
+ * detroit-minitest
432
+ * em-minitest-spec
433
+ * flexmock-minitest
434
+ * guard-minitest
435
+ * guard-minitest-decisiv
436
+ * minitest-activemodel
437
+ * minitest-ar-assertions
438
+ * minitest-capybara-unit
439
+ * minitest-colorer
440
+ * minitest-deluxe
441
+ * minitest-extra-assertions
442
+ * minitest-rails-shoulda
443
+ * minitest-spec
444
+ * minitest-spec-should
445
+ * minitest-sugar
446
+ * minitest_should
447
+ * mongoid-minitest
448
+ * spork-minitest
449
+
450
+ == REQUIREMENTS:
451
+
452
+ * Ruby 1.8, maybe even 1.6 or lower. No magic is involved.
453
+
454
+ == INSTALL:
455
+
456
+ sudo gem install minitest
457
+
458
+ On 1.9, you already have it. To get newer candy you can still install
459
+ the gem, and then requiring "minitest/autorun" should automatically
460
+ pull it in. If not, you'll need to do it yourself:
461
+
462
+ gem "minitest" # ensures you"re using the gem, and not the built-in MT
463
+ require "minitest/autorun"
464
+
465
+ # ... usual testing stuffs ...
466
+
467
+ DO NOTE: There is a serious problem with the way that ruby 1.9/2.0
468
+ packages their own gems. They install a gem specification file, but
469
+ don't install the gem contents in the gem path. This messes up
470
+ Gem.find_files and many other things (gem which, gem contents, etc).
471
+
472
+ Just install minitest as a gem for real and you'll be happier.
473
+
474
+ == LICENSE:
475
+
476
+ (The MIT License)
477
+
478
+ Copyright (c) Ryan Davis, seattle.rb
479
+
480
+ Permission is hereby granted, free of charge, to any person obtaining
481
+ a copy of this software and associated documentation files (the
482
+ 'Software'), to deal in the Software without restriction, including
483
+ without limitation the rights to use, copy, modify, merge, publish,
484
+ distribute, sublicense, and/or sell copies of the Software, and to
485
+ permit persons to whom the Software is furnished to do so, subject to
486
+ the following conditions:
487
+
488
+ The above copyright notice and this permission notice shall be
489
+ included in all copies or substantial portions of the Software.
490
+
491
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
492
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
493
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
494
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
495
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
496
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
497
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.