rspec 0.5.12 → 0.5.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/CHANGES +9 -1
  2. data/README +2 -2
  3. data/Rakefile +13 -5
  4. data/examples/custom_formatter.rb +2 -2
  5. data/examples/file_accessor.rb +18 -0
  6. data/examples/file_accessor_spec.rb +38 -0
  7. data/examples/io_processor.rb +8 -0
  8. data/examples/io_processor_spec.rb +21 -0
  9. data/lib/spec/api/exceptions.rb +3 -0
  10. data/lib/spec/api/mocks/message_expectation.rb +45 -29
  11. data/lib/spec/api/mocks/mock.rb +1 -1
  12. data/lib/spec/api/mocks/order_group.rb +1 -1
  13. data/lib/spec/runner.rb +1 -5
  14. data/lib/spec/runner/formatter.rb +5 -0
  15. data/lib/spec/runner/formatter/base_text_formatter.rb +79 -0
  16. data/lib/spec/runner/formatter/html_formatter.rb +156 -0
  17. data/lib/spec/runner/formatter/progress_bar_formatter.rb +27 -0
  18. data/lib/spec/runner/formatter/rdoc_formatter.rb +22 -0
  19. data/lib/spec/runner/formatter/specdoc_formatter.rb +22 -0
  20. data/lib/spec/runner/option_parser.rb +17 -17
  21. data/lib/spec/runner/reporter.rb +1 -1
  22. data/lib/spec/version.rb +1 -1
  23. data/test/spec/api/helper/arbitrary_predicate_test.rb +38 -38
  24. data/test/spec/api/helper/diff_test.rb +1 -1
  25. data/test/spec/api/helper/identity_test.rb +17 -10
  26. data/test/spec/api/helper/{equality_test.rb → object_equality_test.rb} +15 -29
  27. data/test/spec/api/helper/regex_matching_test.rb +7 -9
  28. data/test/spec/api/helper/throwing_test.rb +11 -12
  29. data/test/spec/api/helper/true_false_special_case_test.rb +15 -17
  30. data/test/spec/api/helper/typing_test.rb +27 -26
  31. data/test/spec/api/mocks/mock_arg_constraints_test.rb +1 -1
  32. data/test/spec/api/mocks/mock_test.rb +45 -11
  33. data/test/spec/api/mocks/null_object_test.rb +3 -3
  34. data/test/spec/runner/context_matching_test.rb +2 -2
  35. data/test/spec/runner/formatter/failure_dump_test.rb +94 -0
  36. data/test/spec/runner/formatter/html_formatter_test.rb +48 -0
  37. data/test/spec/runner/formatter/progress_bar_formatter_test.rb +56 -0
  38. data/test/spec/runner/formatter/rdoc_formatter_test.rb +51 -0
  39. data/test/spec/runner/formatter/specdoc_formatter_test.rb +57 -0
  40. data/test/spec/runner/kernel_ext_test.rb +1 -1
  41. data/test/spec/runner/option_parser_test.rb +22 -12
  42. data/test/spec/runner/reporter_test.rb +1 -1
  43. data/test/test_classes.rb +7 -7
  44. metadata +19 -14
  45. data/lib/spec/runner/base_text_formatter.rb +0 -77
  46. data/lib/spec/runner/html_formatter.rb +0 -153
  47. data/lib/spec/runner/progress_bar_formatter.rb +0 -25
  48. data/lib/spec/runner/rdoc_formatter.rb +0 -20
  49. data/lib/spec/runner/specdoc_formatter.rb +0 -20
  50. data/test/spec/runner/failure_dump_test.rb +0 -92
  51. data/test/spec/runner/html_formatter_test.rb +0 -47
  52. data/test/spec/runner/progress_bar_formatter_test.rb +0 -54
  53. data/test/spec/runner/rdoc_formatter_test.rb +0 -50
  54. data/test/spec/runner/specdoc_formatter_test.rb +0 -55
@@ -3,31 +3,29 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Spec
4
4
  module Api
5
5
  module Helper
6
- class RegexMatchingTest < Test::Unit::TestCase
6
+ class ShouldMatchTest < Test::Unit::TestCase
7
7
 
8
- # should.match
9
-
10
- def test_should_match_should_not_raise_when_objects_match
8
+ def test_should_not_raise_when_objects_match
11
9
  assert_nothing_raised do
12
10
  "hi aslak".should.match /aslak/
13
11
  end
14
12
  end
15
13
 
