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
@@ -0,0 +1,27 @@
|
|
1
|
+
module Spec
|
2
|
+
module Runner
|
3
|
+
module Formatter
|
4
|
+
class ProgressBarFormatter < BaseTextFormatter
|
5
|
+
def add_context(name, first)
|
6
|
+
@output << "\n" if first
|
7
|
+
@output.flush
|
8
|
+
end
|
9
|
+
|
10
|
+
def spec_failed(name, counter, failure)
|
11
|
+
@output << 'F'
|
12
|
+
@output.flush
|
13
|
+
end
|
14
|
+
|
15
|
+
def spec_passed(name)
|
16
|
+
@output << '.'
|
17
|
+
@output.flush
|
18
|
+
end
|
19
|
+
|
20
|
+
def start_dump
|
21
|
+
@output << "\n"
|
22
|
+
@output.flush
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Spec
|
2
|
+
module Runner
|
3
|
+
module Formatter
|
4
|
+
class RdocFormatter < BaseTextFormatter
|
5
|
+
def add_context(name, first)
|
6
|
+
@output << "# #{name}\n"
|
7
|
+
@output.flush
|
8
|
+
end
|
9
|
+
|
10
|
+
def spec_passed(name)
|
11
|
+
@output << "# * #{name}\n"
|
12
|
+
@output.flush
|
13
|
+
end
|
14
|
+
|
15
|
+
def spec_failed(name, counter, failure)
|
16
|
+
@output << "# * #{name} [#{counter} - FAILED]\n"
|
17
|
+
@output.flush
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Spec
|
2
|
+
module Runner
|
3
|
+
module Formatter
|
4
|
+
class SpecdocFormatter < BaseTextFormatter
|
5
|
+
def add_context(name, first)
|
6
|
+
@output << "\n#{name}\n"
|
7
|
+
@output.flush
|
8
|
+
end
|
9
|
+
|
10
|
+
def spec_failed(name, counter, failure)
|
11
|
+
@output << "- #{name} (FAILED - #{counter})\n"
|
12
|
+
@output.flush
|
13
|
+
end
|
14
|
+
|
15
|
+
def spec_passed(name)
|
16
|
+
@output << "- #{name}\n"
|
17
|
+
@output.flush
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -16,7 +16,7 @@ module Spec
|
|
16
16
|
def self.parse(args, standalone, err, out)
|
17
17
|
options = OpenStruct.new
|
18
18
|
options.out = out
|
19
|
-
options.formatter_type = ProgressBarFormatter
|
19
|
+
options.formatter_type = Formatter::ProgressBarFormatter
|
20
20
|
options.backtrace_tweaker = QuietBacktraceTweaker.new
|
21
21
|
options.spec_name = nil
|
22
22
|
|
@@ -24,25 +24,24 @@ module Spec
|
|
24
24
|
opts.banner = "Usage: spec [options] (FILE|DIRECTORY|GLOB)+"
|
25
25
|
opts.separator ""
|
26
26
|
|
27
|
-
opts.on("
|
28
|
-
|
27
|
+
opts.on("--diff", "Show unified diff of Strings that are expected to be equal when they are not") do
|
28
|
+
require 'spec/api/helper/diff'
|
29
29
|
end
|
30
30
|
|
31
|
-
opts.on("-
|
32
|
-
|
33
|
-
require req
|
31
|
+
opts.on("-s", "--spec SPECIFICATION_NAME", "Execute a single specification") do |spec_name|
|
32
|
+
options.spec_name = spec_name
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
opts.on("-f", "--format FORMAT", "Builtin formats: specdoc|s|rdoc|r|html|h",
|
37
36
|
"You can also specify a custom formatter class",
|
38
37
|
"(in which case you should also specify --require)") do |format|
|
39
38
|
case format
|
40
39
|
when 'specdoc', 's'
|
41
|
-
options.formatter_type = SpecdocFormatter
|
40
|
+
options.formatter_type = Formatter::SpecdocFormatter
|
42
41
|
when 'html', 'h'
|
43
|
-
options.formatter_type = HtmlFormatter
|
42
|
+
options.formatter_type = Formatter::HtmlFormatter
|
44
43
|
when 'rdoc', 'r'
|
45
|
-
options.formatter_type = RdocFormatter
|
44
|
+
options.formatter_type = Formatter::RdocFormatter
|
46
45
|
options.dry_run = true
|
47
46
|
else
|
48
47
|
begin
|
@@ -55,18 +54,19 @@ module Spec
|
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
|
-
opts.on("-
|
59
|
-
|
57
|
+
opts.on("-r", "--require FILE", "Require FILE before running specs",
|
58
|
+
"Useful for loading custom formatters or other extensions") do |req|
|
59
|
+
require req
|
60
60
|
end
|
61
61
|
|
62
|
-
opts.on("--
|
63
|
-
|
62
|
+
opts.on("-b", "--backtrace", "Output full backtrace") do
|
63
|
+
options.backtrace_tweaker = NoisyBacktraceTweaker.new
|
64
64
|
end
|
65
65
|
|
66
|
-
opts.on("-
|
67
|
-
options.
|
66
|
+
opts.on("-d", "--dry-run", "Don't execute specs") do
|
67
|
+
options.dry_run = true
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
opts.on("-v", "--version", "Show version") do
|
71
71
|
out.puts ::Spec::VERSION::DESCRIPTION
|
72
72
|
exit if out == $stdout
|
data/lib/spec/runner/reporter.rb
CHANGED
data/lib/spec/version.rb
CHANGED
@@ -6,102 +6,102 @@ module Spec
|
|
6
6
|
|
7
7
|
class ArbitraryPredicateTest < Test::Unit::TestCase
|
8
8
|
|
9
|
-
# should.be.
|
9
|
+
# should.be.funny
|
10
10
|
|
11
|
-
def
|
11
|
+
def test_should_be_funny_should_raise_when_target_doesnt_understand_funny
|
12
12
|
assert_raise(NoMethodError) do
|
13
|
-
5.should.be.
|
13
|
+
5.should.be.funny
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
mock =
|
17
|
+
def test_should_be_funny_should_raise_when_sending_funny_to_target_returns_false
|
18
|
+
mock = HandCodedMock.new(false)
|
19
19
|
assert_raise(ExpectationNotMetError) do
|
20
|
-
mock.should.be.
|
20
|
+
mock.should.be.funny
|
21
21
|
end
|
22
22
|
mock.__verify
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
mock =
|
25
|
+
def test_should_be_funny_should_raise_when_sending_funny_to_target_returns_nil
|
26
|
+
mock = HandCodedMock.new(nil)
|
27
27
|
assert_raise(ExpectationNotMetError) do
|
28
|
-
mock.should.be.
|
28
|
+
mock.should.be.funny
|
29
29
|
end
|
30
30
|
mock.__verify
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
mock =
|
33
|
+
def test_should_be_funny_should_not_raise_when_sending_funny_to_target_returns_true
|
34
|
+
mock = HandCodedMock.new(true)
|
35
35
|
assert_nothing_raised do
|
36
|
-
mock.should.be.
|
36
|
+
mock.should.be.funny
|
37
37
|
end
|
38
38
|
mock.__verify
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
42
|
-
mock =
|
41
|
+
def test_should_be_funny_should_not_raise_when_sending_funny_to_target_returns_something_other_than_true_false_or_nil
|
42
|
+
mock = HandCodedMock.new(5)
|
43
43
|
assert_nothing_raised do
|
44
|
-
mock.should.be.
|
44
|
+
mock.should.be.funny
|
45
45
|
end
|
46
46
|
mock.__verify
|
47
47
|
end
|
48
48
|
|
49
|
-
# should.be.
|
49
|
+
# should.be.funny(args)
|
50
50
|
|
51
|
-
def
|
52
|
-
mock =
|
51
|
+
def test_should_be_funny_with_args_passes_args_properly
|
52
|
+
mock = HandCodedMock.new(true)
|
53
53
|
assert_nothing_raised do
|
54
|
-
mock.should.be.
|
54
|
+
mock.should.be.hungry(1, 2, 3)
|
55
55
|
end
|
56
56
|
mock.__verify
|
57
57
|
end
|
58
58
|
|
59
|
-
# should.not.be.
|
59
|
+
# should.not.be.funny
|
60
60
|
|
61
|
-
def
|
61
|
+
def test_should_not_be_funny_should_raise_when_target_doesnt_understand_funny
|
62
62
|
assert_raise(NoMethodError) do
|
63
|
-
5.should.not.be.
|
63
|
+
5.should.not.be.funny
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
def
|
68
|
-
mock =
|
67
|
+
def test_should_not_be_funny_should_raise_when_sending_funny_to_target_returns_true
|
68
|
+
mock = HandCodedMock.new(true)
|
69
69
|
assert_raise(ExpectationNotMetError) do
|
70
|
-
mock.should.not.be.
|
70
|
+
mock.should.not.be.funny
|
71
71
|
end
|
72
72
|
mock.__verify
|
73
73
|
end
|
74
74
|
|
75
|
-
def
|
76
|
-
mock =
|
75
|
+
def test_should_not_be_funny_shouldnt_raise_when_sending_funny_to_target_returns_nil
|
76
|
+
mock = HandCodedMock.new(nil)
|
77
77
|
assert_nothing_raised do
|
78
|
-
mock.should.not.be.
|
78
|
+
mock.should.not.be.funny
|
79
79
|
end
|
80
80
|
mock.__verify
|
81
81
|
end
|
82
82
|
|
83
|
-
def
|
84
|
-
mock =
|
83
|
+
def test_should_not_be_funny_shouldnt_raise_when_sending_funny_to_target_returns_false
|
84
|
+
mock = HandCodedMock.new(false)
|
85
85
|
assert_nothing_raised do
|
86
|
-
mock.should.not.be.
|
86
|
+
mock.should.not.be.funny
|
87
87
|
end
|
88
88
|
mock.__verify
|
89
89
|
end
|
90
90
|
|
91
|
-
def
|
92
|
-
mock =
|
91
|
+
def test_should_not_be_funny_should_raise_when_sending_funny_to_target_returns_something_other_than_true_false_or_nil
|
92
|
+
mock = HandCodedMock.new(5)
|
93
93
|
assert_raise(ExpectationNotMetError) do
|
94
|
-
mock.should.not.be.
|
94
|
+
mock.should.not.be.funny
|
95
95
|
end
|
96
96
|
mock.__verify
|
97
97
|
end
|
98
98
|
|
99
|
-
# should.be.
|
99
|
+
# should.be.funny(args)
|
100
100
|
|
101
|
-
def
|
102
|
-
mock =
|
101
|
+
def test_should_not_be_funny_with_args_passes_args_properly
|
102
|
+
mock = HandCodedMock.new(false)
|
103
103
|
assert_nothing_raised do
|
104
|
-
mock.should.not.be.
|
104
|
+
mock.should.not.be.hungry(1, 2, 3)
|
105
105
|
end
|
106
106
|
mock.__verify
|
107
107
|
end
|
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Spec
|
4
4
|
module Api
|
5
5
|
module Helper
|
6
|
-
class
|
6
|
+
class ShouldBeTest < Test::Unit::TestCase
|
7
7
|
|
8
8
|
def setup
|
9
9
|
@dummy = 'dummy'
|
@@ -12,51 +12,58 @@ module Spec
|
|
12
12
|
@nil_var = nil
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def test_should_not_raise_when_objects_are_same
|
16
16
|
assert_nothing_raised do
|
17
17
|
@dummy.should.be @dummy
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def test_should_raise_when_objects_are_not_same
|
22
22
|
assert_raise(ExpectationNotMetError) do
|
23
23
|
@dummy.should.be @equal_dummy
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def test_should_not_raise_when_both_objects_are_nil
|
28
28
|
assert_nothing_raised do
|
29
29
|
@nil_var.should.be nil
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
33
|
+
def test_should_raise_when_object_is_not_nil
|
34
34
|
assert_raise(ExpectationNotMetError) do
|
35
35
|
@dummy.should.be nil
|
36
36
|
end
|
37
37
|
end
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
+
class ShouldNotBeTest < Test::Unit::TestCase
|
41
|
+
def setup
|
42
|
+
@dummy = 'dummy'
|
43
|
+
@equal_dummy = 'dummy'
|
44
|
+
@another_dummy = 'another_dummy'
|
45
|
+
@nil_var = nil
|
46
|
+
end
|
40
47
|
|
41
|
-
def
|
48
|
+
def test_should_not_raise_when_objects_are_not_same
|
42
49
|
assert_nothing_raised do
|
43
50
|
@dummy.should.not.be @equal_dummy
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
47
|
-
def
|
54
|
+
def test_should_raise_when_objects_are_same
|
48
55
|
assert_raise(ExpectationNotMetError) do
|
49
56
|
@dummy.should.not.be @dummy
|
50
57
|
end
|
51
58
|
end
|
52
59
|
|
53
|
-
def
|
60
|
+
def test_should_not_raise_when_left_is_not_nil_and_right_is_nil
|
54
61
|
assert_nothing_raised do
|
55
62
|
@dummy.should.not.be nil
|
56
63
|
end
|
57
64
|
end
|
58
65
|
|
59
|
-
def
|
66
|
+
def test_should_raise_when_both_objects_are_nil
|
60
67
|
assert_raise(ExpectationNotMetError) do
|
61
68
|
@nil_var.should.not.be nil
|
62
69
|
end
|
@@ -3,52 +3,38 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Spec
|
4
4
|
module Api
|
5
5
|
module Helper
|
6
|
-
class
|
6
|
+
class ShouldEqualTest < Test::Unit::TestCase
|
7
7
|
|
8
|
-
def
|
9
|
-
@dummy = 'dummy'
|
10
|
-
@equal_dummy = 'dummy'
|
11
|
-
@another_dummy = 'another_dummy'
|
12
|
-
@nil_var = nil
|
13
|
-
end
|
14
|
-
|
15
|
-
# should.equal
|
16
|
-
|
17
|
-
def test_should_equal_should_not_raise_when_objects_are_equal
|
8
|
+
def test_should_not_raise_when_objects_are_equal
|
18
9
|
assert_nothing_raised do
|
19
|
-
|
10
|
+
'apple'.should.equal 'apple'
|
20
11
|
end
|
21
12
|
end
|
22
13
|
|
23
|
-
def
|
14
|
+
def test_should_raise_when_objects_are_not_equal
|
24
15
|
assert_raise(ExpectationNotMetError) do
|
25
|
-
|
16
|
+
'apple'.should.equal 'orange'
|
26
17
|
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_should_raise_nice_message
|
30
|
-
begin
|
31
|
-
"foo\nbar\nzap".should_equal "foo\nzap\nbar"
|
32
|
-
rescue ExpectationNotMetError => e
|
33
|
-
assert_equal "\"foo\\nbar\\nzap\" should equal \"foo\\nzap\\nbar\"", e.message
|
34
|
-
end
|
35
|
-
end
|
18
|
+
end
|
19
|
+
end
|
36
20
|
|
37
|
-
|
21
|
+
class ShouldNotEqualTest < Test::Unit::TestCase
|
38
22
|
|
39
|
-
def
|
23
|
+
def test_should_not_raise_when_objects_are_not_equal
|
40
24
|
assert_nothing_raised do
|
41
|
-
|
25
|
+
'apple'.should.not.equal 'orange'
|
42
26
|
end
|
43
27
|
end
|
44
28
|
|
45
29
|
def test_should_not_equal_should_raise_when_objects_are_equal
|
46
30
|
assert_raise(ExpectationNotMetError) do
|
47
|
-
|
31
|
+
'apple'.should.not.equal 'apple'
|
48
32
|
end
|
49
33
|
end
|
34
|
+
end
|
50
35
|
|
51
|
-
|
36
|
+
class ShouldBeCloseTest < Test::Unit::TestCase
|
37
|
+
def test_should_not_raise_when_values_are_within_bounds
|
52
38
|
assert_nothing_raised do
|
53
39
|
3.5.should.be.close 3.5, 0.5
|
54
40
|
3.5.should.be.close 3.1, 0.5
|
@@ -58,7 +44,7 @@ module Spec
|
|
58
44
|
end
|
59
45
|
end
|
60
46
|
|
61
|
-
def
|
47
|
+
def test_should_raise_when_values_are_outside_bounds
|
62
48
|
assert_raise(ExpectationNotMetError) do
|
63
49
|
3.5.should.be.close 3.0, 0.5
|
64
50
|
end
|