rspec 0.5.16 → 0.6.0
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 +12 -0
- data/EXAMPLES.rd +2 -2
- data/examples/custom_method_spec.rb +2 -2
- data/examples/mocking_spec.rb +2 -2
- data/lib/spec/api/helper.rb +0 -6
- data/lib/spec/api/helper/diff.rb +1 -0
- data/lib/spec/api/helper/have_helper.rb +7 -23
- data/lib/spec/api/helper/should_helper.rb +23 -19
- data/lib/spec/api/helper/should_negator.rb +10 -18
- data/lib/spec/api/mocks/argument_expectation.rb +2 -2
- data/lib/spec/api/mocks/message_expectation.rb +28 -53
- data/lib/spec/api/mocks/mock.rb +4 -5
- data/lib/spec/api/sugar.rb +6 -23
- data/lib/spec/runner/instance_exec.rb +11 -5
- data/lib/spec/version.rb +2 -2
- data/test/spec/api/helper/arbitrary_predicate_test.rb +16 -16
- data/test/spec/api/helper/containment_test.rb +16 -16
- data/test/spec/api/helper/identity_test.rb +8 -8
- data/test/spec/api/helper/object_equality_test.rb +13 -13
- data/test/spec/api/helper/raising_test.rb +14 -14
- data/test/spec/api/helper/regex_matching_test.rb +4 -4
- data/test/spec/api/helper/should_have_test.rb +26 -20
- data/test/spec/api/helper/should_satisfy_test.rb +5 -5
- data/test/spec/api/helper/throwing_test.rb +7 -7
- data/test/spec/api/helper/true_false_special_case_test.rb +12 -12
- data/test/spec/api/helper/typing_test.rb +14 -14
- data/test/spec/api/mocks/mock_arg_constraints_test.rb +26 -20
- data/test/spec/api/mocks/mock_counts_test.rb +431 -0
- data/test/spec/api/mocks/mock_ordering_test.rb +61 -42
- data/test/spec/api/mocks/mock_test.rb +68 -230
- data/test/spec/api/sugar_test.rb +1 -1
- data/test/spec/runner/backtrace_tweaker_test.rb +2 -2
- data/test/spec/runner/context_runner_test.rb +4 -4
- data/test/spec/runner/context_test.rb +22 -22
- data/test/spec/runner/execution_context_test.rb +1 -1
- data/test/spec/runner/reporter_test.rb +6 -6
- data/test/spec/runner/specification_test.rb +30 -30
- data/test/test_classes.rb +13 -4
- metadata +6 -11
- data/lib/spec/api/helper/instance_helper.rb +0 -15
- data/lib/spec/api/helper/instance_negator.rb +0 -15
- data/lib/spec/api/helper/kind_helper.rb +0 -15
- data/lib/spec/api/helper/kind_negator.rb +0 -15
- data/lib/spec/api/helper/respond_helper.rb +0 -15
- data/lib/spec/api/helper/respond_negator.rb +0 -15
- data/test/spec/api/duck_type_test.rb +0 -19
@@ -9,28 +9,79 @@ module Spec
|
|
9
9
|
@mock = Mock.new("test mock")
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
@mock.
|
14
|
-
@mock.
|
12
|
+
def test_should_pass_two_calls_in_order
|
13
|
+
@mock.should_receive(:one).ordered
|
14
|
+
@mock.should_receive(:two).ordered
|
15
15
|
@mock.one
|
16
16
|
@mock.two
|
17
17
|
@mock.__verify
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
@mock.
|
22
|
-
@mock.
|
20
|
+
def test_should_pass_three_calls_in_order
|
21
|
+
@mock.should_receive(:one).ordered
|
22
|
+
@mock.should_receive(:two).ordered
|
23
|
+
@mock.should_receive(:three).ordered
|
24
|
+
@mock.one
|
25
|
+
@mock.two
|
26
|
+
@mock.three
|
27
|
+
@mock.__verify
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_fail_if_second_call_comes_first
|
31
|
+
@mock.should_receive(:one).ordered
|
32
|
+
@mock.should_receive(:two).ordered
|
23
33
|
assert_raise(MockExpectationError) do
|
24
34
|
@mock.two
|
25
35
|
end
|
26
36
|
end
|
37
|
+
|
38
|
+
def test_should_fail_if_third_call_comes_first
|
39
|
+
@mock.should_receive(:one).ordered
|
40
|
+
@mock.should_receive(:two).ordered
|
41
|
+
@mock.should_receive(:three).ordered
|
42
|
+
@mock.one
|
43
|
+
assert_raise(MockExpectationError) do
|
44
|
+
@mock.three
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_should_fail_if_third_call_comes_second
|
49
|
+
@mock.should_receive(:one).ordered
|
50
|
+
@mock.should_receive(:two).ordered
|
51
|
+
@mock.should_receive(:three).ordered
|
52
|
+
@mock.one
|
53
|
+
assert_raise(MockExpectationError) do
|
54
|
+
@mock.one
|
55
|
+
@mock.three
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_should_ignore_order_of_non_ordered_calls
|
60
|
+
@mock.should_receive(:ignored_0)
|
61
|
+
@mock.should_receive(:ordered_1).ordered
|
62
|
+
@mock.should_receive(:ignored_1)
|
63
|
+
@mock.should_receive(:ordered_2).ordered
|
64
|
+
@mock.should_receive(:ignored_2)
|
65
|
+
@mock.should_receive(:ignored_3)
|
66
|
+
@mock.should_receive(:ordered_3).ordered
|
67
|
+
@mock.should_receive(:ignored_4)
|
68
|
+
@mock.ignored_3
|
69
|
+
@mock.ordered_1
|
70
|
+
@mock.ignored_0
|
71
|
+
@mock.ordered_2
|
72
|
+
@mock.ignored_4
|
73
|
+
@mock.ignored_2
|
74
|
+
@mock.ordered_3
|
75
|
+
@mock.ignored_1
|
76
|
+
@mock.__verify
|
77
|
+
end
|
27
78
|
|
28
79
|
def FIXME_test_two_in_order_calls_with_block
|
29
|
-
@mock.
|
80
|
+
@mock.should_receive(:doit).ordered do |a, b|
|
30
81
|
a.should_equal "a1"
|
31
82
|
a.should_equal "b1"
|
32
83
|
end
|
33
|
-
@mock.
|
84
|
+
@mock.should_receive(:doit).ordered do |a, b|
|
34
85
|
a.should_equal "a2"
|
35
86
|
a.should_equal "b2"
|
36
87
|
end
|
@@ -40,11 +91,11 @@ module Spec
|
|
40
91
|
end
|
41
92
|
|
42
93
|
def FIXME_test_two_out_of_order_calls_with_block
|
43
|
-
@mock.
|
94
|
+
@mock.should_receive(:doit).ordered do |a, b|
|
44
95
|
a.should_equal "a1"
|
45
96
|
a.should_equal "b1"
|
46
97
|
end
|
47
|
-
@mock.
|
98
|
+
@mock.should_receive(:doit).ordered do |a, b|
|
48
99
|
a.should_equal "a2"
|
49
100
|
a.should_equal "b2"
|
50
101
|
end
|
@@ -52,38 +103,6 @@ module Spec
|
|
52
103
|
@mock.doit "a1", "b1"
|
53
104
|
@mock.__verify
|
54
105
|
end
|
55
|
-
|
56
|
-
def test_three_linear_calls
|
57
|
-
@mock.should.receive(:one).ordered
|
58
|
-
@mock.should.receive(:two).ordered
|
59
|
-
@mock.should.receive(:three).ordered
|
60
|
-
@mock.one
|
61
|
-
@mock.two
|
62
|
-
@mock.three
|
63
|
-
@mock.__verify
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_three_out_of_order_calls
|
67
|
-
@mock.should.receive(:one).ordered
|
68
|
-
@mock.should.receive(:two).ordered
|
69
|
-
@mock.should.receive(:three).ordered
|
70
|
-
@mock.one
|
71
|
-
assert_raise(MockExpectationError) do
|
72
|
-
@mock.three
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_two_ordered_calls_with_others_between
|
77
|
-
@mock.should.receive(:zero)
|
78
|
-
@mock.should.receive(:one).ordered
|
79
|
-
@mock.should.receive(:two).ordered
|
80
|
-
@mock.should.receive(:one_and_a_half)
|
81
|
-
@mock.one
|
82
|
-
@mock.one_and_a_half
|
83
|
-
@mock.zero
|
84
|
-
@mock.two
|
85
|
-
@mock.__verify
|
86
|
-
end
|
87
106
|
|
88
107
|
end
|
89
108
|
end
|
@@ -2,7 +2,6 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
2
2
|
|
3
3
|
module Spec
|
4
4
|
module Api
|
5
|
-
|
6
5
|
class MockTest < Test::Unit::TestCase
|
7
6
|
|
8
7
|
def setup
|
@@ -10,43 +9,50 @@ module Spec
|
|
10
9
|
end
|
11
10
|
|
12
11
|
def test_should_report_line_number_of_expectation_of_unreceived_message
|
13
|
-
@mock.
|
12
|
+
@mock.should_receive(:wont_happen).with("x", 3)
|
13
|
+
#NOTE - this test is quite ticklish because it specifies that
|
14
|
+
#the above statement appears on line 12 of this file.
|
14
15
|
|
15
16
|
begin
|
16
17
|
@mock.__verify
|
17
18
|
rescue MockExpectationError => e
|
18
|
-
e.backtrace[0].
|
19
|
+
e.backtrace[0].should_match /mock_test\.rb:12:in .test_should_report_line/
|
19
20
|
end
|
20
21
|
|
21
22
|
end
|
23
|
+
|
24
|
+
def test_should_pass_when_not_receiving_message_specified_as_not_to_be_received
|
25
|
+
@mock.should_not_receive(:not_expected)
|
26
|
+
@mock.__verify
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_fail_when_receiving_message_specified_as_not_to_be_received
|
30
|
+
@mock.should_not_receive(:not_expected)
|
31
|
+
assert_raise(MockExpectationError) do
|
32
|
+
@mock.not_expected
|
33
|
+
end
|
34
|
+
end
|
22
35
|
|
23
36
|
def test_should_allow_block_to_calculate_return_values
|
24
|
-
@mock.
|
37
|
+
@mock.should_receive(:random_call).with("a","b","c").and_return { |a,b,c| c+b+a }
|
25
38
|
assert_equal "cba", @mock.random_call("a","b","c")
|
26
39
|
@mock.__verify
|
27
40
|
end
|
28
41
|
|
29
42
|
def test_should_allow_parameter_as_return_value
|
30
|
-
@mock.
|
43
|
+
@mock.should_receive(:random_call).with("a","b","c").and_return("booh")
|
31
44
|
assert_equal "booh", @mock.random_call("a","b","c")
|
32
45
|
@mock.__verify
|
33
46
|
end
|
34
47
|
|
35
48
|
def test_return_nil_if_no_return_value_set
|
36
|
-
@mock.
|
49
|
+
@mock.should_receive(:random_call).with("a","b","c")
|
37
50
|
assert_nil @mock.random_call("a","b","c")
|
38
51
|
@mock.__verify
|
39
52
|
end
|
40
53
|
|
41
|
-
def test_should_test_multiple_calls_to_method_with_same_parameters
|
42
|
-
@mock.should.receive(:random_call).twice.with("a","b","c")
|
43
|
-
@mock.random_call("a","b","c")
|
44
|
-
@mock.random_call("a","b","c")
|
45
|
-
@mock.__verify
|
46
|
-
end
|
47
|
-
|
48
54
|
def test_should_raise_exception_if_parameters_dont_match_when_method_called
|
49
|
-
@mock.
|
55
|
+
@mock.should_receive(:random_call).with("a","b","c").and_return("booh")
|
50
56
|
assert_raise(MockExpectationError) {
|
51
57
|
@mock.random_call("a","d","c")
|
52
58
|
}
|
@@ -58,223 +64,48 @@ module Spec
|
|
58
64
|
}
|
59
65
|
end
|
60
66
|
|
61
|
-
# TODO: rename to should_raise_exception_telling_what_message_was_not_received
|
62
|
-
def test_should_raise_exception_on_verify_if_call_counts_not_as_expected
|
63
|
-
@mock.should.receive(:random_call).twice.with("a","b","c").and.return("booh")
|
64
|
-
@mock.random_call("a","b","c")
|
65
|
-
assert_raise(MockExpectationError) do
|
66
|
-
@mock.__verify
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
67
|
def test_should_use_block_for_expectation_if_provided
|
71
|
-
@mock.
|
72
|
-
a.
|
73
|
-
b.
|
68
|
+
@mock.should_receive(:random_call) do | a, b |
|
69
|
+
a.should_equal "a"
|
70
|
+
b.should_equal "b"
|
74
71
|
"booh"
|
75
72
|
end
|
76
73
|
assert_equal("booh", @mock.random_call("a", "b"))
|
77
74
|
@mock.__verify
|
78
75
|
end
|
79
76
|
|
80
|
-
def
|
81
|
-
@mock.
|
77
|
+
def test_should_fail_if_expectation_block_fails
|
78
|
+
@mock.should_receive(:random_call) {| a | a.should_be true}
|
82
79
|
assert_raise(MockExpectationError) do
|
83
80
|
@mock.random_call false
|
84
81
|
end
|
85
82
|
end
|
86
83
|
|
87
|
-
def
|
88
|
-
@mock.
|
89
|
-
|
90
|
-
assert_equal(12, @mock.multi_call)
|
91
|
-
@mock.__verify
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_repeating_final_return_value
|
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)
|
99
|
-
@mock.__verify
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_should_throw_on_call_of_never_method
|
103
|
-
@mock.should.receive(:random_call).never
|
84
|
+
def test_should_fail_when_method_defined_as_never_is_received
|
85
|
+
@mock.should_receive(:random_call).never
|
86
|
+
#TODO - @mock.should_not_receive(:random_call)
|
104
87
|
assert_raise(MockExpectationError) do
|
105
88
|
@mock.random_call
|
106
89
|
@mock.__verify
|
107
90
|
end
|
108
91
|
end
|
109
|
-
|
110
|
-
def test_should_throw_if_at_least_once_method_not_called
|
111
|
-
@mock.should.receive(:random_call).at.least(:once)
|
112
|
-
assert_raise(MockExpectationError) do
|
113
|
-
@mock.__verify
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_should_not_throw_if_any_number_of_times_method_not_called
|
118
|
-
@mock.should.receive(:random_call).any.number.of.times
|
119
|
-
@mock.__verify
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_should_not_throw_if_any_number_of_times_method_is_called
|
123
|
-
@mock.should.receive(:random_call).any.number.of.times
|
124
|
-
@mock.random_call
|
125
|
-
@mock.__verify
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_should_not_throw_if_at_least_once_method_is_called_twice
|
129
|
-
@mock.should.receive(:random_call).at.least(:once)
|
130
|
-
@mock.random_call
|
131
|
-
@mock.random_call
|
132
|
-
@mock.__verify
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_should_support_mutiple_calls_with_different_args
|
136
|
-
@mock.should.receive(:random_call).once.with(1)
|
137
|
-
@mock.should.receive(:random_call).once.with(2)
|
138
|
-
@mock.random_call(1)
|
139
|
-
@mock.random_call(2)
|
140
|
-
@mock.__verify
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_should_support_multiple_calls_with_different_args_and_counts
|
144
|
-
@mock.should.receive(:random_call).twice.with(1)
|
145
|
-
@mock.should.receive(:random_call).once.with(2)
|
146
|
-
@mock.random_call(1)
|
147
|
-
@mock.random_call(2)
|
148
|
-
@mock.random_call(1)
|
149
|
-
@mock.__verify
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_should_not_throw_if_at_least_twice_method_is_called_twice
|
153
|
-
@mock.should.receive(:random_call).at.least(:twice)
|
154
|
-
@mock.random_call
|
155
|
-
@mock.random_call
|
156
|
-
@mock.__verify
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_should_not_throw_if_at_least_twice_method_is_called_three_times
|
160
|
-
@mock.should.receive(:random_call).at.least(:twice)
|
161
|
-
@mock.random_call
|
162
|
-
@mock.random_call
|
163
|
-
@mock.random_call
|
164
|
-
@mock.__verify
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_should_throw_if_at_least_twice_method_is_called_once
|
168
|
-
@mock.should.receive(:random_call).at.least(:twice)
|
169
|
-
@mock.random_call
|
170
|
-
assert_raise(MockExpectationError) do
|
171
|
-
@mock.__verify
|
172
|
-
end
|
173
|
-
end
|
174
92
|
|
175
|
-
def test_should_throw_if_at_least_twice_method_is_never_called
|
176
|
-
@mock.should.receive(:random_call).at.least(:twice)
|
177
|
-
assert_raise(MockExpectationError) do
|
178
|
-
@mock.__verify
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
def test_should_throw_if_at_least_5_times_method_is_never_called
|
183
|
-
@mock.should.receive(:random_call).at.least(5).times
|
184
|
-
assert_raise(MockExpectationError) do
|
185
|
-
@mock.__verify
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_should_throw_if_at_least_5_times_method_is_called_once
|
190
|
-
@mock.should.receive(:random_call).at.least(5).times
|
191
|
-
@mock.random_call
|
192
|
-
assert_raise(MockExpectationError) do
|
193
|
-
@mock.__verify
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_should_not_throw_if_at_least_5_times_method_is_called_5_times
|
198
|
-
@mock.should.receive(:random_call).at.least(5).times
|
199
|
-
@mock.random_call
|
200
|
-
@mock.random_call
|
201
|
-
@mock.random_call
|
202
|
-
@mock.random_call
|
203
|
-
@mock.random_call
|
204
|
-
@mock.__verify
|
205
|
-
end
|
206
|
-
|
207
|
-
def test_should_not_throw_if_at_least_5_times_method_is_called_6_times
|
208
|
-
@mock.should.receive(:random_call).at.least(5).times
|
209
|
-
@mock.random_call
|
210
|
-
@mock.random_call
|
211
|
-
@mock.random_call
|
212
|
-
@mock.random_call
|
213
|
-
@mock.random_call
|
214
|
-
@mock.random_call
|
215
|
-
@mock.__verify
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_should_raise_if_exactly_3_times_method_is_not_called
|
219
|
-
@mock.should.receive(:random_call).exactly(3).times
|
220
|
-
assert_raise(MockExpectationError) do
|
221
|
-
@mock.__verify
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
def test_should_raise_if_exactly_3_times_method_is_called_once
|
226
|
-
@mock.should.receive(:random_call).exactly(3).times
|
227
|
-
@mock.random_call
|
228
|
-
assert_raise(MockExpectationError) do
|
229
|
-
@mock.__verify
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_should_raise_if_exactly_3_times_method_is_called_twice
|
234
|
-
@mock.should.receive(:random_call).exactly(3).times
|
235
|
-
@mock.random_call
|
236
|
-
@mock.random_call
|
237
|
-
assert_raise(MockExpectationError) do
|
238
|
-
@mock.__verify
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
def test_should_not_raise_if_exactly_3_times_method_is_called_3_times
|
243
|
-
@mock.should.receive(:random_call).exactly(3).times
|
244
|
-
@mock.random_call
|
245
|
-
@mock.random_call
|
246
|
-
@mock.random_call
|
247
|
-
assert_nothing_raised do
|
248
|
-
@mock.__verify
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
def test_should_raise_if_exactly_3_times_method_is_called_4_times
|
253
|
-
@mock.should.receive(:random_call).exactly(3).times
|
254
|
-
@mock.random_call
|
255
|
-
@mock.random_call
|
256
|
-
@mock.random_call
|
257
|
-
assert_nothing_raised do
|
258
|
-
@mock.random_call
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
93
|
def test_should_raise_when_told_to
|
263
|
-
@mock.
|
94
|
+
@mock.should_receive(:random_call).and_raise(RuntimeError)
|
264
95
|
assert_raise(RuntimeError) do
|
265
96
|
@mock.random_call
|
266
97
|
end
|
267
98
|
end
|
268
99
|
|
269
100
|
def test_should_not_raise_when_told_to_if_args_dont_match
|
270
|
-
@mock.
|
101
|
+
@mock.should_receive(:random_call).with(2).and_raise(RuntimeError)
|
271
102
|
assert_raise(MockExpectationError) do
|
272
|
-
@mock.random_call
|
103
|
+
@mock.random_call 1
|
273
104
|
end
|
274
105
|
end
|
275
106
|
|
276
107
|
def test_should_throw_when_told_to
|
277
|
-
@mock.
|
108
|
+
@mock.should_receive(:random_call).and_throw(:blech)
|
278
109
|
assert_throws(:blech) do
|
279
110
|
@mock.random_call
|
280
111
|
end
|
@@ -282,76 +113,76 @@ module Spec
|
|
282
113
|
|
283
114
|
def test_should_raise_when_explicit_return_and_block_constrained
|
284
115
|
assert_raise(AmbiguousReturnError) {
|
285
|
-
@mock.
|
116
|
+
@mock.should_receive(:fruit){|colour|
|
286
117
|
:strawberry
|
287
|
-
}.
|
118
|
+
}.and_return :apple
|
288
119
|
}
|
289
120
|
end
|
290
121
|
|
291
122
|
def TODO_test_should_use_past_tense
|
292
|
-
@mock.
|
123
|
+
@mock.should_have_received(:hello)
|
293
124
|
end
|
294
125
|
|
295
126
|
def TODO_test_should_sent
|
296
|
-
cut.
|
297
|
-
cut.
|
127
|
+
cut.should_have_sent(:hello)
|
128
|
+
cut.should_have_sent(:hello).to(@mock)
|
298
129
|
end
|
299
130
|
|
300
131
|
def test_should_ignore_args_on_any_args
|
301
|
-
@mock.
|
302
|
-
@mock.random_call
|
303
|
-
@mock.random_call
|
304
|
-
@mock.random_call
|
305
|
-
@mock.random_call
|
132
|
+
@mock.should_receive(:random_call).at_least(:once).with(:any_args)
|
133
|
+
@mock.random_call
|
134
|
+
@mock.random_call 1
|
135
|
+
@mock.random_call "a", 2
|
136
|
+
@mock.random_call [], {}, "joe", 7
|
306
137
|
@mock.__verify
|
307
138
|
end
|
308
139
|
|
309
|
-
def
|
310
|
-
@mock.
|
140
|
+
def test_should_fail_on_no_args_if_any_args_received
|
141
|
+
@mock.should_receive(:random_call).with(:no_args)
|
311
142
|
assert_raise(MockExpectationError) do
|
312
|
-
@mock.random_call
|
143
|
+
@mock.random_call 1
|
313
144
|
end
|
314
145
|
end
|
315
146
|
|
316
|
-
def
|
317
|
-
@mock.
|
318
|
-
a
|
319
|
-
@mock.yield_back {|a
|
320
|
-
a.
|
321
|
-
b.should.equal 'zup'
|
147
|
+
def test_should_yield_single_value
|
148
|
+
@mock.should_receive(:yield_back).with(:no_args).once.and_yield(99)
|
149
|
+
a = nil
|
150
|
+
@mock.yield_back {|a|}
|
151
|
+
a.should_equal 99
|
322
152
|
@mock.__verify
|
323
153
|
end
|
324
154
|
|
325
|
-
def
|
326
|
-
@mock.
|
327
|
-
a = nil
|
328
|
-
@mock.yield_back {|a|}
|
329
|
-
a.
|
155
|
+
def test_should_yield_two_values
|
156
|
+
@mock.should_receive(:yield_back).with(:no_args).once.and_yield('wha', 'zup')
|
157
|
+
a, b = nil
|
158
|
+
@mock.yield_back {|a,b|}
|
159
|
+
a.should_equal 'wha'
|
160
|
+
b.should_equal 'zup'
|
330
161
|
@mock.__verify
|
331
162
|
end
|
332
163
|
|
333
164
|
def test_should_fail_when_calling_yielding_method_with_wrong_arity
|
334
|
-
@mock.
|
165
|
+
@mock.should_receive(:yield_back).with(:no_args).once.and_yield('wha', 'zup')
|
335
166
|
assert_raise(MockExpectationError) do
|
336
167
|
@mock.yield_back {|a|}
|
337
168
|
end
|
338
169
|
end
|
339
170
|
|
340
171
|
def test_should_fail_when_calling_yielding_method_without_block
|
341
|
-
@mock.
|
172
|
+
@mock.should_receive(:yield_back).with(:no_args).once.and_yield('wha', 'zup')
|
342
173
|
assert_raise(MockExpectationError) do
|
343
174
|
@mock.yield_back
|
344
175
|
end
|
345
176
|
end
|
346
177
|
|
347
|
-
def
|
348
|
-
@mock.
|
178
|
+
def test_should_be_able_to_mock_send
|
179
|
+
@mock.should_receive(:send).with(:any_args)
|
349
180
|
@mock.send 'hi'
|
350
181
|
@mock.__verify
|
351
182
|
end
|
352
183
|
|
353
184
|
def test_should_be_able_to_raise_from_method_calling_yielding_mock
|
354
|
-
@mock.
|
185
|
+
@mock.should_receive(:yield_me).and_yield 44
|
355
186
|
|
356
187
|
lambda do
|
357
188
|
@mock.yield_me do |x|
|
@@ -362,6 +193,13 @@ module Spec
|
|
362
193
|
@mock.__verify
|
363
194
|
end
|
364
195
|
|
196
|
+
def test_should_use_a_list_of_return_values_for_successive_calls
|
197
|
+
@mock.should_receive(:multi_call).twice.with(:no_args).and_return([8, 12])
|
198
|
+
assert_equal(8, @mock.multi_call)
|
199
|
+
assert_equal(12, @mock.multi_call)
|
200
|
+
@mock.__verify
|
201
|
+
end
|
202
|
+
|
365
203
|
end
|
366
204
|
end
|
367
205
|
end
|