16
- def test_should_equal_should_raise_when_objects_do_not_match
14
+ def test_should_raise_when_objects_do_not_match
17
15
  assert_raise(ExpectationNotMetError) do
18
16
  "hi aslak".should.match /steve/
19
17
  end
20
18
  end
19
+ end
21
20
 
22
- # should.not.match
23
-
24
- def test_should_not_match_should_not_raise_when_objects_do_not_match
21
+ class ShouldNotMatchTest < Test::Unit::TestCase
22
+ def test_should_not_raise_when_objects_do_not_match
25
23
  assert_nothing_raised do
26
24
  "hi aslak".should.not.match /steve/
27
25
  end
28
26
  end
29
27
 
30
- def test_should_not_match_should_raise_when_objects_match
28
+ def test_should_raise_when_objects_match
31
29
  assert_raise(ExpectationNotMetError) do
32
30
  "hi aslak".should.not.match /aslak/
33
31
  end
@@ -3,49 +3,48 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Spec
4
4
  module Api
5
5
  module Helper
6
- class ThrowingTest < Test::Unit::TestCase
6
+ class ShouldThrowTest < Test::Unit::TestCase
7
7
 
8
- # should.raise
9
-
10
- def test_should_throw_should_pass_when_proper_symbol_is_thrown
8
+ def test_should_pass_when_proper_symbol_is_thrown
11
9
  assert_nothing_raised do
12
10
  proc { throw :foo }.should.throw :foo
13
11
  end
14
12
  end
15
13
 
16
- def test_should_throw_should_fail_when_wrong_exception_is_thrown
14
+ def test_should_fail_when_wrong_symbol_is_thrown
17
15
  assert_raise(ExpectationNotMetError) do
18
16
  proc { throw :bar }.should.throw :foo
19
17
  end
20
18
  end
21
19
 
22
- def test_should_throw_should_fail_when_no_symbol_is_thrown
20
+ def test_should_fail_when_no_symbol_is_thrown
23
21
  assert_raise(ExpectationNotMetError) do
24
- proc {''.to_s}.should.throw :foo
22
+ proc { ''.to_s }.should.throw :foo
25
23
  end
26
24
  end
25
+ end
27
26
 
28
- # should.not.throw
27
+ class ShouldNotThrowTest < Test::Unit::TestCase
29
28
 
30
- def test_should_not_throw_should_fail_when_specific_symbol_is_thrown
29
+ def test_should_fail_when_expected_symbol_is_actually_thrown
31
30
  assert_raise(ExpectationNotMetError) do
32
31
  proc { throw :foo }.should.not.throw :foo
33
32
  end
34
33
  end
35
34
 
36
- def test_should_not_throw_should_pass_when_other_symbol_is_thrown
35
+ def test_should_pass_when_expected_symbol_is_thrown
37
36
  assert_nothing_raised do
38
37
  proc { throw :bar }.should.not.throw :foo
39
38
  end
40
39
  end
41
40
 
42
- def test_should_not_throw_should_pass_when_no_symbol_is_thrown
41
+ def test_should_pass_when_no_symbol_is_thrown
43
42
  assert_nothing_raised do
44
43
  proc { ''.to_s }.should.not.throw :foo
45
44
  end
46
45
  end
47
46
 
48
- def test_should_not_throw_should_pass_when_no_symbol_is_thrown_and_none_is_specified
47
+ def test_should_pass_when_no_symbol_is_thrown_and_none_is_specified
49
48
  assert_nothing_raised do
50
49
  proc { ''.to_s }.should.not.throw
51
50
  end
@@ -3,79 +3,77 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Spec
4
4
  module Api
5
5
  module Helper
6
- class TrueFalseSpecialCaseTest < Test::Unit::TestCase
6
+ class ShouldBeTrueTest < Test::Unit::TestCase
7
7
 
8
- # should.be true
9
-
10
- def test_should_be_true_should_raise_when_object_is_nil
8
+ def test_should_raise_when_object_is_nil
11
9
  assert_raise(ExpectationNotMetError) do
12
10
  nil.should.be true
13
11
  end
14
12
  end
15
13
 
16
- def test_should_be_true_should_raise_when_object_is_false
14
+ def test_should_raise_when_object_is_false
17
15
  assert_raise(ExpectationNotMetError) do
18
16
  false.should.be true
19
17
  end
20
18
  end
21
19
 
22
- def test_should_be_true_shouldnt_raise_when_object_is_true
20
+ def test_shouldnt_raise_when_object_is_true
23
21
  assert_nothing_raised do
24
22
  true.should.be true
25
23
  end
26
24
  end
27
25
 
