mspec 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/LICENSE +22 -0
  2. data/README +101 -0
  3. data/Rakefile +44 -0
  4. data/bin/mkspec +7 -0
  5. data/bin/mspec +7 -0
  6. data/bin/mspec-ci +8 -0
  7. data/bin/mspec-run +8 -0
  8. data/bin/mspec-tag +8 -0
  9. data/lib/mspec.rb +6 -0
  10. data/lib/mspec/commands/mkspec.rb +147 -0
  11. data/lib/mspec/commands/mspec-ci.rb +71 -0
  12. data/lib/mspec/commands/mspec-run.rb +80 -0
  13. data/lib/mspec/commands/mspec-tag.rb +87 -0
  14. data/lib/mspec/commands/mspec.rb +143 -0
  15. data/lib/mspec/expectations.rb +2 -0
  16. data/lib/mspec/expectations/expectations.rb +12 -0
  17. data/lib/mspec/expectations/should.rb +23 -0
  18. data/lib/mspec/guards.rb +13 -0
  19. data/lib/mspec/guards/bug.rb +27 -0
  20. data/lib/mspec/guards/compliance.rb +18 -0
  21. data/lib/mspec/guards/conflict.rb +16 -0
  22. data/lib/mspec/guards/endian.rb +40 -0
  23. data/lib/mspec/guards/extensions.rb +12 -0
  24. data/lib/mspec/guards/guard.rb +120 -0
  25. data/lib/mspec/guards/noncompliance.rb +12 -0
  26. data/lib/mspec/guards/platform.rb +38 -0
  27. data/lib/mspec/guards/quarantine.rb +15 -0
  28. data/lib/mspec/guards/runner.rb +30 -0
  29. data/lib/mspec/guards/superuser.rb +15 -0
  30. data/lib/mspec/guards/support.rb +12 -0
  31. data/lib/mspec/guards/version.rb +40 -0
  32. data/lib/mspec/helpers.rb +6 -0
  33. data/lib/mspec/helpers/bignum.rb +5 -0
  34. data/lib/mspec/helpers/const_lookup.rb +5 -0
  35. data/lib/mspec/helpers/flunk.rb +5 -0
  36. data/lib/mspec/helpers/io.rb +13 -0
  37. data/lib/mspec/helpers/scratch.rb +17 -0
  38. data/lib/mspec/helpers/tmp.rb +32 -0
  39. data/lib/mspec/matchers.rb +16 -0
  40. data/lib/mspec/matchers/base.rb +95 -0
  41. data/lib/mspec/matchers/be_ancestor_of.rb +24 -0
  42. data/lib/mspec/matchers/be_close.rb +27 -0
  43. data/lib/mspec/matchers/be_empty.rb +20 -0
  44. data/lib/mspec/matchers/be_false.rb +20 -0
  45. data/lib/mspec/matchers/be_kind_of.rb +24 -0
  46. data/lib/mspec/matchers/be_nil.rb +20 -0
  47. data/lib/mspec/matchers/be_true.rb +20 -0
  48. data/lib/mspec/matchers/complain.rb +56 -0
  49. data/lib/mspec/matchers/eql.rb +26 -0
  50. data/lib/mspec/matchers/equal.rb +26 -0
  51. data/lib/mspec/matchers/equal_utf16.rb +34 -0
  52. data/lib/mspec/matchers/include.rb +32 -0
  53. data/lib/mspec/matchers/output.rb +67 -0
  54. data/lib/mspec/matchers/output_to_fd.rb +71 -0
  55. data/lib/mspec/matchers/raise_error.rb +48 -0
  56. data/lib/mspec/mocks.rb +3 -0
  57. data/lib/mspec/mocks/mock.rb +123 -0
  58. data/lib/mspec/mocks/object.rb +28 -0
  59. data/lib/mspec/mocks/proxy.rb +112 -0
  60. data/lib/mspec/runner.rb +13 -0
  61. data/lib/mspec/runner/actions.rb +6 -0
  62. data/lib/mspec/runner/actions/debug.rb +17 -0
  63. data/lib/mspec/runner/actions/filter.rb +40 -0
  64. data/lib/mspec/runner/actions/gdb.rb +17 -0
  65. data/lib/mspec/runner/actions/tag.rb +97 -0
  66. data/lib/mspec/runner/actions/tally.rb +80 -0
  67. data/lib/mspec/runner/actions/timer.rb +22 -0
  68. data/lib/mspec/runner/filters.rb +4 -0
  69. data/lib/mspec/runner/filters/match.rb +22 -0
  70. data/lib/mspec/runner/filters/profile.rb +54 -0
  71. data/lib/mspec/runner/filters/regexp.rb +7 -0
  72. data/lib/mspec/runner/filters/tag.rb +29 -0
  73. data/lib/mspec/runner/formatters.rb +7 -0
  74. data/lib/mspec/runner/formatters/dotted.rb +81 -0
  75. data/lib/mspec/runner/formatters/html.rb +87 -0
  76. data/lib/mspec/runner/formatters/specdoc.rb +27 -0
  77. data/lib/mspec/runner/formatters/spinner.rb +89 -0
  78. data/lib/mspec/runner/formatters/summary.rb +8 -0
  79. data/lib/mspec/runner/formatters/unit.rb +25 -0
  80. data/lib/mspec/runner/formatters/yaml.rb +43 -0
  81. data/lib/mspec/runner/mspec.rb +232 -0
  82. data/lib/mspec/runner/object.rb +20 -0
  83. data/lib/mspec/runner/shared.rb +12 -0
  84. data/lib/mspec/runner/state.rb +116 -0
  85. data/lib/mspec/runner/tag.rb +20 -0
  86. data/lib/mspec/utils/name_map.rb +130 -0
  87. data/lib/mspec/utils/options.rb +344 -0
  88. data/lib/mspec/utils/script.rb +77 -0
  89. data/lib/mspec/version.rb +3 -0
  90. data/spec/commands/mkspec_spec.rb +321 -0
  91. data/spec/commands/mspec_ci_spec.rb +139 -0
  92. data/spec/commands/mspec_run_spec.rb +146 -0
  93. data/spec/commands/mspec_spec.rb +359 -0
  94. data/spec/commands/mspec_tag_spec.rb +131 -0
  95. data/spec/expectations/expectations_spec.rb +16 -0
  96. data/spec/expectations/should_spec.rb +99 -0
  97. data/spec/guards/bug_spec.rb +137 -0
  98. data/spec/guards/compliance_spec.rb +70 -0
  99. data/spec/guards/conflict_spec.rb +20 -0
  100. data/spec/guards/endian_spec.rb +42 -0
  101. data/spec/guards/extensions_spec.rb +36 -0
  102. data/spec/guards/guard_spec.rb +355 -0
  103. data/spec/guards/noncompliance_spec.rb +36 -0
  104. data/spec/guards/platform_spec.rb +84 -0
  105. data/spec/guards/quarantine_spec.rb +19 -0
  106. data/spec/guards/runner_spec.rb +75 -0
  107. data/spec/guards/superuser_spec.rb +22 -0
  108. data/spec/guards/support_spec.rb +22 -0
  109. data/spec/guards/version_spec.rb +133 -0
  110. data/spec/helpers/bignum_spec.rb +11 -0
  111. data/spec/helpers/const_lookup_spec.rb +19 -0
  112. data/spec/helpers/flunk_spec.rb +15 -0
  113. data/spec/helpers/io_spec.rb +34 -0
  114. data/spec/helpers/scratch_spec.rb +22 -0
  115. data/spec/helpers/tmp_spec.rb +72 -0
  116. data/spec/matchers/base_spec.rb +180 -0
  117. data/spec/matchers/be_ancestor_of_spec.rb +28 -0
  118. data/spec/matchers/be_close_spec.rb +46 -0
  119. data/spec/matchers/be_empty_spec.rb +26 -0
  120. data/spec/matchers/be_false_spec.rb +28 -0
  121. data/spec/matchers/be_kind_of_spec.rb +29 -0
  122. data/spec/matchers/be_nil_spec.rb +27 -0
  123. data/spec/matchers/be_true_spec.rb +28 -0
  124. data/spec/matchers/complain_spec.rb +52 -0
  125. data/spec/matchers/eql_spec.rb +33 -0
  126. data/spec/matchers/equal_spec.rb +33 -0
  127. data/spec/matchers/equal_utf16_spec.rb +47 -0
  128. data/spec/matchers/include_spec.rb +37 -0
  129. data/spec/matchers/output_spec.rb +74 -0
  130. data/spec/matchers/output_to_fd_spec.rb +33 -0
  131. data/spec/matchers/raise_error_spec.rb +56 -0
  132. data/spec/mocks/mock_spec.rb +272 -0
  133. data/spec/mocks/proxy_spec.rb +259 -0
  134. data/spec/runner/actions/debug_spec.rb +61 -0
  135. data/spec/runner/actions/filter_spec.rb +84 -0
  136. data/spec/runner/actions/gdb_spec.rb +61 -0
  137. data/spec/runner/actions/tag_spec.rb +253 -0
  138. data/spec/runner/actions/tally_spec.rb +107 -0
  139. data/spec/runner/actions/timer_spec.rb +42 -0
  140. data/spec/runner/filters/a.yaml +4 -0
  141. data/spec/runner/filters/b.yaml +11 -0
  142. data/spec/runner/filters/match_spec.rb +44 -0
  143. data/spec/runner/filters/profile_spec.rb +117 -0
  144. data/spec/runner/filters/regexp_spec.rb +13 -0
  145. data/spec/runner/filters/tag_spec.rb +77 -0
  146. data/spec/runner/formatters/dotted_spec.rb +184 -0
  147. data/spec/runner/formatters/html_spec.rb +191 -0
  148. data/spec/runner/formatters/specdoc_spec.rb +57 -0
  149. data/spec/runner/formatters/spinner_spec.rb +78 -0
  150. data/spec/runner/formatters/summary_spec.rb +29 -0
  151. data/spec/runner/formatters/unit_spec.rb +71 -0
  152. data/spec/runner/formatters/yaml_spec.rb +123 -0
  153. data/spec/runner/mspec_spec.rb +393 -0
  154. data/spec/runner/shared_spec.rb +41 -0
  155. data/spec/runner/state_spec.rb +535 -0
  156. data/spec/runner/tag_spec.rb +93 -0
  157. data/spec/runner/tags.txt +3 -0
  158. data/spec/spec_helper.rb +46 -0
  159. data/spec/utils/name_map_spec.rb +178 -0
  160. data/spec/utils/options_spec.rb +862 -0
  161. data/spec/utils/script_spec.rb +240 -0
  162. metadata +217 -0
