rspec 0.6.4 → 0.7.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.
Files changed (114) hide show
  1. data/CHANGES +90 -1
  2. data/EXAMPLES.rd +28 -6
  3. data/MIT-LICENSE +20 -0
  4. data/README +18 -12
  5. data/Rakefile +60 -54
  6. data/examples/custom_formatter.rb +4 -4
  7. data/examples/helper_method_example.rb +11 -0
  8. data/examples/mocking_example.rb +19 -2
  9. data/examples/partial_mock_example.rb +28 -0
  10. data/examples/stack_spec.rb +8 -8
  11. data/examples/stubbing_example.rb +50 -9
  12. data/examples/test_case_spec.rb +6 -6
  13. data/lib/spec.rb +1 -2
  14. data/lib/spec/callback.rb +0 -0
  15. data/lib/spec/expectations.rb +3 -6
  16. data/lib/spec/expectations/diff.rb +23 -47
  17. data/lib/spec/expectations/differs/default.rb +62 -0
  18. data/lib/spec/expectations/{exceptions.rb → errors.rb} +0 -0
  19. data/lib/spec/expectations/extensions.rb +4 -0
  20. data/lib/spec/expectations/extensions/inspect_for_expectation_not_met_error.rb +14 -0
  21. data/lib/spec/expectations/extensions/numeric.rb +5 -0
  22. data/lib/spec/expectations/{expectations.rb → extensions/object.rb} +3 -6
  23. data/lib/spec/expectations/extensions/symbol.rb +5 -0
  24. data/lib/spec/expectations/should.rb +4 -0
  25. data/lib/spec/expectations/should/base.rb +42 -0
  26. data/lib/spec/expectations/should/have.rb +79 -0
  27. data/lib/spec/expectations/should/not.rb +72 -0
  28. data/lib/spec/expectations/should/should.rb +83 -0
  29. data/lib/spec/expectations/sugar.rb +6 -25
  30. data/lib/spec/mocks.rb +5 -1
  31. data/lib/spec/mocks/argument_expectation.rb +15 -1
  32. data/lib/spec/mocks/error_generator.rb +72 -0
  33. data/lib/spec/mocks/{exceptions.rb → errors.rb} +0 -0
  34. data/lib/spec/mocks/extensions/object.rb +3 -0
  35. data/lib/spec/mocks/message_expectation.rb +80 -73
  36. data/lib/spec/mocks/mock.rb +4 -69
  37. data/lib/spec/mocks/mock_handler.rb +158 -0
  38. data/lib/spec/mocks/mock_methods.rb +44 -0
  39. data/lib/spec/mocks/order_group.rb +10 -2
  40. data/lib/spec/rake/spectask.rb +20 -18
  41. data/lib/spec/rake/{rcov_verify.rb → verify_rcov.rb} +2 -2
  42. data/lib/spec/runner.rb +3 -1
  43. data/lib/spec/runner/backtrace_tweaker.rb +2 -1
  44. data/lib/spec/runner/context.rb +10 -16
  45. data/lib/spec/runner/context_eval.rb +40 -40
  46. data/lib/spec/runner/execution_context.rb +1 -12
  47. data/lib/spec/runner/{kernel_ext.rb → extensions/kernel.rb} +2 -2
  48. data/lib/spec/runner/{instance_exec.rb → extensions/object.rb} +0 -0
  49. data/lib/spec/runner/formatter/base_text_formatter.rb +25 -18
  50. data/lib/spec/runner/formatter/html_formatter.rb +81 -101
  51. data/lib/spec/runner/formatter/progress_bar_formatter.rb +9 -9
  52. data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
  53. data/lib/spec/runner/formatter/specdoc_formatter.rb +7 -6
  54. data/lib/spec/runner/option_parser.rb +41 -5
  55. data/lib/spec/runner/reporter.rb +3 -15
  56. data/lib/spec/runner/spec_should_raise_handler.rb +74 -0
  57. data/lib/spec/runner/specification.rb +33 -14
  58. data/lib/spec/version.rb +6 -3
  59. data/vendor/watir/README.txt +1 -1
  60. metadata +34 -68
  61. data/bin/test2spec +0 -112
  62. data/examples/helper_method_spec.rb +0 -12
  63. data/lib/spec/expectations/have_helper.rb +0 -41
  64. data/lib/spec/expectations/helper.rb +0 -4
  65. data/lib/spec/expectations/should_base.rb +0 -52
  66. data/lib/spec/expectations/should_helper.rb +0 -93
  67. data/lib/spec/expectations/should_negator.rb +0 -71
  68. data/lib/spec/test_to_spec/ruby2ruby.rb +0 -492
  69. data/lib/spec/test_to_spec/sexp_transformer.rb +0 -196
  70. data/lib/spec/test_to_spec/test_case_ext.rb +0 -22
  71. data/lib/spec/test_to_spec/translation_test_runner.rb +0 -147
  72. data/test/spec/expectations/arbitrary_operator_test.rb +0 -55
  73. data/test/spec/expectations/arbitrary_predicate_test.rb +0 -163
  74. data/test/spec/expectations/containment_test.rb +0 -129
  75. data/test/spec/expectations/diff_test.rb +0 -62
  76. data/test/spec/expectations/identity_test.rb +0 -75
  77. data/test/spec/expectations/object_equality_test.rb +0 -65
  78. data/test/spec/expectations/raising_test.rb +0 -106
  79. data/test/spec/expectations/regex_matching_test.rb +0 -36
  80. data/test/spec/expectations/should_have_test.rb +0 -169
  81. data/test/spec/expectations/should_satisfy_test.rb +0 -37
  82. data/test/spec/expectations/sugar_test.rb +0 -93
  83. data/test/spec/expectations/supported_symbols_test.rb +0 -33
  84. data/test/spec/expectations/throwing_test.rb +0 -55
  85. data/test/spec/expectations/true_false_special_case_test.rb +0 -85
  86. data/test/spec/expectations/typing_test.rb +0 -108
  87. data/test/spec/mocks/mock_arg_constraints_test.rb +0 -113
  88. data/test/spec/mocks/mock_counts_test.rb +0 -431
  89. data/test/spec/mocks/mock_ordering_test.rb +0 -109
  90. data/test/spec/mocks/mock_test.rb +0 -220
  91. data/test/spec/mocks/null_object_test.rb +0 -37
  92. data/test/spec/runner/backtrace_tweaker_test.rb +0 -90
  93. data/test/spec/runner/context_matching_test.rb +0 -35
  94. data/test/spec/runner/context_runner_test.rb +0 -62
  95. data/test/spec/runner/context_test.rb +0 -191
  96. data/test/spec/runner/execution_context_test.rb +0 -45
  97. data/test/spec/runner/formatter/failure_dump_test.rb +0 -94
  98. data/test/spec/runner/formatter/html_formatter_test.rb +0 -48
  99. data/test/spec/runner/formatter/progress_bar_formatter_test.rb +0 -56
  100. data/test/spec/runner/formatter/rdoc_formatter_test.rb +0 -51
  101. data/test/spec/runner/formatter/specdoc_formatter_test.rb +0 -57
  102. data/test/spec/runner/kernel_ext_test.rb +0 -13
  103. data/test/spec/runner/option_parser_test.rb +0 -141
  104. data/test/spec/runner/reporter_test.rb +0 -128
  105. data/test/spec/runner/spec_matcher_test.rb +0 -47
  106. data/test/spec/runner/specification_test.rb +0 -121
  107. data/test/spec/test_to_spec/ruby_to_ruby_test.rb +0 -79
  108. data/test/spec/test_to_spec/sexp_transformer_assertion_test.rb +0 -207
  109. data/test/spec/test_to_spec/sexp_transformer_test.rb +0 -303
  110. data/test/spec/test_to_spec/test_case_ext_test.rb +0 -25
  111. data/test/spec/test_to_spec/testfiles/test_unit_api_spec.rb +0 -75
  112. data/test/spec/test_to_spec/testfiles/test_unit_api_test.rb +0 -70
  113. data/test/test_classes.rb +0 -102
  114. data/test/test_helper.rb +0 -32