28
- def test_should_be_true_shouldnt_raise_when_object_is_a_number
26
+ def test_shouldnt_raise_when_object_is_a_number
29
27
  assert_nothing_raised do
30
28
  5.should.be true
31
29
  end
32
30
  end
33
31
 
34
- def test_should_be_true_shouldnt_raise_when_object_is_a_string
32
+ def test_shouldnt_raise_when_object_is_a_string
35
33
  assert_nothing_raised do
36
34
  "hello".should.be true
37
35
  end
38
36
  end
39
37
 
40
- def test_should_be_true_shouldnt_raise_when_object_is_a_some_random_object
38
+ def test_shouldnt_raise_when_object_is_a_some_random_object
41
39
  assert_nothing_raised do
42
40
  self.should.be true
43
41
  end
44
42
  end
43
+ end
45
44
 
46
- # should.be false
47
-
48
- def test_should_be_false_shouldnt_raise_when_object_is_nil
45
+ class ShouldBeFalseTest < Test::Unit::TestCase
46
+ def test_shouldnt_raise_when_object_is_nil
49
47
  assert_nothing_raised do
50
48
  nil.should.be false
51
49
  end
52
50
  end
53
51
 
54
- def test_should_be_false_shouldnt_raise_when_object_is_false
52
+ def test_shouldnt_raise_when_object_is_false
55
53
  assert_nothing_raised do
56
54
  false.should.be false
57
55
  end
58
56
  end
59
57
 
60
- def test_should_be_false_should_raise_when_object_is_true
58
+ def test_should_raise_when_object_is_true
61
59
  assert_raise(ExpectationNotMetError) do
62
60
  true.should.be false
63
61
  end
64
62
  end
65
63
 
66
- def test_should_be_false_shouldnt_raise_when_object_is_a_number
64
+ def test_shouldnt_raise_when_object_is_a_number
67
65
  assert_raise(ExpectationNotMetError) do
68
66
  5.should.be false
69
67
  end
70
68
  end
71
69
 
72
- def test_should_be_false_shouldnt_raise_when_object_is_a_string
70
+ def test_shouldnt_raise_when_object_is_a_string
73
71
  assert_raise(ExpectationNotMetError) do
74
72
  "hello".should.be false
75
73
  end
76
74
  end
77
75
 
78
- def test_should_be_false_shouldnt_raise_when_object_is_a_some_random_object
76
+ def test_shouldnt_raise_when_object_is_a_some_random_object
79
77
  assert_raise(ExpectationNotMetError) do
80
78
  self.should.be false
81
79
  end
@@ -3,99 +3,100 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Spec
4
4
  module Api
5
5
  module Helper
6
- class TypeTest < Test::Unit::TestCase
6
+ class ShouldBeAnInstanceOfTest < Test::Unit::TestCase
7
7
 
8
- # should.be.an.instance.of <class>
9
-
10
- def test_should_be_an_instance_of_should_pass_when_target_is_specified_class
8
+ def test_should_pass_when_target_is_specified_class
11
9
  assert_nothing_raised do
12
10
  5.should.be.an.instance.of Fixnum
13
11
  end
14
12
  end
15
13
 
16
- def test_should_be_an_instance_of_should_fail_when_target_is_not_specified_class
14
+ def test_should_fail_when_target_is_not_specified_class
17
15
  assert_raise(ExpectationNotMetError) do
18
16
  5.should.be.an.instance.of Integer
19
17
  end
20
18
  end
19
+ end
20
+
21
+ class ShouldBeAKindOfTest < Test::Unit::TestCase
21
22
 
22
- # should.be.a.kind.of <class>
23
-
24
- def test_should_be_a_kind_of_should_pass_when_target_is_of_specified_class
23
+ def test_should_pass_when_target_is_of_specified_class
25
24
  assert_nothing_raised do
26
25
  5.should.be.a.kind.of Fixnum
27
26
  end
28
27
  end
29
28
 
30
- def test_should_be_a_kind_of_should_pass_when_target_is_of_subclass_of_specified_class
29
+ def test_should_pass_when_target_is_of_subclass_of_specified_class
31
30
  assert_nothing_raised do
32
31
  5.should.be.a.kind.of Integer
33
32
  end
34
33
  end
35
34
 
36
- def test_should_be_an_instance_of_should_fail_when_target_is_not_specified_class
35
+ def test_should_fail_when_target_is_not_specified_class
37
36
  assert_raise(ExpectationNotMetError) do
38
37
  5.should.be.a.kind.of String
39
38
  end
40
39
  end
