rr 0.10.10 → 0.10.11

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 (50) hide show
  1. data/CHANGES +4 -0
  2. data/VERSION.yml +1 -1
  3. data/lib/rr.rb +5 -3
  4. data/lib/rr/adapters/rr_methods.rb +5 -5
  5. data/lib/rr/blank_slate.rb +17 -0
  6. data/lib/rr/double_definitions/{child_double_definition_creator.rb → child_double_definition_create.rb} +1 -1
  7. data/lib/rr/double_definitions/double_definition.rb +13 -11
  8. data/lib/rr/double_definitions/{double_definition_creator.rb → double_definition_create.rb} +52 -43
  9. data/lib/rr/double_definitions/double_definition_create_blank_slate.rb +26 -0
  10. data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +2 -2
  11. data/lib/rr/double_definitions/strategies/scope/instance.rb +1 -1
  12. data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +6 -6
  13. data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +2 -2
  14. data/lib/rr/double_definitions/strategies/strategy.rb +15 -16
  15. data/lib/rr/double_definitions/strategies/verification/mock.rb +1 -1
  16. data/lib/rr/double_definitions/strategies/verification/stub.rb +1 -1
  17. data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +2 -2
  18. data/lib/rr/injections/double_injection.rb +59 -4
  19. data/lib/rr/injections/injection.rb +6 -0
  20. data/lib/rr/injections/method_missing_injection.rb +13 -1
  21. data/lib/rr/injections/singleton_method_added_injection.rb +14 -3
  22. data/lib/rr/method_dispatches/base_method_dispatch.rb +2 -2
  23. data/lib/rr/method_dispatches/method_missing_dispatch.rb +2 -2
  24. data/lib/rr/recorded_calls.rb +1 -1
  25. data/lib/rr/space.rb +17 -68
  26. data/lib/rr/spy_verification_proxy.rb +1 -6
  27. data/spec/rr/adapters/rr_methods_creator_spec.rb +9 -21
  28. data/spec/rr/adapters/rr_methods_space_spec.rb +10 -25
  29. data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +16 -16
  30. data/spec/rr/double_definitions/double_definition_create_blank_slate_spec.rb +87 -0
  31. data/spec/rr/double_definitions/{double_definition_creator_spec.rb → double_definition_create_spec.rb} +64 -72
  32. data/spec/rr/double_injection/double_injection_verify_spec.rb +2 -2
  33. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +5 -29
  34. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +7 -39
  35. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +19 -47
  36. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +1 -9
  37. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +18 -64
  38. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +7 -53
  39. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +12 -56
  40. data/spec/rr/rspec/rspec_adapter_spec.rb +8 -11
  41. data/spec/rr/space/space_spec.rb +72 -212
  42. data/spec/spec_helper.rb +0 -76
  43. data/spec/spy_verification_spec.rb +1 -1
  44. metadata +8 -11
  45. data/lib/rr/double_definitions/double_definition_creator_proxy.rb +0 -37
  46. data/ruby_19_spec.rb +0 -12
  47. data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +0 -124
  48. data/spec/rr/double_definitions/double_definition_spec.rb +0 -1168
  49. data/spec/rr/double_spec.rb +0 -361
  50. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +0 -38
