minitest 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,12 @@
1
+ === 4.3.0 / 2012-11-17
2
+
3
+ * 4 minor enhancements:
4
+
5
+ * Allow #autorun to run even if loaded with other test libs that call exit. (sunaku)
6
+ * Do not include Expectations in Object if $MT_NO_EXPECTATIONS is set (experimental?)
7
+ * Gave some much needed love to assert_raises.
8
+ * Mock#expect can take a block to custom-validate args. (gmoothart)
9
+
1
10
  === 4.2.0 / 2012-11-02
2
11
 
3
12
  * 4 major enhancements:
data/README.txt CHANGED
@@ -49,6 +49,17 @@ discovery.
49
49
 
50
50
  -- Piotr Szotkowski
51
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
+
52
63
  == FEATURES/PROBLEMS:
53
64
 
54
65
  * minitest/autorun - the easy and explicit way to run all your tests.
@@ -264,43 +275,74 @@ fixture loading:
264
275
 
265
276
  == Known Extensions:
266
277
 
267
- minitest-capistrano :: Assertions and expectations for testing Capistrano recipes
268
- minitest-capybara :: Capybara matchers support for minitest unit and spec
269
- minitest-chef-handler :: Run Minitest suites as Chef report handlers
270
- minitest-ci :: CI reporter plugin for MiniTest.
271
- minitest-colorize :: Colorize MiniTest output and show failing tests instantly.
272
- minitest-context :: Defines contexts for code reuse in MiniTest
273
- specs that share common expectations.
274
- minitest-debugger :: Wraps assert so failed assertions drop into
275
- the ruby debugger.
276
- minitest-display :: Patches MiniTest to allow for an easily configurable output.
277
- minitest-emoji :: Print out emoji for your test passes, fails, and skips.
278
- minitest-excludes :: Clean API for excluding certain tests you
279
- don't want to run under certain conditions.
280
- minitest-firemock :: Makes your MiniTest mocks more resilient.
281
- minitest-growl :: Test notifier for minitest via growl.
282
- minitest-instrument :: Instrument ActiveSupport::Notifications when
283
- test method is executed
284
- minitest-instrument-db :: Store information about speed of test
285
- execution provided by minitest-instrument in database
286
- minitest-libnotify :: Test notifier for minitest via libnotify.
287
- minitest-macruby :: Provides extensions to minitest for macruby UI testing.
288
- minitest-matchers :: Adds support for RSpec-style matchers to minitest.
289
- minitest-metadata :: Annotate tests with metadata (key-value).
290
- minitest-mongoid :: Mongoid assertion matchers for MiniTest
291
- minitest-must_not :: Provides must_not as an alias for wont in MiniTest
292
- minitest-predicates :: Adds support for .predicate? methods
293
- minitest-pry :: A minitest plugin to drop into pry on assertion failure.
294
- minitest-rails :: MiniTest integration for Rails 3.1.
295
- minitest-reporters :: Create customizable MiniTest output formats
296
- minitest-rg :: redgreen minitest
297
- minitest-spec-magic :: Minitest::Spec extensions for Rails and beyond
298
- minitest-tags :: add tags for minitest
299
- minitest-wscolor :: Yet another test colorizer.
300
- minitest_owrapper :: Get tests results as a TestResult object.
301
- minitest_should :: Shoulda style syntax for minitest test::unit.
302
- minitest_tu_shim :: minitest_tu_shim bridges between test/unit and minitest.
303
- mongoid-minitest :: MiniTest matchers for Mongoid.
278
+ minitest-capistrano :: Assertions and expectations for testing Capistrano recipes
279
+ minitest-capybara :: Capybara matchers support for minitest unit and spec
280
+ minitest-chef-handler :: Run Minitest suites as Chef report handlers
281
+ minitest-ci :: CI reporter plugin for MiniTest.
282
+ minitest-colorize :: Colorize MiniTest output and show failing tests instantly.
283
+ minitest-context :: Defines contexts for code reuse in MiniTest
284
+ specs that share common expectations.
285
+ minitest-debugger :: Wraps assert so failed assertions drop into
286
+ the ruby debugger.
287
+ minitest-display :: Patches MiniTest to allow for an easily configurable output.
288
+ minitest-emoji :: Print out emoji for your test passes, fails, and skips.
289
+ minitest-excludes :: Clean API for excluding certain tests you
290
+ don't want to run under certain conditions.
291
+ minitest-firemock :: Makes your MiniTest mocks more resilient.
292
+ minitest-growl :: Test notifier for minitest via growl.
293
+ minitest-instrument :: Instrument ActiveSupport::Notifications when
294
+ test method is executed
295
+ minitest-instrument-db :: Store information about speed of test
296
+ execution provided by minitest-instrument in database
297
+ minitest-libnotify :: Test notifier for minitest via libnotify.
298
+ minitest-macruby :: Provides extensions to minitest for macruby UI testing.
299
+ minitest-matchers :: Adds support for RSpec-style matchers to minitest.
300
+ minitest-metadata :: Annotate tests with metadata (key-value).
301
+ minitest-mongoid :: Mongoid assertion matchers for MiniTest
302
+ minitest-must_not :: Provides must_not as an alias for wont in MiniTest
303
+ minitest-predicates :: Adds support for .predicate? methods
304
+ minitest-rails :: MiniTest integration for Rails 3.x
305
+ minitest-rails-capybara :: Capybara integration for MiniTest::Rails
306
+ minitest-reporters :: Create customizable MiniTest output formats
307
+ minitest-rg :: redgreen minitest
308
+ minitest-shouldify :: Adding all manner of shoulds to MiniTest (bad idea)
309
+ minitest-spec-magic :: Minitest::Spec extensions for Rails and beyond
310
+ minitest-tags :: add tags for minitest
311
+ minitest-wscolor :: Yet another test colorizer.
312
+ minitest_owrapper :: Get tests results as a TestResult object.
313
+ minitest_should :: Shoulda style syntax for minitest test::unit.
314
+ minitest_tu_shim :: minitest_tu_shim bridges between test/unit and minitest.
315
+ mongoid-minitest :: MiniTest matchers for Mongoid.
316
+ pry-rescue :: A pry plugin w/ minitest support. See pry-rescue/minitest.rb.
317
+
318
+ == Unknown Extensions:
319
+
320
+ Authors... Please send me a pull request with a description of your minitest extension.
321
+
322
+ * assay-minitest
323
+ * capybara_minitest_spec
324
+ * detroit-minitest
325
+ * em-minitest-spec
326
+ * flexmock-minitest
327
+ * guard-minitest
328
+ * guard-minitest-decisiv
329
+ * minitest-activemodel
330
+ * minitest-ar-assertions
331
+ * minitest-around
332
+ * minitest-capybara-unit
333
+ * minitest-colorer
334
+ * minitest-deluxe
335
+ * minitest-extra-assertions
336
+ * minitest-nc
337
+ * minitest-rails-shoulda
338
+ * minitest-spec
339
+ * minitest-spec-context
340
+ * minitest-spec-rails
341
+ * minitest-spec-should
342
+ * minitest-sugar
343
+ * minitest_should
344
+ * mongoid-minitest
345
+ * spork-minitest
304
346
 