@@ -1,108 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Expectations
5
- module Helper
6
- class ShouldBeAnInstanceOfTest < Test::Unit::TestCase
7
-
8
- def test_should_pass_when_target_is_specified_class
9
- assert_nothing_raised do
10
- 5.should_be_an_instance_of Fixnum
11
- end
12
- end
13
-
14
- def test_should_fail_when_target_is_not_specified_class
15
- assert_raise(ExpectationNotMetError) do
16
- 5.should_be_an_instance_of Integer
17
- end
18
- end
19
- end
20
-
21
- class ShouldBeAKindOfTest < Test::Unit::TestCase
22
-
23
- def test_should_pass_when_target_is_of_specified_class
24
- assert_nothing_raised do
25
- 5.should_be_a_kind_of Fixnum
26
- end
27
- end
28
-
29
- def test_should_pass_when_target_is_of_subclass_of_specified_class
30
- assert_nothing_raised do
31
- 5.should_be_a_kind_of Integer
32
- end
33
- end
34
-
35
- def test_should_fail_when_target_is_not_specified_class
36
- assert_raise(ExpectationNotMetError) do
37
- 5.should_be_a_kind_of String
38
- end
39
- end
40
- end
41
-
42
- class ShouldNotBeAnInstanceOfTest < Test::Unit::TestCase
43
-
44
- def test_should_fail_when_target_is_of_specified_class
45
- assert_raise(ExpectationNotMetError) do
46
- 'hello'.should_not_be_an_instance_of String
47
- end
48
- end
49
-
50
- def test_should_pass_when_target_is_not_of_specified_class
51
- assert_nothing_raised do
52
- [].should_not_be_an_instance_of String
53
- end
54
- end
55
- end
56
-
57
- class ShouldNotBeAKindOfTest < Test::Unit::TestCase
58
-
59
- def test_should_fail_when_target_is_of_specified_class
60
- assert_raise(ExpectationNotMetError) do
61
- 5.should_not_be_a_kind_of Fixnum
62
- end
63
- end
64
-
65
- def test_should_fail_when_target_is_of_subclass_of_specified_class
66
- assert_raise(ExpectationNotMetError) do
67
- 5.should_not_be_a_kind_of Integer
68
- end
69
- end
70
-
71
- def test_should_pass_when_target_is_not_specified_class
72
- assert_nothing_raised do
73
- 5.should_not_be_a_kind_of String
74
- end
75
- end
76
- end
77
-
78
- class ShouldRespondToTest < Test::Unit::TestCase
79
- def test_should_pass_when_target_responds_to
80
- assert_nothing_raised do
81
- "".should_respond_to :length
82
- end
83
- end
84
-
85
- def test_should_fail_when_target_doesnt_respond_to
86
- assert_raise(ExpectationNotMetError) do
87
- "".should_respond_to :connect
88
- end
89
- end
90
- end
91
-
92
- class ShouldNotRespondToTest < Test::Unit::TestCase
93
- def test_should_fail_when_target_responds_to
94
- assert_raise(ExpectationNotMetError) do
95
- "".should_not_respond_to :length
96
- end
97
- end
98
-
99
- def test_should_pass_when_target_doesnt_respond_to
100
- assert_nothing_raised do
101
- "".should_not_respond_to :connect
102
- end
103
- end
104
-
105
- end
106
- end
107
- end
108
- end
@@ -1,113 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Mocks
5
- class PassingMockArgumentConstraintsTest < Test::Unit::TestCase
6
-
7
- def setup
8
- @mock = Mock.new("test mock")
9
- end
10
-
11
- def test_should_accept_string_as_anything
12
- @mock.should_receive(:random_call).with("a", :anything, "c")
13
- @mock.random_call("a", "whatever", "c")
14
- @mock.__verify
15
- end
16
-
17
- def test_should_accept_fixnum_as_numeric
18
- @mock.should_receive(:random_call).with(:numeric)
19
- @mock.random_call(1)
20
- @mock.__verify
21
- end
22
-
23
- def test_should_accept_float_as_numeric
24
- @mock.should_receive(:random_call).with(:numeric)
25
- @mock.random_call(1.5)
26
- @mock.__verify
27
- end
28
-
29
- def test_should_accept_true_as_boolean
30
- @mock.should_receive(:random_call).with(:boolean)
31
- @mock.random_call(true)
32
- @mock.__verify
33
- end
34
-
35
- def test_should_accept_false_as_boolean
36
- @mock.should_receive(:random_call).with(:boolean)
37
- @mock.random_call(false)
38
- @mock.__verify
39
- end
40
-
41
- def test_should_match_string
42
- @mock.should_receive(:random_call).with(:string)
43
- @mock.random_call("a string")
44
- @mock.__verify
45
- end
46
-
47
- def test_should_match_non_special_symbol
48
- @mock.should_receive(:random_call).with(:some_symbol)
49
- @mock.random_call(:some_symbol)
50
- @mock.__verify
51
- end
52
-
53
- def test_should_match_duck_type_with_one_method
54
- @mock.should_receive(:random_call).with(DuckTypeArgConstraint.new(:length))
55
- @mock.random_call([])
56
- @mock.__verify
57
- end
58
-
59
- def test_should_match_duck_type_with_two_methods
60
- @mock.should_receive(:random_call).with(DuckTypeArgConstraint.new(:abs, :div))
61
- @mock.random_call(1)
62
- @mock.__verify
63
- end
64
-
65
- def test_should_match_user_defined_type
66
- @mock.should_receive(:random_call).with(Expectations::Person.new("David"))
67
- @mock.random_call(Expectations::Person.new("David"))
68
- @mock.__verify
69
- end
70
-
71
- end
72
-
73
- class FailingMockArgumentConstraintsTest < Test::Unit::TestCase
74
-
75
- def setup
76
- @mock = Mock.new("test mock")
77
- end
78
-
79
- def test_should_reject_non_numeric
80
- @mock.should_receive(:random_call).with(:numeric)
81
- assert_raise(MockExpectationError) do
82
- @mock.random_call("1")
83
- @mock.__verify
84
- end
85
- end
86
-
87
- def test_should_reject_non_boolean
88
- @mock.should_receive(:random_call).with(:boolean)
89
- assert_raise(MockExpectationError) do
90
- @mock.random_call("false")
91
- @mock.__verify
92
- end
93
- end
94
-
95
- def test_should_reject_non_string
96
- @mock.should_receive(:random_call).with(:string)
97
- assert_raise(MockExpectationError) do
98
- @mock.random_call(123)
99
- @mock.__verify
100
- end
101
- end
102
-
103
- def test_should_reject_goose_when_expecting_a_duck
104
- @mock.should_receive(:random_call).with(DuckTypeArgConstraint.new(:abs, :div))
105
- assert_raise(MockExpectationError) do
106
- @mock.random_call("I don't respond to :abs or :div")
107
- @mock.__verify
108
- end
109
- end
110
-
111
- end
112
- end
113
- end
@@ -1,431 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Mocks
5
- class OnceCountsTest < Test::Unit::TestCase
6
-
7
- def setup
8
- @mock = Mock.new("test mock")
9
- end
10
-
11
- def test_once_should_pass_when_called_once
12
- @mock.should_receive(:random_call).once
13
- @mock.random_call
14
- assert_nothing_raised do
15
- @mock.__verify
16
- end
17
- end
18
-
19
- def test_once_should_pass_when_called_once_with_unspecified_args
20
- @mock.should_receive(:random_call).once
21
- @mock.random_call("a","b","c")
22
- assert_nothing_raised do
23
- @mock.__verify
24
- end
25
- end
26
-
27
- def test_once_should_pass_when_called_once_with_specified_args
28
- @mock.should_receive(:random_call).once.with("a","b","c")
29
- @mock.random_call("a","b","c")
30
- assert_nothing_raised do
31
- @mock.__verify
32
- end
33
- end
34
-
35
- def test_once_should_fail_when_not_called
36
- @mock.should_receive(:random_call).once
37
- assert_raise(MockExpectationError) do
38
- @mock.__verify
39
- end
40
- end
41
-
42
- def test_once_should_fail_when_called_twice
43
- @mock.should_receive(:random_call).once
44
- @mock.random_call
45
- @mock.random_call
46
- assert_raise(MockExpectationError) do
47
- @mock.__verify
48
- end
49
- end
50
-
51
- def test_once_should_fail_when_called_once_with_wrong_args
52
- @mock.should_receive(:random_call).once.with("a","b","c")
53
- assert_raise(MockExpectationError) do
54
- @mock.random_call "d","e","f"
55
- end
56
- end
57
- end
58
-
59
- class TwiceCountsTest < Test::Unit::TestCase
60
-
61
- def setup
62
- @mock = Mock.new("test mock")
63
- end
64
-
65
- def test_twice_should_pass_when_called_twice
66
- @mock.should_receive(:random_call).twice
67
- @mock.random_call
68
- @mock.random_call
69
- assert_nothing_raised do
70
- @mock.__verify
71
- end
72
- end
73
-
74
- def test_twice_should_pass_when_called_twice_with_unspecified_args
75
- @mock.should_receive(:random_call).twice
76
- @mock.random_call "1"
77
- @mock.random_call 1
78
- assert_nothing_raised do
79
- @mock.__verify
80
- end
81
- end
82
-
83
- def test_twice_should_pass_when_called_twice_with_specified_args
84
- @mock.should_receive(:random_call).twice.with("1", 1)
85
- @mock.random_call "1", 1
86
- @mock.random_call "1", 1
87
- assert_nothing_raised do
88
- @mock.__verify
89
- end
90
- end
91
-
92
- def test_twice_should_fail_when_called_twice_with_wrong_args_on_the_second_call
93
- @mock.should_receive(:random_call).twice.with("1", 1)
94
- @mock.random_call "1", 1
95
- assert_raise(MockExpectationError) do
96
- @mock.random_call 1, "1"
97
- end
98
- end
99
-
100
- def test_twice_should_fail_when_called_twice_with_wrong_args_on_the_first_call
101
- @mock.should_receive(:random_call).twice.with("1", 1)
102
- assert_raise(MockExpectationError) do
103
- @mock.random_call 1, "1"
104
- end
105
- end
106
-
107
- def test_twice_should_fail_when_call_count_is_lower_than_expected
108
- @mock.should_receive(:random_call).twice
109
- @mock.random_call
110
- assert_raise(MockExpectationError) do
111
- @mock.__verify
112
- end
113
- end
114
-
115
- def test_twice_should_fail_when_call_count_is_higher_than_expected
116
- @mock.should_receive(:random_call).twice
117
- @mock.random_call
118
- @mock.random_call
119
- @mock.random_call
120
- assert_raise(MockExpectationError) do
121
- @mock.__verify
122
- end
123
- end
124
- end
125
-
126
- class AnyNumberOfTimesTest < Test::Unit::TestCase
127
-
128
- def setup
129
- @mock = Mock.new("test mock")
130
- end
131
-
132
- def test_should_pass_if_any_number_of_times_method_is_not_called
133
- @mock.should_receive(:random_call).any_number_of_times
134
- assert_nothing_raised do
135
- @mock.__verify
136
- end
137
- end
138
-
139
- def test_should_pass_if_any_number_of_times_method_is_called_once
140
- @mock.should_receive(:random_call).any_number_of_times
141
- @mock.random_call
142
- assert_nothing_raised do
143
- @mock.__verify
144
- end
145
- end
146
-
147
- def test_should_pass_if_any_number_of_times_method_is_called_many_times
148
- @mock.should_receive(:random_call).any_number_of_times
149
- (1..10).each { @mock.random_call }
150
- assert_nothing_raised do
151
- @mock.__verify
152
- end
153
- end
154
- end
155
-
156
- class PreciseCountsTest < Test::Unit::TestCase
157
-
158
- def setup
159
- @mock = Mock.new("test mock")
160
- end
161
-
162
- def test_should_pass_mutiple_calls_with_different_args
163
- @mock.should_receive(:random_call).once.with(1)
164
- @mock.should_receive(:random_call).once.with(2)
165
- @mock.random_call(1)
166
- @mock.random_call(2)
167
- assert_nothing_raised do
168
- @mock.__verify
169
- end
170
- end
171
-
172
- def test_should_pass_multiple_calls_with_different_args_and_counts
173
- @mock.should_receive(:random_call).twice.with(1)
174
- @mock.should_receive(:random_call).once.with(2)
175
- @mock.random_call(1)
176
- @mock.random_call(2)
177
- @mock.random_call(1)
178
- assert_nothing_raised do
179
- @mock.__verify
180
- end
181
- end
182
-
183
- def test_should_fail_when_exactly_n_times_method_is_never_called
184
- @mock.should_receive(:random_call).exactly(3).times
185
- assert_raise(MockExpectationError) do
186
- @mock.__verify
187
- end
188
- end
189
-
190
- def test_should_fail_when_exactly_n_times_method_is_called_less_than_n_times
191
- @mock.should_receive(:random_call).exactly(3).times
192
- @mock.random_call
193
- @mock.random_call
194
- assert_raise(MockExpectationError) do
195
- @mock.__verify
196
- end
197
- end
198
-
199
- def test_should_pass_if_exactly_n_times_method_is_called_exactly_n_times
200
- @mock.should_receive(:random_call).exactly(3).times
201
- @mock.random_call
202
- @mock.random_call
203
- @mock.random_call
204
- assert_nothing_raised do
205
- @mock.__verify
206
- end
207
- end
208
-
209
- end
210
-
211
- class AtLeastTest < Test::Unit::TestCase
212
-
213
- def setup
214
- @mock = Mock.new("test mock")
215
- end
216
-
217
- def test_should_fail_when_at_least_once_method_is_never_called
218
- @mock.should_receive(:random_call).at_least(:once)
219
- assert_raise(MockExpectationError) do
220
- @mock.__verify
221
- end
222
- end
223
-
224
- def test_should_pass_when_at_least_once_method_is_called_once
225
- @mock.should_receive(:random_call).at_least(:once)
226
- @mock.random_call
227
- assert_nothing_raised do
228
- @mock.__verify
229
- end
230
- end
231
-
232
- def test_should_pass_when_at_least_once_method_is_called_twice
233
- @mock.should_receive(:random_call).at_least(:once)
234
- @mock.random_call
235
- @mock.random_call
236
- assert_nothing_raised do
237
- @mock.__verify
238
- end
239
- end
240
-
241
- def test_should_fail_when_at_least_twice_method_is_never_called
242
- @mock.should_receive(:random_call).at_least(:twice)
243
- assert_raise(MockExpectationError) do
244
- @mock.__verify
245
- end
246
- end
247
-
248
- def test_should_fail_when_at_least_twice_method_is_called_once
249
- @mock.should_receive(:random_call).at_least(:twice)
250
- @mock.random_call
251
- assert_raise(MockExpectationError) do
252
- @mock.__verify
253
- end
254
- end
255
-
256
- def test_should_pass_when_at_least_twice_method_is_called_twice
257
- @mock.should_receive(:random_call).at_least(:twice)
258
- @mock.random_call
259
- @mock.random_call
260
- assert_nothing_raised do
261
- @mock.__verify
262
- end
263
- end
264
-
265
- def test_should_pass_when_at_least_twice_method_is_called_three_times
266
- @mock.should_receive(:random_call).at_least(:twice)
267
- @mock.random_call
268
- @mock.random_call
269
- @mock.random_call
270
- assert_nothing_raised do
271
- @mock.__verify
272
- end
273
- end
274
-
275
- def test_should_fail_at_least_n_times_method_is_never_called
276
- @mock.should_receive(:random_call).at_least(4).times
277
- assert_raise(MockExpectationError) do
278
- @mock.__verify
279
- end
280
- end
281
-
282
- def test_should_fail_when_at_least_n_times_method_is_called_less_than_n_times
283
- @mock.should_receive(:random_call).at_least(4).times
284
- @mock.random_call
285
- @mock.random_call
286
- @mock.random_call
287
- assert_raise(MockExpectationError) do
288
- @mock.__verify
289
- end
290
- end
291
-
292
- def test_should_pass_when_at_least_n_times_method_is_called_exactly_n_times
293
- @mock.should_receive(:random_call).at_least(4).times
294
- @mock.random_call
295
- @mock.random_call
296
- @mock.random_call
297
- @mock.random_call
298
- assert_nothing_raised do
299
- @mock.__verify
300
- end
301
- end
302
-
303
- def test_should_pass_when_at_least_n_times_method_is_called_n_plus_1_times
304
- @mock.should_receive(:random_call).at_least(4).times
305
- @mock.random_call
306
- @mock.random_call
307
- @mock.random_call
308
- @mock.random_call
309
- @mock.random_call
310
- assert_nothing_raised do
311
- @mock.__verify
312
- end
313
- end
314
-
315
- def test_should_use_last_return_value_for_subsequent_calls
316
- @mock.should_receive(:multi_call).at_least(:once).with(:no_args).and_return([11, 22])
317
- assert_equal(11, @mock.multi_call)
318
- assert_equal(22, @mock.multi_call)
319
- assert_equal(22, @mock.multi_call)
320
- assert_nothing_raised do
321
- @mock.__verify
322
- end
323
- end
324
- end
325
-
326
- class AtMostTest < Test::Unit::TestCase
327
-
328
- def setup
329
- @mock = Mock.new("test mock")
330
- end
331
-
332
- def test_should_pass_when_at_most_once_method_is_never_called
333
- @mock.should_receive(:random_call).at_most(:once)
334
- assert_nothing_raised do
335
- @mock.__verify
336
- end
337
- end
338
-
339
- def test_should_pass_when_at_most_once_method_is_called_once
340
- @mock.should_receive(:random_call).at_most(:once)
341
- @mock.random_call
342
- assert_nothing_raised do
343
- @mock.__verify
344
- end
345
- end
346
-
347
- def test_should_fail_when_at_most_once_method_is_called_twice
348
- @mock.should_receive(:random_call).at_most(:once)
349
- @mock.random_call
350
- @mock.random_call
351
- assert_raise(MockExpectationError) do
352
- @mock.__verify
353
- end
354
- end
355
-
356
- def test_should_pass_when_at_most_twice_method_is_never_called
357
- @mock.should_receive(:random_call).at_most(:twice)
358
- assert_nothing_raised do
359
- @mock.__verify
360
- end
361
- end
362
-
363
- def test_should_pass_when_at_most_twice_method_is_called_once
364
- @mock.should_receive(:random_call).at_most(:twice)
365
- @mock.random_call
366
- assert_nothing_raised do
367
- @mock.__verify
368
- end
369
- end
370
-
371
- def test_should_pass_when_at_most_twice_method_is_called_twice
372
- @mock.should_receive(:random_call).at_most(:twice)
373
- @mock.random_call
374
- @mock.random_call
375
- assert_nothing_raised do
376
- @mock.__verify
377
- end
378
- end
379
-
380
- def test_should_fail_when_at_most_twice_method_is_called_three_times
381
- @mock.should_receive(:random_call).at_most(:twice)
382
- @mock.random_call
383
- @mock.random_call
384
- @mock.random_call
385
- assert_raise(MockExpectationError) do
386
- @mock.__verify
387
- end
388
- end
389
-
390
- def test_should_pass_when_at_most_n_times_method_is_never_called
391
- @mock.should_receive(:random_call).at_most(4).times
392
- assert_nothing_raised do
393
- @mock.__verify
394
- end
395
- end
396
-
397
- def test_should_pass_when_at_most_n_times_method_is_called_less_than_n_times
398
- @mock.should_receive(:random_call).at_most(4).times
399
- @mock.random_call
400
- @mock.random_call
401
- @mock.random_call
402
- assert_nothing_raised do
403
- @mock.__verify
404
- end
405
- end
406
-
407
- def test_should_pass_when_at_most_n_times_method_is_called_exactly_n_times
408
- @mock.should_receive(:random_call).at_most(4).times
409
- @mock.random_call
410
- @mock.random_call
411
- @mock.random_call
412
- @mock.random_call
413
- assert_nothing_raised do
414
- @mock.__verify
415
- end
416
- end
417
-
418
- def test_should_fail_when_at_most_n_times_method_is_called_n_plus_1_times
419
- @mock.should_receive(:random_call).at_most(4).times
420
- @mock.random_call
421
- @mock.random_call
422
- @mock.random_call
423
- @mock.random_call
424
- @mock.random_call
425
- assert_raise(MockExpectationError) do
426
- @mock.__verify
427
- end
428
- end
429
- end
430
- end
431
- end