40
+ end
41
+
42
+ class ShouldNotBeAnInstanceOfTest < Test::Unit::TestCase
41
43
 
42
- # should.not.be.an.instance_of <class>
43
-
44
- def test_should_not_be_an_instance_of_should_fail_when_target_is_of_specified_class
44
+ def test_should_fail_when_target_is_of_specified_class
45
45
  assert_raise(ExpectationNotMetError) do
46
46
  'hello'.should.not.be.an.instance.of String
47
47
  end
48
48
  end
49
49
 
50
- def test_should_be_an_instance_of_should_pass_when_target_is_not_of_specified_class
50
+ def test_should_pass_when_target_is_not_of_specified_class
51
51
  assert_nothing_raised do
52
52
  [].should.not.be.an.instance.of String
53
53
  end
54
54
  end
55
+ end
55
56
 
56
- # should.be.a.kind.of <class>
57
+ class ShouldNotBeAKindOfTest < Test::Unit::TestCase
57
58
 
58
- def test_should_not_be_a_kind_of_should_fail_when_target_is_of_specified_class
59
+ def test_should_fail_when_target_is_of_specified_class
59
60
  assert_raise(ExpectationNotMetError) do
60
61
  5.should.not.be.a.kind.of Fixnum
61
62
  end
62
63
  end
63
64
 
64
- def test_should_not_be_a_kind_of_should_fail_when_target_is_of_subclass_of_specified_class
65
+ def test_should_fail_when_target_is_of_subclass_of_specified_class
65
66
  assert_raise(ExpectationNotMetError) do
66
67
  5.should.not.be.a.kind.of Integer
67
68
  end
68
69
  end
69
70
 
70
- def test_should_not_be_an_instance_of_should_pass_when_target_is_not_specified_class
71
+ def test_should_pass_when_target_is_not_specified_class
71
72
  assert_nothing_raised do
72
73
  5.should.not.be.a.kind.of String
73
74
  end
74
75
  end
76
+ end
75
77
 
76
- # should.respond.to <message>
77
-
78
- def test_should_respond_to_should_pass_when_target_does
78
+ class ShouldRespondToTest < Test::Unit::TestCase
79
+ def test_should_pass_when_target_responds_to
79
80
  assert_nothing_raised do
80
81
  "".should.respond.to :length
81
82
  end
82
83
  end
83
84
 
84
- def test_should_respond_to_should_fail_when_target_doesnt
85
+ def test_should_fail_when_target_doesnt_respond_to
85
86
  assert_raise(ExpectationNotMetError) do
86
87
  "".should.respond.to :connect
87
88
  end
88
89
  end
90
+ end
89
91
 
90
- # should.not.respond.to <message>
91
-
92
- def test_not_should_respond_to_should_fail_when_target_does
92
+ class ShouldNotRespondToTest < Test::Unit::TestCase
93
+ def test_should_fail_when_target_responds_to
93
94
  assert_raise(ExpectationNotMetError) do
94
95
  "".should.not.respond.to :length
95
96
  end
96
97
  end
97
98
 
98
- def test_not_should_respond_to_should_pass_when_target_doesnt
99
+ def test_should_pass_when_target_doesnt_respond_to
99
100
  assert_nothing_raised do
100
101
  "".should.not.respond.to :connect
101
102
  end
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../../../test_helper'
2
2
 
3
3
  module Spec
4
4
  module Api
5
- class PassingConstraintsTest < Test::Unit::TestCase
5
+ class PassingConstraintsToMockTest < Test::Unit::TestCase
6
6
 
7
7
  def setup
8
8
  @mock = Mock.new("test mock")
@@ -23,7 +23,6 @@ module Spec
23
23
  def test_should_allow_block_to_calculate_return_values
24
24
  @mock.should.receive(:random_call).with("a","b","c").and.return { |a,b,c| c+b+a }
25
25
  assert_equal "cba", @mock.random_call("a","b","c")
26
- # TODO: remove __verify when migrating to self-hosting. Verify happens transparently in teardown. (AH)
27
26
  @mock.__verify
28
27
  end
29
28
 
@@ -86,17 +85,17 @@ module Spec
86
85
  end
87
86
 
88
87
  def test_two_return_values
89
- @mock.should.receive(:multi_call).twice.with(:no_args).and.return([1, 2])
90
- assert_equal(1, @mock.multi_call)
91
- assert_equal(2, @mock.multi_call)
88
+ @mock.should.receive(:multi_call).twice.with(:no_args).and.return([8, 12])
89
+ assert_equal(8, @mock.multi_call)
90
+ assert_equal(12, @mock.multi_call)
92
91
  @mock.__verify