305
347
  == REQUIREMENTS:
306
348
 
@@ -24,8 +24,8 @@ module MiniTest
24
24
  end
25
25
 
26
26
  ##
27
- # Expect that method +name+ is called, optionally with +args+, and returns
28
- # +retval+.
27
+ # Expect that method +name+ is called, optionally with +args+ or a
28
+ # +blk+, and returns +retval+.
29
29
  #
30
30
  # @mock.expect(:meaning_of_life, 42)
31
31
  # @mock.meaning_of_life # => 42
@@ -33,6 +33,10 @@ module MiniTest
33
33
  # @mock.expect(:do_something_with, true, [some_obj, true])
34
34
  # @mock.do_something_with(some_obj, true) # => true
35
35
  #
36
+ # @mock.expect(:do_something_else, true) do |a1, a2|
37
+ # a1 == "buggs" && a2 == :bunny
38
+ # end
39
+ #
36
40
  # +args+ is compared to the expected args using case equality (ie, the
37
41
  # '===' operator), allowing for less specific expectations.
38
42
  #
@@ -44,9 +48,14 @@ module MiniTest
44
48
  # @mock.uses_one_string("bar") # => true
45
49
  # @mock.verify # => raises MockExpectationError
46
50
 
47
- def expect(name, retval, args=[])
48
- raise ArgumentError, "args must be an array" unless Array === args
49
- @expected_calls[name] << { :retval => retval, :args => args }
51
+ def expect(name, retval, args=[], &blk)
52
+ if block_given?
53
+ raise ArgumentError, "args ignored when block given" unless args.empty?
54
+ @expected_calls[name] << { :retval => retval, :block => blk }
55
+ else
56
+ raise ArgumentError, "args must be an array" unless Array === args
57
+ @expected_calls[name] << { :retval => retval, :args => args }
58
+ end
50
59
  self