@@ -1,361 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
-
3
- module RR
4
- describe Double do
5
- it_should_behave_like "Swapped Space"
6
- attr_reader :subject, :double_injection, :definition, :definition_creator, :double
7
- before do
8
- @subject = Object.new
9
- def subject.foobar(a, b)
10
- [b, a]
11
- end
12
- @double_injection = create_double_injection
13
- @definition_creator = DoubleDefinitions::DoubleDefinitionCreator.new
14
- @definition = DoubleDefinitions::DoubleDefinition.new(definition_creator, subject).
15
- any_number_of_times.
16
- with_any_args
17
- @double = Double.new(double_injection, definition)
18
- end
19
-
20
- def create_double_injection
21
- space.double_injection(subject, :foobar)
22
- end
23
-
24
- describe "#initialize" do
25
- it "registers self with associated DoubleInjection" do
26
- double_injection.doubles.should include(double)
27
- end
28
- end
29
-
30
- describe "#ordered?" do
31
- it "defaults to false" do
32
- double.should_not be_ordered
33
- end
34
- end
35
-
36
- describe "#call" do
37
- describe "when verbose" do
38
- attr_reader :original_stdout
39
- before do
40
- @original_stdout = $stdout
41
- end
42
-
43
- after do
44
- $stdout = original_stdout
45
- end
46
-
47
- it "prints the message call" do
48
- double.definition.verbose
49
- $stdout = StringIO.new(output = "")
50
- subject.foobar(1, 2)
51
- output.strip.should == Double.formatted_name(:foobar, [1, 2])
52
- end
53
- end
54
-
55
- describe "when not verbose" do
56
- it "does not print the message call" do
57
- output = nil
58
- (class << double; self; end).__send__(:define_method, :puts) do |output|
59
- output = output
60
- end
61
- subject.foobar(1, 2)
62
- output.should be_nil
63
- end
64
- end
65
-
66
- describe "when implemented by a lambda" do
67
- it "calls the return lambda when implemented by a lambda" do
68
- double.definition.returns {|arg| "returning #{arg}"}
69
- subject.foobar(:foobar).should == "returning foobar"
70
- end
71
-
72
- it "calls and returns the after_call when after_call is set" do
73
- double.definition.returns {|arg| "returning #{arg}"}.after_call do |value|
74
- "#{value} after call"
75
- end
76
- subject.foobar(:foobar).should == "returning foobar after call"
77
- end
78
-
79
- it "returns nil when to returns is not set" do
80
- subject.foobar.should be_nil
81
- end
82
-
83
- it "works when times_called is not set" do
84
- double.definition.returns {:value}
85
- subject.foobar
86
- end
87
-
88
- it "verifes the times_called does not exceed the TimesCalledExpectation" do
89
- double.definition.times(2).returns {:value}
90
-
91
- subject.foobar(:foobar)
92
- subject.foobar(:foobar)
93
- lambda {subject.foobar(:foobar)}.should raise_error(Errors::TimesCalledError)
94
- end
95
-
96
- it "raises DoubleOrderError when ordered and called out of order" do
97
- double1 = double
98
- double2 = Double.new(double_injection, DoubleDefinitions::DoubleDefinition.new(definition_creator, subject))
99
-
100
- double1.definition.with(1).returns {:return_1}.once.ordered
101
- double2.definition.with(2).returns {:return_2}.once.ordered
102
-
103
- lambda do
104
- subject.foobar(2)
105
- end.should raise_error(
106
- Errors::DoubleOrderError,
107
- "foobar(2) called out of order in list\n" <<
108
- "- foobar(1)\n" <<
109
- "- foobar(2)"
110
- )
111
- end
112
-
113
- it "dispatches to Space#verify_ordered_double when ordered" do
114
- verify_ordered_double_called = false
115
- passed_in_double = nil
116
- space.method(:verify_ordered_double).arity.should == 1
117
- (class << space; self; end).class_eval do
118
- define_method :verify_ordered_double do |double|
119
- passed_in_double = double
120
- verify_ordered_double_called = true
121
- end
122
- end
123
-
124
- double.definition.returns {:value}.ordered
125
- subject.foobar(:foobar)
126
- verify_ordered_double_called.should be_true
127
- passed_in_double.should === double
128
- end
129
-
130
- it "does not dispatche to Space#verify_ordered_double when not ordered" do
131
- verify_ordered_double_called = false
132
- space.method(:verify_ordered_double).arity.should == 1
133
- (class << space; self; end).class_eval do
134
- define_method :verify_ordered_double do |double|
135
- verify_ordered_double_called = true
136
- end
137
- end
138
-
139
- double.definition.returns {:value}
140
- subject.foobar(:foobar)
141
- verify_ordered_double_called.should be_false
142
- end
143
-
144
- it "does not add block argument if no block passed in" do
145
- double.definition.with(1, 2).returns {|*args| args}
146
-
147
- args = subject.foobar(1, 2)
148
- args.should == [1, 2]
149
- end
150
-
151
- it "makes the block the last argument" do
152
- double.definition.with(1, 2).returns {|a, b, blk| blk}
153
-
154
- block = subject.foobar(1, 2) {|a, b| [b, a]}
155
- block.call(3, 4).should == [4, 3]
156
- end
157
-
158
- it "raises ArgumentError when yields was called and no block passed in" do
159
- double.definition.with(1, 2).yields(55)
160
-
161
- lambda do
162
- subject.foobar(1, 2)
163
- end.should raise_error(ArgumentError, "A Block must be passed into the method call when using yields")
164
- end
165
- end
166
-
167
- describe "when implemented by a method" do
168
- it "sends block to the method" do
169
- class << subject
170
- remove_method :foobar
171
- def foobar(a, b)
172
- yield(a, b)
173
- end
174
- end
175
-
176
- double.definition.with(1, 2).implemented_by(subject.method(:foobar))
177
-
178
- subject.foobar(1, 2) {|a, b| [b, a]}.should == [2, 1]
179
- end
180
- end
181
- end
182
-
183
- describe "#exact_match?" do
184
- context "when no expectation is set" do
185
- it "raises a DoubleDefinitionError" do
186
- double.definition.argument_expectation = nil
187
- lambda do
188
- double.exact_match?
189
- end.should raise_error(Errors::DoubleDefinitionError)
190
- end
191
- end
192
-
193
- context "when arguments are not an exact match" do
194
- it "returns false" do
195
- double.definition.with(1, 2, 3)
196
- double.should_not be_exact_match(1, 2)
197
- double.should_not be_exact_match(1)
198
- double.should_not be_exact_match()
199
- double.should_not be_exact_match("does not match")
200
- end
201
- end
202
-
203
- context "when arguments are an exact match" do
204
- it "returns true" do
205
- double.definition.with(1, 2, 3)
206
- double.should be_exact_match(1, 2, 3)
207
- end
208
- end
209
- end
210
-
211
- describe "#wildcard_match?" do
212
- context "when no expectation set" do
213
- it "raises a DoubleDefinitionError" do
214
- double.definition.argument_expectation = nil
215
- lambda do
216
- double.wildcard_match?
217
- end.should raise_error(Errors::DoubleDefinitionError)
218
- end
219
- end
220
-
221
- context "when arguments are an exact match" do
222
- it "returns true" do
223
- double.definition.with(1, 2, 3)
224
- double.should be_wildcard_match(1, 2, 3)
225
- double.should_not be_wildcard_match(1, 2)
226
- double.should_not be_wildcard_match(1)
227
- double.should_not be_wildcard_match()
228
- double.should_not be_wildcard_match("does not match")
229
- end
230
- end
231
-
232
- context "when with_any_args" do
233
- it "returns true" do
234
- double.definition.with_any_args
235
-
236
- double.should be_wildcard_match(1, 2, 3)
237
- double.should be_wildcard_match(1, 2)
238
- double.should be_wildcard_match(1)
239
- double.should be_wildcard_match()
240
- double.should be_wildcard_match("does not match")
241
- end
242
- end
243
- end
244
-
245
- describe "#attempt?" do
246
- context "when TimesCalledExpectation#attempt? is true" do
247
- it "returns true" do
248
- double.definition.with(1, 2, 3).twice
249
- subject.foobar(1, 2, 3)
250
- double.times_called_expectation.should be_attempt
251
- double.should be_attempt
252
- end
253
- end
254
-
255
- context "when TimesCalledExpectation#attempt? is true" do
256
- it "returns false" do
257
- double.definition.with(1, 2, 3).twice
258
- subject.foobar(1, 2, 3)
259
- subject.foobar(1, 2, 3)
260
- double.times_called_expectation.should_not be_attempt
261
- double.should_not be_attempt
262
- end
263
- end
264
-
265
- context "when there is no Times Called expectation" do
266
- it "raises a DoubleDefinitionError" do
267
- double.definition.with(1, 2, 3)
268
- double.definition.times_matcher = nil
269
- lambda do
270
- double.should be_attempt
271
- end.should raise_error(RR::Errors::DoubleDefinitionError)
272
- end
273
- end
274
- end
275
-
276
- describe "#verify" do
277
- it "verifies that times called expectation was met" do
278
- double.definition.twice.returns {:return_value}
279
-
280
- lambda {double.verify}.should raise_error(Errors::TimesCalledError)
281
- subject.foobar
282
- lambda {double.verify}.should raise_error(Errors::TimesCalledError)
283
- subject.foobar
284
-
285
- lambda {double.verify}.should_not raise_error
286
- end
287
-
288
- it "does not raise an error when there is no times called expectation" do
289
- lambda {double.verify}.should_not raise_error
290
- subject.foobar
291
- lambda {double.verify}.should_not raise_error
292
- subject.foobar
293
- lambda {double.verify}.should_not raise_error
294
- end
295
- end
296
-
297
- describe "#terminal?" do
298
- context "when times_called_expectation's terminal? is true" do
299
- it "returns true" do
300
- double.definition.once
301
- double.times_called_expectation.should be_terminal
302
- double.should be_terminal
303
- end
304
- end
305
-
306
- context "when times_called_expectation's terminal? is false" do
307
- it "returns false" do
308
- double.definition.any_number_of_times
309
- double.times_called_expectation.should_not be_terminal
310
- double.should_not be_terminal
311
- end
312
- end
313
-
314
- context "when there is no times_matcher" do
315
- it "raises a DoubleDefinitionError" do
316
- double.definition.times_matcher = nil
317
- lambda do
318
- double.should_not be_terminal
319
- end.should raise_error(RR::Errors::DoubleDefinitionError)
320
- end
321
- end
322
- end
323
-
324
- describe "#method_name" do
325
- it "returns the DoubleInjection's method_name" do
326
- double_injection.method_name.should == :foobar
327
- double.method_name.should == :foobar
328
- end
329
- end
330
-
331
- describe "#expected_arguments" do
332
- context "when there is an argument expectation" do
333
- it "returns argument expectation's expected_arguments" do
334
- double.definition.with(1, 2)
335
- double.definition.argument_expectation.should_not be_nil
336
- double.expected_arguments.should == [1, 2]
337
- end
338
- end
339
-
340
- context "when there is no argument expectation" do
341
- it "raises an DoubleDefinitionError" do
342
- double.definition.argument_expectation = nil
343
- lambda do
344
- double.expected_arguments
345
- end.should raise_error(Errors::DoubleDefinitionError)
346
- end
347
- end
348
- end
349
-
350
- describe "#formatted_name" do
351
- it "renders the formatted name of the Double with no arguments" do
352
- double.formatted_name.should == "foobar()"
353
- end
354
-
355
- it "renders the formatted name of the Double with arguments" do
356
- double.definition.with(1, 2)
357
- double.formatted_name.should == "foobar(1, 2)"
358
- end
359
- end
360
- end
361
- end
@@ -1,38 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
-
3
- module RR
4
- module Expectations
5
- describe TimesCalledExpectation do
6
- context "with a failure" do
7
- it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
- attr_reader :times, :matcher, :expectation
9
-
10
- before do
11
- @times = 0
12
- double.definition.times(0)
13
- @matcher = double.definition.times_matcher
14
- @expectation = TimesCalledExpectation.new(double)
15
- end
16
-
17
- describe "#attempt!" do
18
- it "raises error that includes the double" do
19
- lambda {expectation.attempt}.should raise_error(
20
- RR::Errors::TimesCalledError,
21
- "#{double.formatted_name}\n#{matcher.error_message(1)}"
22
- )
23
- end
24
- end
25
-
26
- describe "#verify!" do
27
- it "raises error with passed in message prepended" do
28
- expectation.instance_variable_set(:@times_called, 1)
29
- lambda {expectation.verify!}.should raise_error(
30
- RR::Errors::TimesCalledError,
31
- "#{double.formatted_name}\n#{matcher.error_message(1)}"
32
- )
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end