93
92
  end
94
93
 
95
94
  def test_repeating_final_return_value
96
- @mock.should.receive(:multi_call).at.least(:once).with(:no_args).and.return([1, 2])
97
- assert_equal(1, @mock.multi_call)
98
- assert_equal(2, @mock.multi_call)
99
- assert_equal(2, @mock.multi_call)
95
+ @mock.should.receive(:multi_call).at.least(:once).with(:no_args).and.return([11, 22])
96
+ assert_equal(11, @mock.multi_call)
97
+ assert_equal(22, @mock.multi_call)
98
+ assert_equal(22, @mock.multi_call)
100
99
  @mock.__verify
101
100
  end
102
101
 
@@ -249,7 +248,7 @@ module Spec
249
248
  @mock.__verify
250
249
  end
251
250
  end
252
-
251
+
253
252
  def test_should_raise_if_exactly_3_times_method_is_called_4_times
254
253
  @mock.should.receive(:random_call).exactly(3).times
255
254
  @mock.random_call
@@ -260,19 +259,34 @@ module Spec
260
259
  end
261
260
  end
262
261
 
263
- def test_raising
262
+ def test_should_raise_when_told_to
264
263
  @mock.should.receive(:random_call).and.raise(RuntimeError)
265
264
  assert_raise(RuntimeError) do
266
265
  @mock.random_call
267
266
  end
268
267
  end
269
268
 
270
- def test_throwing
269
+ def test_should_not_raise_when_told_to_if_args_dont_match
270
+ @mock.should.receive(:random_call).with(2).and.raise(RuntimeError)
271
+ assert_raise(MockExpectationError) do
272
+ @mock.random_call(1)
273
+ end
274
+ end
275
+
276
+ def test_should_throw_when_told_to
271
277
  @mock.should.receive(:random_call).and.throw(:blech)
272
278
  assert_throws(:blech) do
273
279
  @mock.random_call
274
280
  end
275
281
  end
282
+
283
+ def test_should_raise_when_explicit_return_and_block_constrained
284
+ assert_raise(AmbiguousReturnError) {
285
+ @mock.should.receive(:fruit){|colour|
286
+ :strawberry
287
+ }.and.return :apple
288
+ }
289
+ end
276
290
 
277
291
  def TODO_test_should_use_past_tense
278
292
  @mock.should.have.received(:hello)
@@ -308,6 +322,14 @@ module Spec
308
322
  @mock.__verify
309
323
  end
310
324
 
325
+ def test_should_yield_single_values
326
+ @mock.should.receive(:yield_back).with(:no_args).once.and.yield(99)
327
+ a = nil
328
+ @mock.yield_back {|a|}
329
+ a.should.equal 99
330
+ @mock.__verify
331
+ end
332
+
311
333
  def test_should_fail_when_calling_yielding_method_with_wrong_arity
312
334
  @mock.should.receive(:yield_back).with(:no_args).once.and.yield('wha', 'zup')
313
335
  assert_raise(MockExpectationError) do
@@ -328,6 +350,18 @@ module Spec
328
350
  @mock.__verify
329
351
  end
330
352
 
353
+ def test_should_be_able_to_raise_from_method_calling_yielding_mock
354
+ @mock.should.receive(:yield_me).and_yield 44
355
+
356
+ lambda do
357
+ @mock.yield_me do |x|
358
+ raise "Bang"
359
+ end
360
+ end.should_raise(StandardError)
361
+
362
+ @mock.__verify
363
+ end
364
+
331
365
  end
332
366
  end
333
367
  end
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Spec
4
4
  module Api
5
5
 
6
- class NullObjectTest < Test::Unit::TestCase
6
+ class NullObjectMockTest < Test::Unit::TestCase
7
7
 
8
8
  def setup
9
9
  @mock = Mock.new("null_object", :null_object=>true)
@@ -14,13 +14,13 @@ module Spec
14
14
  @mock.__verify
15
15
  end
16
16
 
17
- def test_should_handle_passing_expectation
17
+ def test_should_allow_explicit_expectation
18
18
  @mock.should_receive(:something)
19
19
  @mock.something
20
20
  @mock.__verify
21
21
  end
22
22
 
23
- def test_should_handle_failing_expectation
23
+ def test_should_fail_verification_when_explicit_exception_not_met
24
24
  assert_raises(MockExpectationError) do
25
25
  @mock.should_receive(:something)
26
26
  @mock.__verify