51
60
  end
52
61
 
@@ -96,7 +105,17 @@ module MiniTest
96
105
  [sym, args]
97
106
  end
98
107
 
99
- expected_args, retval = expected_call[:args], expected_call[:retval]
108
+ expected_args, retval, val_block =
109
+ expected_call.values_at(:args, :retval, :block)
110
+
111
+ if val_block then
112
+ raise MockExpectationError, "mocked method %p failed block w/ %p" %
113
+ [sym, args] unless val_block.call(args)
114
+
115
+ # keep "verify" happy
116
+ @actual_calls[sym] << expected_call
117
+ return retval
118
+ end
100
119
 
101
120
  if expected_args.size != args.size then
102
121
  raise ArgumentError, "mocked method %p expects %d arguments, got %d" %
@@ -530,5 +530,5 @@ module MiniTest::Expectations
530
530
  end
531
531
 
532
532
  class Object # :nodoc:
533
- include MiniTest::Expectations
533
+ include MiniTest::Expectations unless ENV["MT_NO_EXPECTATIONS"]
534
534
  end
@@ -358,30 +358,30 @@ module MiniTest
358
358
  def assert_raises *exp
359
359
  msg = "#{exp.pop}.\n" if String === exp.last
360
360
 
361
- should_raise = false
362
361
  begin
363
362
  yield
364
- should_raise = true
365
363
  rescue MiniTest::Skip => e
366
- details = "#{msg}#{mu_pp(exp)} exception expected, not"
367
-
368
- if exp.include? MiniTest::Skip then
369
- return e
370
- else
371
- raise e
372
- end
364
+ return e if exp.include? MiniTest::Skip
365
+ raise e
373
366
  rescue Exception => e
374
- details = "#{msg}#{mu_pp(exp)} exception expected, not"
375
- assert(exp.any? { |ex|
376
- ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class
377
- }, exception_details(e, details))
367
+ expected = exp.any? { |ex|
368
+ if ex.instance_of? Module then
369
+ e.kind_of? ex
370
+ else
371
+ e.instance_of? ex
372
+ end
373
+ }
374
+
375
+ assert expected, proc {
376
+ exception_details(e, "#{msg}#{mu_pp(exp)} exception expected, not")
377
+ }
378
378
 
379
379
  return e
380
380
  end
381
381
 
382
382
  exp = exp.first if exp.size == 1
383
- flunk "#{msg}#{mu_pp(exp)} expected but nothing was raised." if
384
- should_raise
383
+
384
+ flunk "#{msg}#{mu_pp(exp)} expected but nothing was raised."
385
385
  end
386
386
 
387
387
  ##
@@ -439,7 +439,7 @@ module MiniTest
439
439
  begin
440
440
  yield
441
441
  rescue ThreadError => e # wtf?!? 1.8 + threads == suck
442
- default += ", not :#{e.message[/uncaught throw \`(\w+?)\'/, 1]}"
442
+ default += ", not \:#{e.message[/uncaught throw \`(\w+?)\'/, 1]}"
443
443
  rescue ArgumentError => e # 1.9 exception
444
444
  default += ", not #{e.message.split(/ /).last}"
445
445
  rescue NameError => e # 1.8 exception
@@ -729,7 +729,7 @@ module MiniTest
729
729
  end
730
730
 
731
731
  class Unit # :nodoc:
732
- VERSION = "4.2.0" # :nodoc:
732
+ VERSION = "4.3.0" # :nodoc:
733
733
 
734
734
  attr_accessor :report, :failures, :errors, :skips # :nodoc:
