rspec 0.1.4 → 0.1.5
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 +4 -0
- data/Rakefile.rb +5 -1
- data/examples/craps.rb +15 -0
- data/examples/craps_spec.rb +110 -0
- data/examples/movie.rb +7 -0
- data/examples/movie_list.rb +19 -0
- data/examples/movie_spec.rb +43 -0
- data/lib/spec/context.rb +0 -1
- data/test/context_fixtures_test.rb +71 -0
- data/test/context_run_test.rb +174 -0
- data/test/error_reporting_test.rb +271 -0
- data/test/expectations_test.rb +399 -0
- data/test/mock_test.rb +77 -0
- data/test/rspec_test.rb +35 -0
- data/test/spec_collection_test.rb +39 -0
- data/test/specification_identification_test.rb +71 -0
- data/test/test_unit_ext_spec.rb +9 -0
- data/test/text_runner_test.rb +111 -0
- metadata +20 -3
data/CHANGES
CHANGED
data/Rakefile.rb
CHANGED
@@ -19,11 +19,13 @@ PKG_NAME = "rspec"
|
|
19
19
|
# (This is subject to change - AH)
|
20
20
|
#
|
21
21
|
# REMEMBER TO KEEP PKG_VERSION IN SYNC WITH CHANGELOG
|
22
|
-
PKG_VERSION = "0.1.
|
22
|
+
PKG_VERSION = "0.1.5"
|
23
23
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
24
24
|
PKG_FILES = FileList[
|
25
25
|
'[A-Z]*',
|
26
26
|
'lib/**/*.rb',
|
27
|
+
'test/**/*.rb',
|
28
|
+
'examples/**/*.rb',
|
27
29
|
'doc/**/*'
|
28
30
|
]
|
29
31
|
|
@@ -74,6 +76,8 @@ spec = Gem::Specification.new do |s|
|
|
74
76
|
'--title' << 'RSpec' <<
|
75
77
|
'--main' << 'README' <<
|
76
78
|
'--line-numbers'
|
79
|
+
|
80
|
+
s.test_files = Dir.glob('test/tc_*.rb')
|
77
81
|
|
78
82
|
#### Author and project details.
|
79
83
|
|
data/examples/craps.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec'
|
2
|
+
require 'craps'
|
3
|
+
|
4
|
+
class CrapsSpecification < Spec::Context
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@die1 = Mock.new
|
8
|
+
@die2 = Mock.new
|
9
|
+
@game = Craps.new(@die1, @die2)
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
@die1.__verify
|
14
|
+
@die2.__verify
|
15
|
+
end
|
16
|
+
|
17
|
+
# coming out roll of 7
|
18
|
+
|
19
|
+
def come_out_roll_of_1_6_wins
|
20
|
+
_load_dice([1], [6])
|
21
|
+
@game.play.should_be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
def come_out_roll_of_2_5_wins
|
25
|
+
_load_dice([2], [5])
|
26
|
+
@game.play.should_be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
def come_out_roll_of_3_4_wins
|
30
|
+
_load_dice([3], [4])
|
31
|
+
@game.play.should_be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
def come_out_roll_of_4_3_wins
|
35
|
+
_load_dice([4], [3])
|
36
|
+
@game.play.should_be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
def come_out_roll_of_5_2_wins
|
40
|
+
_load_dice([5], [2])
|
41
|
+
@game.play.should_be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
def come_out_roll_of_6_1_wins
|
45
|
+
_load_dice([6], [1])
|
46
|
+
@game.play.should_be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
# coming out roll of 11
|
50
|
+
|
51
|
+
def come_out_roll_of_5_6_wins
|
52
|
+
_load_dice([5], [6])
|
53
|
+
@game.play.should_be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
def come_out_roll_of_6_5_wins
|
57
|
+
_load_dice([6], [5])
|
58
|
+
@game.play.should_be_true
|
59
|
+
end
|
60
|
+
|
61
|
+
# coming out roll of 2
|
62
|
+
|
63
|
+
def come_out_roll_of_1_1_looses
|
64
|
+
_load_dice([1], [1])
|
65
|
+
@game.play.should_be_false
|
66
|
+
end
|
67
|
+
|
68
|
+
# coming out roll of 3
|
69
|
+
|
70
|
+
def come_out_roll_of_1_2_looses
|
71
|
+
_load_dice([1], [2])
|
72
|
+
@game.play.should_be_false
|
73
|
+
end
|
74
|
+
|
75
|
+
def come_out_roll_of_2_1_looses
|
76
|
+
_load_dice([2], [1])
|
77
|
+
@game.play.should_be_false
|
78
|
+
end
|
79
|
+
|
80
|
+
# coming out roll of 12
|
81
|
+
|
82
|
+
def come_out_roll_of_6_6_looses
|
83
|
+
_load_dice([6], [6])
|
84
|
+
@game.play.should_be_false
|
85
|
+
end
|
86
|
+
|
87
|
+
# loosing with a point
|
88
|
+
|
89
|
+
# def second_roll_of_7_looses
|
90
|
+
# _load_dice([2, 4], [2, 3])
|
91
|
+
# @game.play.should_be_false
|
92
|
+
# end
|
93
|
+
|
94
|
+
# support
|
95
|
+
|
96
|
+
def _load_dice(rolls1, rolls2)
|
97
|
+
_load_die(@die1, rolls1)
|
98
|
+
_load_die(@die2, rolls2)
|
99
|
+
end
|
100
|
+
|
101
|
+
def _load_die(die, rolls)
|
102
|
+
rolls.each {| each | die.__expects(:roll).once.with_no_args.returns(each) }
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
if __FILE__ == $0
|
108
|
+
runner = Spec::TextRunner.new($stdout)
|
109
|
+
runner.run(CrapsSpecification)
|
110
|
+
end
|
data/examples/movie.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
class MovieList
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
@movies = Hash.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def size
|
8
|
+
@movies.size
|
9
|
+
end
|
10
|
+
|
11
|
+
def add (movieToAdd)
|
12
|
+
@movies.store(movieToAdd.name, movieToAdd)
|
13
|
+
end
|
14
|
+
|
15
|
+
def include? (aName)
|
16
|
+
@movies.include?(aName)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec'
|
2
|
+
require 'movie'
|
3
|
+
require 'movie_list'
|
4
|
+
|
5
|
+
class EmptyMovieList < Spec::Context
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@list = MovieList.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def should_have_size_of_0
|
12
|
+
@list.size.should_equal 0
|
13
|
+
end
|
14
|
+
|
15
|
+
def should_not_include_star_wars
|
16
|
+
@list.should_not_include "Star Wars"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class OneMovieList < Spec::Context
|
22
|
+
|
23
|
+
def setup
|
24
|
+
@list = MovieList.new
|
25
|
+
star_wars = Movie.new "Star Wars"
|
26
|
+
@list.add star_wars
|
27
|
+
end
|
28
|
+
|
29
|
+
def should_have_size_of_1
|
30
|
+
@list.size.should_equal 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def should_include_star_wars
|
34
|
+
@list.should_include "Star Wars"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
if __FILE__ == $0
|
40
|
+
runner = Spec::TextRunner.new($stdout)
|
41
|
+
runner.run(EmptyMovieList)
|
42
|
+
runner.run(OneMovieList)
|
43
|
+
end
|
data/lib/spec/context.rb
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require 'spec'
|
4
|
+
|
5
|
+
|
6
|
+
class FixtureTestingContext < Spec::Context
|
7
|
+
|
8
|
+
@setup_called = false
|
9
|
+
@spec_called = false
|
10
|
+
@teardown_called = false
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@setup_called = true
|
14
|
+
end
|
15
|
+
|
16
|
+
def verify_setup
|
17
|
+
@setup_called
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
@teardown_called = true
|
22
|
+
end
|
23
|
+
|
24
|
+
def verify_teardown
|
25
|
+
@teardown_called
|
26
|
+
end
|
27
|
+
|
28
|
+
def specification
|
29
|
+
@spec_called = true
|
30
|
+
end
|
31
|
+
|
32
|
+
def verify_spec
|
33
|
+
@spec_called
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
class NullResultListener
|
40
|
+
|
41
|
+
def pass(spec)
|
42
|
+
end
|
43
|
+
|
44
|
+
def failure(spec)
|
45
|
+
end
|
46
|
+
|
47
|
+
def error(spec)
|
48
|
+
end
|
49
|
+
|
50
|
+
def spec(spec)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
class ContextFixturesTest < Test::Unit::TestCase
|
57
|
+
|
58
|
+
def setup
|
59
|
+
@fixture_testing_context = FixtureTestingContext.new(:specification)
|
60
|
+
@fixture_testing_context.run(NullResultListener.new)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_should_run_setup_before
|
64
|
+
@fixture_testing_context.verify_setup
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_should_run_teardown_after
|
68
|
+
@fixture_testing_context.verify_teardown
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require 'spec'
|
4
|
+
|
5
|
+
|
6
|
+
class TestCon < Spec::Context
|
7
|
+
|
8
|
+
def empty_specification
|
9
|
+
end
|
10
|
+
|
11
|
+
def passing_once_specification
|
12
|
+
true.should_equal(true)
|
13
|
+
end
|
14
|
+
|
15
|
+
def failing_once_specification
|
16
|
+
false.should_equal(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
def erroring_once_specification
|
20
|
+
undefined_method.should_equal(true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def passing_multi_specification
|
24
|
+
true.should_equal(true)
|
25
|
+
false.should_equal(false)
|
26
|
+
Object.should_equal(Object)
|
27
|
+
end
|
28
|
+
|
29
|
+
def failing_multi_specification
|
30
|
+
false.should_equal(true)
|
31
|
+
true.should_equal(false)
|
32
|
+
false.should_equal(nil)
|
33
|
+
end
|
34
|
+
|
35
|
+
def erroring_multi_specification
|
36
|
+
undefined_method.should_equal(false)
|
37
|
+
undefined_method.should_not_equal(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
class MockResultListener
|
44
|
+
|
45
|
+
def initialize
|
46
|
+
@pass_count = 0
|
47
|
+
@failure_count = 0
|
48
|
+
@spec_count = 0
|
49
|
+
end
|
50
|
+
|
51
|
+
def pass(spec)
|
52
|
+
@pass_count += 1
|
53
|
+
end
|
54
|
+
|
55
|
+
def failure(spec, exception)
|
56
|
+
@failure_count += 1
|
57
|
+
end
|
58
|
+
|
59
|
+
def spec(spec)
|
60
|
+
@spec_count += 1
|
61
|
+
end
|
62
|
+
|
63
|
+
def verify_failures(count)
|
64
|
+
check(count, @failure_count)
|
65
|
+
end
|
66
|
+
|
67
|
+
def verify_passes(count)
|
68
|
+
check(count, @pass_count)
|
69
|
+
end
|
70
|
+
|
71
|
+
def verify_specs(count)
|
72
|
+
check(count, @spec_count)
|
73
|
+
end
|
74
|
+
|
75
|
+
def check(expected, actual)
|
76
|
+
if (expected != actual)
|
77
|
+
raise Test::Unit::AssertionFailedError.new("expected: " + expected.to_s + " actual: " + actual.to_s)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
class ContextRunPassingOnceTest < Test::Unit::TestCase
|
85
|
+
|
86
|
+
def setup
|
87
|
+
@context = TestCon.new(:passing_once_specification)
|
88
|
+
@result_listener = MockResultListener.new
|
89
|
+
@context.run(@result_listener)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_should_have_one_pass
|
93
|
+
@result_listener.verify_passes(1)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_should_have_no_failures
|
97
|
+
@result_listener.verify_failures(0)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_should_have_one_expectation
|
101
|
+
@result_listener.verify_specs(1)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
class ContextRunFailingOnceTest < Test::Unit::TestCase
|
108
|
+
|
109
|
+
def setup
|
110
|
+
@context = TestCon.new(:failing_once_specification)
|
111
|
+
@result_listener = MockResultListener.new
|
112
|
+
@context.run(@result_listener)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_should_have_one_failure
|
116
|
+
@result_listener.verify_failures(1)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_should_have_no_passes
|
120
|
+
@result_listener.verify_passes(0)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_should_have_one_expectation
|
124
|
+
@result_listener.verify_specs(1)
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
class ContextRunErroringTest < Test::Unit::TestCase
|
131
|
+
|
132
|
+
def setup
|
133
|
+
@context = TestCon.new(:erroring_once_specification)
|
134
|
+
@result_listener = MockResultListener.new
|
135
|
+
@context.run(@result_listener)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_should_have_one_failures
|
139
|
+
@result_listener.verify_failures(1)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_should_have_no_passes
|
143
|
+
@result_listener.verify_passes(0)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_should_have_one_spec
|
147
|
+
@result_listener.verify_specs(1);
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
class ContextRunFailingMultipleTest <Test::Unit::TestCase
|
154
|
+
|
155
|
+
def test_should_have_one_expectation
|
156
|
+
@context = TestCon.new(:failing_multi_specification)
|
157
|
+
@result_listener = MockResultListener.new
|
158
|
+
@context.run(@result_listener)
|
159
|
+
@result_listener.verify_specs(1)
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
class ContextRunErroringMultipleTest < Test::Unit::TestCase
|
166
|
+
|
167
|
+
def test_should_have_no_expectations
|
168
|
+
@context = TestCon.new(:erroring_multi_specification)
|
169
|
+
@result_listener = MockResultListener.new
|
170
|
+
@context.run(@result_listener)
|
171
|
+
@result_listener.verify_specs(1)
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|