@@ -0,0 +1,272 @@
1
+ # This is a bit awkward. Currently the way to verify that the
2
+ # opposites are true (for example a failure when the specified
3
+ # arguments are NOT provided) is to simply alter the particular
4
+ # spec to a failure condition.
5
+ require File.dirname(__FILE__) + '/../spec_helper'
6
+ require 'mspec/runner/mspec'
7
+ require 'mspec/mocks/mock'
8
+ require 'mspec/mocks/proxy'
9
+
10
+ describe Mock do
11
+ after :each do
12
+ Mock.cleanup
13
+ end
14
+
15
+ it "provides expects that returns a Hash" do
16
+ Mock.expects.should be_an_instance_of(Hash)
17
+ end
18
+ end
19
+
20
+ describe Mock, ".replaced_name" do
21
+ it "returns the name for a method that is being replaced by a mock method" do
22
+ Mock.replaced_name(:method_call).should == :__ms_method_call__
23
+ end
24
+ end
25
+
26
+ describe Mock, ".install_method" do
27
+ before :each do
28
+ @mock = mock('install_method')
29
+ MSpec.stub!(:actions)
30
+ MSpec.stub!(:current).and_return(mock("spec state", :null_object => true))
31
+ end
32
+
33
+ after :each do
34
+ Mock.cleanup
35
+ end
36
+
37
+ it "returns a MockProxy instance" do
38
+ Mock.install_method(@mock, :method_call).should be_an_instance_of(MockProxy)
39
+ end
40
+
41
+ it "sets the proxy to expect exactly 1 call" do
42
+ proxy = Mock.install_method(@mock, :method_call)
43
+ proxy.count.should == [:exactly, 1]
44
+ end
45
+
46
+ it "does not override a previously mocked method with the same name" do
47
+ Mock.install_method(@mock, :method_call).with(:a, :b).and_return(1)
48
+ Mock.install_method(@mock, :method_call).with(:c).and_return(2)
49
+ @mock.method_call(:a, :b)
50
+ @mock.method_call(:c)
51
+ lambda { @mock.method_call(:d) }.should raise_error(ExpectationNotMetError)
52
+ end
53
+
54
+ it "properly sends #respond_to? calls to the aliased respond_to? method when not matching mock expectations" do
55
+ Mock.install_method(@mock, :respond_to?).with(:to_str).and_return('mock to_str')
56
+ Mock.install_method(@mock, :respond_to?).with(:to_int).and_return('mock to_int')
57
+ @mock.respond_to?(:to_str).should == 'mock to_str'
58
+ @mock.respond_to?(:to_int).should == 'mock to_int'
59
+ @mock.respond_to?(:to_s).should == true
60
+ @mock.respond_to?(:not_really_a_real_method_seriously).should == false
61
+ end
62
+
63
+ it "adds to the expectation tally" do
64
+ state = mock("run state", :null_object => true)
65
+ state.stub!(:state).and_return(mock("spec state"))
66
+ MSpec.should_receive(:current).and_return(state)
67
+ MSpec.should_receive(:actions).with(:expectation, state.state)
68
+ Mock.install_method(@mock, :method_call).and_return(1)
69
+ end
70
+ end
71
+
72
+ describe Mock, ".verify_call" do
73
+ before :each do
74
+ MSpec.stub!(:actions)
75
+ MSpec.stub!(:current).and_return(mock("spec state", :null_object => true))
76
+
77
+ @mock = mock('verify_call')
78
+ @proxy = Mock.install_method @mock, :method_call
79
+ end
80
+
81
+ after :each do
82
+ ScratchPad.clear
83
+ Mock.cleanup
84
+ end
85
+
86
+ it "does not raise an exception when the mock method receives the expected arguments" do
87
+ @proxy.with(1, 'two', :three)
88
+ Mock.verify_call @mock, :method_call, 1, 'two', :three
89
+ end
90
+
91
+ it "raises an ExpectationNotMetError when the mock method does not receive the expected arguments" do
92
+ @proxy.with(4, 2)
93
+ lambda {
94
+ Mock.verify_call @mock, :method_call, 42
95
+ }.should raise_error(ExpectationNotMetError)
96
+ end
97
+
98
+ it "raises an ExpectationNotMetError when the mock method is called with arguments but expects none" do
99
+ lambda {
100
+ @proxy.with(:no_args)
101
+ Mock.verify_call @mock, :method_call, "hello"
102
+ }.should raise_error(ExpectationNotMetError)
103
+ end
104
+
105
+ it "raises an ExpectationNotMetError when the mock method is called with no arguments but expects some" do
106
+ @proxy.with("hello", "beautiful", "world")
107
+ lambda {
108
+ Mock.verify_call @mock, :method_call
109
+ }.should raise_error(ExpectationNotMetError)
110
+ end
111
+
112
+ it "does not raise an exception when the mock method is called with arguments and is expecting :any_args" do
113
+ @proxy.with(:any_args)
114
+ Mock.verify_call @mock, :method_call, 1, 2, 3
115
+ end
116
+
117
+ it "yields a passed block when it is expected to" do
118
+ @proxy.and_yield()
119
+ Mock.verify_call @mock, :method_call do
120
+ ScratchPad.record true
121
+ end
122
+ ScratchPad.recorded.should == true
123
+ end
124
+
125
+ it "does not yield a passed block when it is not expected to" do
126
+ Mock.verify_call @mock, :method_call do
127
+ ScratchPad.record true
128
+ end
129
+ ScratchPad.recorded.should == nil
130
+ end
131
+
132
+ it "can yield subsequently" do
133
+ @proxy.and_yield(1).and_yield(2).and_yield(3)
134
+
135
+ ScratchPad.record []
136
+ Mock.verify_call @mock, :method_call do |arg|
137
+ ScratchPad << arg
138
+ end
139
+ ScratchPad.recorded.should == [1, 2, 3]
140
+ end
141
+
142
+ it "can yield and return an expected value" do
143
+ @proxy.and_yield(1).and_return(3)
144
+
145
+ Mock.verify_call(@mock, :method_call) { |arg| ScratchPad.record arg }.should == 3
146
+ ScratchPad.recorded.should == 1
147
+ end
148
+
149
+ it "raises an expection when it is expected to yield but no block is given" do
150
+ @proxy.and_yield(1, 2, 3)
151
+ lambda {
152
+ Mock.verify_call(@mock, :method_call)
153
+ }.should raise_error(ExpectationNotMetError)
154
+ end
155
+
156
+ it "raises an expection when it is expected to yield more arguments than the block can take" do
157
+ @proxy.and_yield(1, 2, 3)
158
+ lambda {
159
+ Mock.verify_call(@mock, :method_call) {|a, b|}
160
+ }.should raise_error(ExpectationNotMetError)
161
+ end
162
+
163
+ it "does not raise an expection when it is expected to yield to a block that can take any number of arguments" do
164
+ @proxy.and_yield(1, 2, 3)
165
+ lambda {
166
+ Mock.verify_call(@mock, :method_call) {|*a|}
167
+ }.should_not raise_error(ExpectationNotMetError)
168
+ end
169
+ end
170
+
171
+ describe Mock, ".verify_count" do
172
+ before :each do
173
+ MSpec.stub!(:actions)
174
+ MSpec.stub!(:current).and_return(mock("spec state", :null_object => true))
175
+
176
+ @mock = mock('verify_count')
177
+ @proxy = Mock.install_method @mock, :method_call
178
+ end
179
+
180
+ after :each do
181
+ Mock.cleanup
182
+ end
183
+
184
+ it "does not raise an exception when the mock receives at least the expected number of calls" do
185
+ @proxy.at_least(2)
186
+ @mock.method_call
187
+ @mock.method_call
188
+ Mock.verify_count
189
+ end
190
+
191
+ it "raises an ExpectationNotMetError when the mock receives less than at least the expected number of calls" do
192
+ @proxy.at_least(2)
193
+ @mock.method_call
194
+ lambda { Mock.verify_count }.should raise_error(ExpectationNotMetError)
195
+ end
196
+
197
+ it "does not raise an exception when the mock receives at most the expected number of calls" do
198
+ @proxy.at_most(2)
199
+ @mock.method_call
200
+ @mock.method_call
201
+ Mock.verify_count
202
+ end
203
+
204
+ it "raises an ExpectationNotMetError when the mock receives more than at most the expected number of calls" do
205
+ @proxy.at_most(2)
206
+ @mock.method_call
207
+ @mock.method_call
208
+ @mock.method_call
209
+ lambda { Mock.verify_count }.should raise_error(ExpectationNotMetError)
210
+ end
211
+
212
+ it "does not raise an exception when the mock receives exactly the expected number of calls" do
213
+ @proxy.exactly(2)
214
+ @mock.method_call
215
+ @mock.method_call
216
+ Mock.verify_count
217
+ end
218
+
219
+ it "raises an ExpectationNotMetError when the mock receives less than exactly the expected number of calls" do
220
+ @proxy.exactly(2)
221
+ @mock.method_call
222
+ lambda { Mock.verify_count }.should raise_error(ExpectationNotMetError)
223
+ end
224
+
225
+ it "raises an ExpectationNotMetError when the mock receives more than exactly the expected number of calls" do
226
+ @proxy.exactly(2)
227
+ @mock.method_call
228
+ @mock.method_call
229
+ @mock.method_call
230
+ lambda { Mock.verify_count }.should raise_error(ExpectationNotMetError)
231
+ end
232
+ end
233
+
234
+ describe Mock, ".cleanup" do
235
+ before :each do
236
+ MSpec.stub!(:actions)
237
+ MSpec.stub!(:current).and_return(mock("spec state", :null_object => true))
238
+
239
+ @mock = mock('cleanup')
240
+ @proxy = Mock.install_method @mock, :method_call
241
+ end
242
+
243
+ after :each do
244
+ Mock.cleanup
245
+ end
246
+
247
+ it "removes the mock method call if it did not override an existing method" do
248
+ @mock.should respond_to(:method_call)
249
+
250
+ Mock.cleanup
251
+ @mock.should_not respond_to(:method_call)
252
+ end
253
+
254
+ it "removes the replaced method if the mock method overrides an existing method" do
255
+ def @mock.already_here() :hey end
256
+ @mock.should respond_to(:already_here)
257
+ Mock.install_method @mock, :already_here
258
+ @mock.should respond_to(Mock.replaced_name(:already_here))
259
+
260
+ Mock.cleanup
261
+ @mock.should_not respond_to(Mock.replaced_name(:already_here))
262
+ @mock.should respond_to(:already_here)
263
+ @mock.already_here.should == :hey
264
+ end
265
+
266
+ it "removes all mock expectations" do
267
+ Mock.expects.should == { [@mock, :method_call] => [@proxy] }
268
+
269
+ Mock.cleanup
270
+ Mock.expects.should == {}
271
+ end
272
+ end
@@ -0,0 +1,259 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/mocks/proxy'
3
+
4
+ describe MockProxy, "reporting method" do
5
+ before :each do
6
+ @proxy = MockProxy.new
7
+ end
8
+
9
+ it "returns the expected number of calls the mock should receive with #count" do
10
+ @proxy.count.should == [:exactly, 0]
11
+ end
12
+
13
+ it "returns the expected arguments with #arguments" do
14
+ @proxy.arguments.should == :any_args
15
+ end
16
+
17
+ it "returns the expected return value with #returning" do
18
+ @proxy.returning.should == nil
19
+ end
20
+ end
21
+
22
+ describe MockProxy, "#with" do
23
+ before :each do
24
+ @proxy = MockProxy.new
25
+ end
26
+
27
+ it "returns self" do
28
+ @proxy.with(:a).should be_equal(@proxy)
29
+ end
30
+
31
+ it "raises an ArgumentError if no arguments are given" do
32
+ lambda { @proxy.with }.should raise_error(ArgumentError)
33
+ end
34
+
35
+ it "accepts any number of arguments" do
36
+ @proxy.with(1, 2, 3).should be_an_instance_of(MockProxy)
37
+ @proxy.arguments.should == [1,2,3]
38
+ end
39
+ end
40
+
41
+ describe MockProxy, "#once" do
42
+ before :each do
43
+ @proxy = MockProxy.new
44
+ end
45
+
46
+ it "returns self" do
47
+ @proxy.once.should be_equal(@proxy)
48
+ end
49
+
50
+ it "sets the expected calls to 1" do
51
+ @proxy.once
52
+ @proxy.count.should == [:exactly, 1]
53
+ end
54
+
55
+ it "accepts no arguments" do
56
+ lambda { @proxy.once(:a) }.should raise_error
57
+ end
58
+ end
59
+
60
+ describe MockProxy, "#twice" do
61
+ before :each do
62
+ @proxy = MockProxy.new
63
+ end
64
+
65
+ it "returns self" do
66
+ @proxy.twice.should be_equal(@proxy)
67
+ end
68
+
69
+ it "sets the expected calls to 2" do
70
+ @proxy.twice
71
+ @proxy.count.should == [:exactly, 2]
72
+ end
73
+
74
+ it "accepts no arguments" do
75
+ lambda { @proxy.twice(:b) }.should raise_error
76
+ end
77
+ end
78
+
79
+ describe MockProxy, "#exactly" do
80
+ before :each do
81
+ @proxy = MockProxy.new
82
+ end
83
+
84
+ it "returns self" do
85
+ @proxy.exactly(2).should be_equal(@proxy)
86
+ end
87
+
88
+ it "sets the expected calls to exactly n" do
89
+ @proxy.exactly(5)
90
+ @proxy.count.should == [:exactly, 5]
91
+ end
92
+
93
+ it "does not accept an argument that Integer() cannot convert" do
94
+ lambda { @proxy.exactly('x') }.should raise_error
95
+ end
96
+ end
97
+
98
+ describe MockProxy, "#at_least" do
99
+ before :each do
100
+ @proxy = MockProxy.new
101
+ end
102
+
103
+ it "returns self" do
104
+ @proxy.at_least(3).should be_equal(@proxy)
105
+ end
106
+
107
+ it "sets the expected calls to at least n" do
108
+ @proxy.at_least(3)
109
+ @proxy.count.should == [:at_least, 3]
110
+ end
111
+
112
+ it "accepts :once :twice" do
113
+ @proxy.at_least(:once)
114
+ @proxy.count.should == [:at_least, 1]
115
+ @proxy.at_least(:twice)
116
+ @proxy.count.should == [:at_least, 2]
117
+ end
118
+
119
+ it "does not accept an argument that Integer() cannot convert" do
120
+ lambda { @proxy.at_least('x') }.should raise_error
121
+ end
122
+ end
123
+
124
+ describe MockProxy, "#at_most" do
125
+ before :each do
126
+ @proxy = MockProxy.new
127
+ end
128
+
129
+ it "returns self" do
130
+ @proxy.at_most(2).should be_equal(@proxy)
131
+ end
132
+
133
+ it "sets the expected calls to at most n" do
134
+ @proxy.at_most(2)
135
+ @proxy.count.should == [:at_most, 2]
136
+ end
137
+
138
+ it "accepts :once, :twice" do
139
+ @proxy.at_most(:once)
140
+ @proxy.count.should == [:at_most, 1]
141
+ @proxy.at_most(:twice)
142
+ @proxy.count.should == [:at_most, 2]
143
+ end
144
+
145
+ it "does not accept an argument that Integer() cannot convert" do
146
+ lambda { @proxy.at_most('x') }.should raise_error
147
+ end
148
+ end
149
+
150
+ describe MockProxy, "#any_number_of_times" do
151
+ before :each do
152
+ @proxy = MockProxy.new
153
+ end
154
+
155
+ it "returns self" do
156
+ @proxy.any_number_of_times.should be_equal(@proxy)
157
+ end
158
+
159
+ it "sets the expected calls to at least 0" do
160
+ @proxy.any_number_of_times
161
+ @proxy.count.should == [:at_least, 0]
162
+ end
163
+
164
+ it "does not accept an argument" do
165
+ lambda { @proxy.any_number_of_times(2) }.should raise_error
166
+ end
167
+ end
168
+
169
+ describe MockProxy, "#and_return" do
170
+ before :each do
171
+ @proxy = MockProxy.new
172
+ end
173
+
174
+ it "returns self" do
175
+ @proxy.and_return(false).should be_equal(@proxy)
176
+ end
177
+
178
+ it "sets the expected return value" do
179
+ @proxy.and_return(false)
180
+ @proxy.returning.should == false
181
+ end
182
+
183
+ it "accepts any number of return values" do
184
+ @proxy.and_return(1, 2, 3)
185
+ @proxy.returning.should == 1
186
+ @proxy.returning.should == 2
187
+ @proxy.returning.should == 3
188
+ end
189
+
190
+ it "implicitly sets the expected number of calls" do
191
+ @proxy.and_return(1, 2, 3)
192
+ @proxy.count.should == [:exactly, 3]
193
+ end
194
+
195
+ it "it only sets the expected number of calls if it is higher than what is already set" do
196
+ @proxy.at_least(5).times.and_return(1, 2, 3)
197
+ @proxy.count.should == [:at_least, 5]
198
+
199
+ @proxy.at_least(2).times.and_return(1, 2, 3)
200
+ @proxy.count.should == [:at_least, 3]
201
+ end
202
+ end
203
+
204
+ describe MockProxy, "#calls" do
205
+ before :each do
206
+ @proxy = MockProxy.new
207
+ end
208
+
209
+ it "returns the number of times the proxy is called" do
210
+ @proxy.calls.should == 0
211
+ end
212
+ end
213
+
214
+ describe MockProxy, "#called" do
215
+ before :each do
216
+ @proxy = MockProxy.new
217
+ end
218
+
219
+ it "increments the number of times the proxy is called" do
220
+ @proxy.called
221
+ @proxy.called
222
+ @proxy.calls.should == 2
223
+ end
224
+ end
225
+
226
+ describe MockProxy, "#returning" do
227
+ before :each do
228
+ @proxy = MockProxy.new
229
+ end
230
+
231
+ it "should return nil by default" do
232
+ @proxy.returning.should be_nil
233
+ end
234
+
235
+ it "should return the value set by #and_return" do
236
+ @proxy.and_return(2)
237
+ @proxy.returning.should == 2
238
+ end
239
+
240
+ it "should return a sequence of values set by #and_return" do
241
+ @proxy.and_return(1,2,3,4)
242
+ @proxy.returning.should == 1
243
+ @proxy.returning.should == 2
244
+ @proxy.returning.should == 3
245
+ @proxy.returning.should == 4
246
+ @proxy.returning.should == 4
247
+ @proxy.returning.should == 4
248
+ end
249
+ end
250
+
251
+ describe MockProxy, "#times" do
252
+ before :each do
253
+ @proxy = MockProxy.new
254
+ end
255
+
256
+ it "is a no-op" do
257
+ @proxy.times.should == @proxy
258
+ end
259
+ end