735
735
  attr_accessor :test_count, :assertion_count # :nodoc:
@@ -764,7 +764,8 @@ module MiniTest
764
764
 
765
765
  def self.autorun
766
766
  at_exit {
767
- next if $! # don't run if there was an exception
767
+ # don't run if there was a non-exit exception
768
+ next if $! and not $!.kind_of? SystemExit
768
769
 
769
770
  # the order here is important. The at_exit handler must be
770
771
  # installed before anyone else gets a chance to install their
@@ -198,6 +198,68 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
198
198
  assert_equal exp, e.message
199
199
  end
200
200
 
201
+ def test_verify_passes_when_mock_block_returns_true
202
+ mock = MiniTest::Mock.new
203
+ mock.expect :foo, nil do
204
+ true
205
+ end
206
+
207
+ mock.foo
208
+
209
+ assert mock.verify
210
+ end
211
+
212
+ def test_mock_block_is_passed_function_params
213
+ arg1, arg2, arg3 = :bar, [1,2,3], {:a => 'a'}
214
+ mock = MiniTest::Mock.new
215
+ mock.expect :foo, nil do |a1, a2, a3|
216
+ a1 == arg1 &&
217
+ a2 == arg2 &&
218
+ a3 == arg3
219
+ end
220
+
221
+ mock.foo arg1, arg2, arg3
222
+
223
+ assert mock.verify
224
+ end
225
+
226
+ def test_verify_fails_when_mock_block_returns_false
227
+ mock = MiniTest::Mock.new
228
+ mock.expect :foo, nil do
229
+ false
230
+ end
231
+
232
+ e = assert_raises(MockExpectationError) { mock.foo }
233
+ exp = "mocked method :foo failed block w/ []"
234
+
235
+ assert_equal exp, e.message
236
+ end
237
+
238
+ def test_mock_block_throws_if_args_passed
239
+ mock = MiniTest::Mock.new
240
+
241
+ e = assert_raises(ArgumentError) do
242
+ mock.expect :foo, nil, [:a, :b, :c] do
243
+ true
244
+ end
245
+ end
246
+
247
+ exp = "args ignored when block given"
248
+
249
+ assert_equal exp, e.message
250
+ end
251
+
252
+ def test_mock_returns_retval_when_called_with_block
253
+ mock = MiniTest::Mock.new
254
+ mock.expect(:foo, 32) do
255
+ true
256
+ end
257
+
258
+ rs = mock.foo
259
+
260
+ assert_equal rs, 32
261
+ end
262
+
201
263
  def util_verify_bad exp
202
264
  e = assert_raises MockExpectationError do
203
265
  @mock.verify
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 51
5
5
  prerelease:
6
6
  segments:
7
7
  - 4
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 4.2.0
10
+ version: 4.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Davis
@@ -36,7 +36,7 @@ cert_chain:
36
36
  FBHgymkyj/AOSqKRIpXPhjC6
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2012-11-02 00:00:00 Z
39
+ date: 2012-11-17 00:00:00 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
@@ -61,11 +61,11 @@ dependencies:
61
61
  requirements:
62
62
  - - ~>
63
63
  - !ruby/object:Gem::Version
64
- hash: 5
64
+ hash: 1
65
65
  segments:
66
66
  - 3
67
- - 1
68
- version: "3.1"
67
+ - 3
68
+ version: "3.3"
69
69
  type: :development
70
70
  version_requirements: *id002
71
71
  description: |-
@@ -111,6 +111,17 @@ description: |-
111
111
  framework that I can actually read in full in one sitting!"
112
112
 
113
113
  -- Piotr Szotkowski
114
+
115
+ Comparing to rspec:
116
+
117
+ rspec is a testing DSL. minitest is ruby.
118
+
119
+ -- Adam Hawkins, "Bow Before MiniTest"
120
+
121
+ minitest doesn't reinvent anything that ruby already provides, like:
122
+ classes, modules, inheritance, methods. This means you only have to
123
+ learn ruby to use minitest and all of your regular OO practices like
124
+ extract-method refactorings still apply.
114
125
  email:
115
126
  - ryand-ruby@zenspider.com
116
127
  executables: []
metadata.gz.sig CHANGED
Binary file