rspec 0.5.12 → 0.5.13
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.
- data/CHANGES +9 -1
- data/README +2 -2
- data/Rakefile +13 -5
- data/examples/custom_formatter.rb +2 -2
- data/examples/file_accessor.rb +18 -0
- data/examples/file_accessor_spec.rb +38 -0
- data/examples/io_processor.rb +8 -0
- data/examples/io_processor_spec.rb +21 -0
- data/lib/spec/api/exceptions.rb +3 -0
- data/lib/spec/api/mocks/message_expectation.rb +45 -29
- data/lib/spec/api/mocks/mock.rb +1 -1
- data/lib/spec/api/mocks/order_group.rb +1 -1
- data/lib/spec/runner.rb +1 -5
- data/lib/spec/runner/formatter.rb +5 -0
- data/lib/spec/runner/formatter/base_text_formatter.rb +79 -0
- data/lib/spec/runner/formatter/html_formatter.rb +156 -0
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +27 -0
- data/lib/spec/runner/formatter/rdoc_formatter.rb +22 -0
- data/lib/spec/runner/formatter/specdoc_formatter.rb +22 -0
- data/lib/spec/runner/option_parser.rb +17 -17
- data/lib/spec/runner/reporter.rb +1 -1
- data/lib/spec/version.rb +1 -1
- data/test/spec/api/helper/arbitrary_predicate_test.rb +38 -38
- data/test/spec/api/helper/diff_test.rb +1 -1
- data/test/spec/api/helper/identity_test.rb +17 -10
- data/test/spec/api/helper/{equality_test.rb → object_equality_test.rb} +15 -29
- data/test/spec/api/helper/regex_matching_test.rb +7 -9
- data/test/spec/api/helper/throwing_test.rb +11 -12
- data/test/spec/api/helper/true_false_special_case_test.rb +15 -17
- data/test/spec/api/helper/typing_test.rb +27 -26
- data/test/spec/api/mocks/mock_arg_constraints_test.rb +1 -1
- data/test/spec/api/mocks/mock_test.rb +45 -11
- data/test/spec/api/mocks/null_object_test.rb +3 -3
- data/test/spec/runner/context_matching_test.rb +2 -2
- data/test/spec/runner/formatter/failure_dump_test.rb +94 -0
- data/test/spec/runner/formatter/html_formatter_test.rb +48 -0
- data/test/spec/runner/formatter/progress_bar_formatter_test.rb +56 -0
- data/test/spec/runner/formatter/rdoc_formatter_test.rb +51 -0
- data/test/spec/runner/formatter/specdoc_formatter_test.rb +57 -0
- data/test/spec/runner/kernel_ext_test.rb +1 -1
- data/test/spec/runner/option_parser_test.rb +22 -12
- data/test/spec/runner/reporter_test.rb +1 -1
- data/test/test_classes.rb +7 -7
- metadata +19 -14
- data/lib/spec/runner/base_text_formatter.rb +0 -77
- data/lib/spec/runner/html_formatter.rb +0 -153
- data/lib/spec/runner/progress_bar_formatter.rb +0 -25
- data/lib/spec/runner/rdoc_formatter.rb +0 -20
- data/lib/spec/runner/specdoc_formatter.rb +0 -20
- data/test/spec/runner/failure_dump_test.rb +0 -92
- data/test/spec/runner/html_formatter_test.rb +0 -47
- data/test/spec/runner/progress_bar_formatter_test.rb +0 -54
- data/test/spec/runner/rdoc_formatter_test.rb +0 -50
- 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
|
6
|
+
class ShouldMatchTest < Test::Unit::TestCase
|
7
7
|
|
8
|
-
|
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
|
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
|
-
|
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
|
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
|
6
|
+
class ShouldThrowTest < Test::Unit::TestCase
|
7
7
|
|
8
|
-
|
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
|
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
|
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
|
-
|
27
|
+
class ShouldNotThrowTest < Test::Unit::TestCase
|
29
28
|
|
30
|
-
def
|
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
|
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
|
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
|
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
|
6
|
+
class ShouldBeTrueTest < Test::Unit::TestCase
|
7
7
|
|
8
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
6
|
+
class ShouldBeAnInstanceOfTest < Test::Unit::TestCase
|
7
7
|
|
8
|
-
|
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
|
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
|
-
|
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
|
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
|
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
|
-
|
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
|
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
|
-
|
57
|
+
class ShouldNotBeAKindOfTest < Test::Unit::TestCase
|
57
58
|
|
58
|
-
def
|
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
|
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
|
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
|
-
|
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
|
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
|
-
|
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
|
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
|
@@ -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([
|
90
|
-
assert_equal(
|
91
|
-
assert_equal(
|
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([
|
97
|
-
assert_equal(
|
98
|
-
assert_equal(
|
99
|
-
assert_equal(
|
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
|
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
|
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
|
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
|
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
|
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
|