rr 1.0.4 → 1.0.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.
Files changed (121) hide show
  1. checksums.yaml +15 -0
  2. data/CHANGES.md +392 -0
  3. data/Gemfile +7 -10
  4. data/README.md +822 -0
  5. data/Rakefile +24 -78
  6. data/VERSION +1 -0
  7. data/lib/rr/adapters/minitest.rb +6 -0
  8. data/lib/rr/adapters/rr_methods.rb +6 -10
  9. data/lib/rr/adapters/rspec.rb +3 -0
  10. data/lib/rr/adapters/rspec2.rb +30 -0
  11. data/lib/rr/adapters/test_unit.rb +2 -0
  12. data/lib/rr/double.rb +3 -2
  13. data/lib/rr/double_definitions/child_double_definition_create.rb +3 -2
  14. data/lib/rr/double_definitions/double_definition.rb +15 -13
  15. data/lib/rr/double_definitions/double_definition_create.rb +9 -5
  16. data/lib/rr/double_definitions/double_injections/any_instance_of.rb +3 -2
  17. data/lib/rr/double_definitions/strategies/strategy.rb +5 -4
  18. data/lib/rr/double_definitions/strategies/strategy_methods.rb +6 -8
  19. data/lib/rr/double_definitions/strategies/verification/mock.rb +3 -3
  20. data/lib/rr/double_matches.rb +2 -1
  21. data/lib/rr/expectations/argument_equality_expectation.rb +2 -2
  22. data/lib/rr/expectations/times_called_expectation.rb +2 -2
  23. data/lib/rr/injections/double_injection.rb +12 -11
  24. data/lib/rr/injections/injection.rb +2 -2
  25. data/lib/rr/injections/method_missing_injection.rb +21 -7
  26. data/lib/rr/injections/singleton_method_added_injection.rb +3 -1
  27. data/lib/rr/method_dispatches/base_method_dispatch.rb +1 -1
  28. data/lib/rr/method_dispatches/method_dispatch.rb +2 -1
  29. data/lib/rr/method_dispatches/method_missing_dispatch.rb +2 -1
  30. data/lib/rr/proc_from_block.rb +8 -4
  31. data/lib/rr/space.rb +3 -2
  32. data/lib/rr/times_called_matchers/times_called_matcher.rb +2 -2
  33. data/lib/rr/version.rb +5 -0
  34. data/lib/rr/wildcard_matchers/boolean.rb +2 -2
  35. data/lib/rr.rb +3 -0
  36. data/spec/runner.rb +41 -0
  37. metadata +45 -133
  38. data/.gitignore +0 -10
  39. data/.runrc +0 -3
  40. data/.rvmrc +0 -2
  41. data/CHANGES +0 -266
  42. data/Gemfile.lock +0 -31
  43. data/README.rdoc +0 -392
  44. data/benchmarks/rr_benchmark.rb +0 -32
  45. data/benchmarks/rspec_benchmark.rb +0 -14
  46. data/doc/0.6.0.release.markdown +0 -81
  47. data/doc/todo.txt +0 -0
  48. data/introducting_rr.txt +0 -206
  49. data/rr.gemspec +0 -37
  50. data/spec/api/any_instance_of/all_instances_of_spec.rb +0 -12
  51. data/spec/api/any_instance_of/any_instance_of_spec.rb +0 -47
  52. data/spec/api/any_instance_of/instance_of_spec.rb +0 -12
  53. data/spec/api/dont_allow/dont_allow_after_stub_spec.rb +0 -14
  54. data/spec/api/mock/mock_spec.rb +0 -193
  55. data/spec/api/proxy/proxy_spec.rb +0 -86
  56. data/spec/api/spy/spy_spec.rb +0 -49
  57. data/spec/api/strong/strong_spec.rb +0 -87
  58. data/spec/api/stub/stub_spec.rb +0 -152
  59. data/spec/core_spec_suite.rb +0 -19
  60. data/spec/environment_fixture_setup.rb +0 -8
  61. data/spec/minitest_spec_suite.rb +0 -21
  62. data/spec/proc_from_block_spec.rb +0 -14
  63. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +0 -67
  64. data/spec/rr/adapters/rr_methods_creator_spec.rb +0 -137
  65. data/spec/rr/adapters/rr_methods_space_spec.rb +0 -98
  66. data/spec/rr/adapters/rr_methods_spec_helper.rb +0 -11
  67. data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +0 -13
  68. data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +0 -112
  69. data/spec/rr/double_definitions/double_definition_create_blank_slate_spec.rb +0 -91
  70. data/spec/rr/double_definitions/double_definition_create_spec.rb +0 -443
  71. data/spec/rr/double_injection/double_injection_spec.rb +0 -546
  72. data/spec/rr/double_injection/double_injection_verify_spec.rb +0 -29
  73. data/spec/rr/errors/rr_error_spec.rb +0 -67
  74. data/spec/rr/expectations/any_argument_expectation_spec.rb +0 -47
  75. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +0 -14
  76. data/spec/rr/expectations/argument_equality_expectation_spec.rb +0 -135
  77. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +0 -34
  78. data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +0 -82
  79. data/spec/rr/expectations/hash_including_spec.rb +0 -17
  80. data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +0 -59
  81. data/spec/rr/expectations/satisfy_spec.rb +0 -14
  82. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +0 -22
  83. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +0 -37
  84. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +0 -43
  85. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +0 -15
  86. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +0 -58
  87. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +0 -35
  88. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +0 -39
  89. data/spec/rr/minitest/minitest_integration_test.rb +0 -59
  90. data/spec/rr/minitest/test_helper.rb +0 -7
  91. data/spec/rr/rspec/invocation_matcher_spec.rb +0 -279
  92. data/spec/rr/rspec/rspec_adapter_spec.rb +0 -63
  93. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +0 -31
  94. data/spec/rr/rspec/rspec_backtrace_tweaking_spec_fixture.rb +0 -11
  95. data/spec/rr/rspec/rspec_usage_spec.rb +0 -86
  96. data/spec/rr/space/hash_with_object_id_key_spec.rb +0 -88
  97. data/spec/rr/space/space_spec.rb +0 -596
  98. data/spec/rr/test_unit/test_helper.rb +0 -7
  99. data/spec/rr/test_unit/test_unit_backtrace_test.rb +0 -36
  100. data/spec/rr/test_unit/test_unit_integration_test.rb +0 -59
  101. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +0 -47
  102. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +0 -55
  103. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +0 -70
  104. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +0 -70
  105. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +0 -55
  106. data/spec/rr/times_called_matchers/range_matcher_spec.rb +0 -76
  107. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +0 -118
  108. data/spec/rr/wildcard_matchers/anything_spec.rb +0 -24
  109. data/spec/rr/wildcard_matchers/boolean_spec.rb +0 -36
  110. data/spec/rr/wildcard_matchers/duck_type_spec.rb +0 -52
  111. data/spec/rr/wildcard_matchers/is_a_spec.rb +0 -32
  112. data/spec/rr/wildcard_matchers/numeric_spec.rb +0 -32
  113. data/spec/rr/wildcard_matchers/range_spec.rb +0 -35
  114. data/spec/rr/wildcard_matchers/regexp_spec.rb +0 -43
  115. data/spec/rr_spec.rb +0 -28
  116. data/spec/rspec_spec_suite.rb +0 -17
  117. data/spec/spec.opts +0 -10
  118. data/spec/spec_helper.rb +0 -41
  119. data/spec/spec_suite.rb +0 -54
  120. data/spec/spy_verification_spec.rb +0 -129
  121. data/spec/test_unit_spec_suite.rb +0 -21
@@ -1,443 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
-
3
- module RR
4
- module DoubleDefinitions
5
- describe DoubleDefinitionCreate do
6
- attr_reader :double_definition_create, :subject, :strategy_method_name
7
- it_should_behave_like "Swapped Space"
8
- before(:each) do
9
- @subject = Object.new
10
- @double_definition_create = DoubleDefinitionCreate.new
11
- end
12
-
13
- describe "#root_subject" do
14
- it "returns #subject" do
15
- double_definition_create.stub(subject).foobar
16
- double_definition_create.root_subject.should == subject
17
- end
18
- end
19
-
20
- describe "StrategySetupMethods" do
21
- describe "normal strategy definitions" do
22
- def call_strategy(*args, &block)
23
- double_definition_create.__send__(strategy_method_name, *args, &block)
24
- end
25
-
26
- describe "#mock" do
27
- before do
28
- @strategy_method_name = :mock
29
- end
30
-
31
- context "when passing no args" do
32
- it "returns self" do
33
- call_strategy.should === double_definition_create
34
- end
35
- end
36
-
37
- context "when passed a subject and a method_name argument" do
38
- it "creates a mock Double for method" do
39
- double_definition = double_definition_create.mock(subject, :foobar).returns {:baz}
40
- double_definition.times_matcher.should == RR::TimesCalledMatchers::IntegerMatcher.new(1)
41
- double_definition.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
42
- double_definition.argument_expectation.expected_arguments.should == []
43
- subject.foobar.should == :baz
44
- end
45
- end
46
- end
47
-
48
- describe "#stub" do
49
- before do
50
- @strategy_method_name = :stub
51
- end
52
-
53
- context "when passing no args" do
54
- it "returns self" do
55
- call_strategy.should === double_definition_create
56
- end
57
- end
58
-
59
- context "when passed subject and a method_name argument" do
60
- it "creates a stub Double for method when passed a method_name argument" do
61
- double_definition = double_definition_create.stub(subject, :foobar).returns {:baz}
62
- double_definition.times_matcher.should == RR::TimesCalledMatchers::AnyTimesMatcher.new
63
- double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
64
- subject.foobar.should == :baz
65
- end
66
- end
67
- end
68
-
69
- describe "#dont_allow" do
70
- before do
71
- @strategy_method_name = :dont_allow
72
- end
73
-
74
- context "when passing no args" do
75
- it "returns self" do
76
- call_strategy.should === double_definition_create
77
- end
78
- end
79
-
80
- context "when passed a subject and a method_name argument_expectation" do
81
- it "creates a mock Double for method" do
82
- double_definition = double_definition_create.dont_allow(subject, :foobar)
83
- double_definition.times_matcher.should == RR::TimesCalledMatchers::NeverMatcher.new
84
- double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
85
-
86
- lambda do
87
- subject.foobar
88
- end.should raise_error(RR::Errors::TimesCalledError)
89
- RR.reset
90
- end
91
- end
92
- end
93
- end
94
-
95
- describe "! strategy definitions" do
96
- attr_reader :strategy_method_name
97
- def call_strategy(*args, &definition_eval_block)
98
- double_definition_create.__send__(strategy_method_name, *args, &definition_eval_block)
99
- end
100
-
101
- describe "#mock!" do
102
- before do
103
- @strategy_method_name = :mock!
104
- end
105
-
106
- context "when passed a method_name argument" do
107
- it "sets #verification_strategy to Mock" do
108
- double_definition_create.mock!(:foobar)
109
- double_definition_create.verification_strategy.class.should == Strategies::Verification::Mock
110
- lambda {RR.verify}.should raise_error(::RR::Errors::TimesCalledError)
111
- end
112
- end
113
- end
114
-
115
- describe "#stub!" do
116
- before do
117
- @strategy_method_name = :stub!
118
- end
119
-
120
- context "when passed a method_name argument" do
121
- it "sets #verification_strategy to Stub" do
122
- double_definition_create.stub!(:foobar)
123
- double_definition_create.verification_strategy.class.should == Strategies::Verification::Stub
124
- end
125
- end
126
- end
127
-
128
- describe "#dont_allow!" do
129
- before do
130
- @strategy_method_name = :dont_allow!
131
- end
132
-
133
- context "when passed a method_name argument" do
134
- it "sets #verification_strategy to DontAllow" do
135
- double_definition_create.dont_allow!(:foobar)
136
- double_definition_create.verification_strategy.class.should == Strategies::Verification::DontAllow
137
- end
138
- end
139
- end
140
- end
141
-
142
- describe "#stub.proxy" do
143
- before do
144
- class << subject
145
- def foobar(*args)
146
- :original_foobar
147
- end
148
- end
149
- end
150
-
151
- context "when passed a method_name argument" do
152
- it "creates a proxy Double for method" do
153
- double_definition = double_definition_create.stub.proxy(subject, :foobar).after_call {:baz}
154
- double_definition.times_matcher.should == RR::TimesCalledMatchers::AnyTimesMatcher.new
155
- double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
156
- subject.foobar.should == :baz
157
- end
158
- end
159
- end
160
-
161
- describe "#instance_of" do
162
- context "when not passed a class" do
163
- it "raises an ArgumentError" do
164
- lambda do
165
- double_definition_create.instance_of(Object.new).foobar
166
- end.should raise_error(ArgumentError, "instance_of only accepts class objects")
167
- end
168
- end
169
-
170
- context "when passed a method_name argument" do
171
- it "creates a proxy Double for method" do
172
- klass = Class.new
173
- double_definition = double_definition_create.stub.instance_of(klass, :foobar).returns {:baz}
174
- double_definition.times_matcher.should == RR::TimesCalledMatchers::AnyTimesMatcher.new
175
- double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
176
- klass.new.foobar.should == :baz
177
- end
178
- end
179
- end
180
-
181
- describe "#instance_of.mock" do
182
- before do
183
- @klass = Class.new
184
- end
185
-
186
- # context "when passed no arguments" do
187
- # it "returns a DoubleDefinitiondouble_definition_create" do
188
- # instance_of.instance_of.should be_instance_of(DoubleDefinitionCreate)
189
- # end
190
- # end
191
-
192
- context "when passed a method_name argument" do
193
- it "creates a instance_of Double for method" do
194
- double_definition = instance_of.mock(@klass, :foobar)
195
- double_definition.with(1, 2) {:baz}
196
- double_definition.times_matcher.should == RR::TimesCalledMatchers::IntegerMatcher.new(1)
197
- double_definition.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
198
- double_definition.argument_expectation.expected_arguments.should == [1, 2]
199
-
200
- @klass.new.foobar(1, 2).should == :baz
201
- end
202
- end
203
- end
204
- end
205
-
206
- describe "StrategyExecutionMethods" do
207
- describe "#create" do
208
- context "when #verification_strategy is a Mock" do
209
- context "when #implementation_strategy is a Reimplementation" do
210
- before do
211
- double_definition_create.mock(subject)
212
- end
213
-
214
- it "sets expectation on the #subject that it will be sent the method_name once with the passed-in arguments" do
215
- mock(subject).foobar(1, 2)
216
- subject.foobar(1, 2)
217
- lambda {subject.foobar(1, 2)}.should raise_error(RR::Errors::TimesCalledError)
218
- lambda {RR.verify}.should raise_error(RR::Errors::TimesCalledError)
219
- end
220
-
221
- describe "#subject.method_name being called" do
222
- it "returns the return value of the Double#returns block" do
223
- double_definition_create.call(:foobar, 1, 2) {:baz}
224
- subject.foobar(1, 2).should == :baz
225
- end
226
- end
227
- end
228
-
229
- context "when #implementation_strategy is a Proxy" do
230
- before do
231
- double_definition_create.mock
232
- double_definition_create.proxy(subject)
233
- end
234
-
235
- it "sets expectation on the #subject that it will be sent the method_name once with the passed-in arguments" do
236
- def subject.foobar(*args)
237
- :baz
238
- end
239
- mock(subject).foobar(1, 2)
240
-
241
- subject.foobar(1, 2)
242
- lambda {subject.foobar(1, 2)}.should raise_error(RR::Errors::TimesCalledError)
243
- lambda {RR.verify}.should raise_error(RR::Errors::TimesCalledError)
244
- end
245
-
246
- describe "#subject.method_name being called" do
247
- it "calls the original method" do
248
- original_method_called = false
249
- (class << subject; self; end).class_eval do
250
- define_method(:foobar) do |*args|
251
- original_method_called = true
252
- end
253
- end
254
- double_definition_create.call(:foobar, 1, 2)
255
- subject.foobar(1, 2)
256
- original_method_called.should be_true
257
- end
258
-
259
- context "when not passed a block" do
260
- it "returns the value of the original method" do
261
- def subject.foobar(*args)
262
- :baz;
263
- end
264
- double_definition_create.call(:foobar, 1, 2)
265
- subject.foobar(1, 2).should == :baz
266
- end
267
- end
268
-
269
- context "when passed a block" do
270
- attr_reader :real_value
271
- before do
272
- @real_value = real_value = Object.new
273
- (class << subject; self; end).class_eval do
274
- define_method(:foobar) {|arg1, arg2| real_value}
275
- end
276
- end
277
-
278
- it "calls the block with the return value of the original method" do
279
- double_definition_create.call(:foobar, 1, 2) do |value|
280
- mock(value).a_method {99}
281
- value
282
- end
283
- subject.foobar(1, 2)
284
- real_value.a_method.should == 99
285
- end
286
-
287
- it "returns the return value of the block" do
288
- double_definition_create.call(:foobar, 1, 2) do |value|
289
- :something_else
290
- end
291
- subject.foobar(1, 2).should == :something_else
292
- end
293
- end
294
- end
295
- end
296
- end
297
-
298
- context "when #verification_strategy is a Stub" do
299
- context "when #implementation_strategy is a Reimplementation" do
300
- before do
301
- double_definition_create.stub(subject)
302
- end
303
-
304
- context "when not passed a block" do
305
- it "returns nil" do
306
- double_definition_create.call(:foobar)
307
- subject.foobar.should be_nil
308
- end
309
- end
310
-
311
- context "when passed a block" do
312
- describe "#subject.method_name being called" do
313
- it "returns the return value of the block" do
314
- double_definition_create.call(:foobar) {:baz}
315
- subject.foobar.should == :baz
316
- end
317
- end
318
- end
319
-
320
- context "when not passed args" do
321
- describe "#subject.method_name being called with any arguments" do
322
- it "invokes the implementation of the Stub" do
323
- double_definition_create.call(:foobar) {:baz}
324
- subject.foobar(1, 2).should == :baz
325
- subject.foobar().should == :baz
326
- subject.foobar([]).should == :baz
327
- end
328
- end
329
- end
330
-
331
- context "when passed args" do
332
- describe "#subject.method_name being called with the passed-in arguments" do
333
- it "invokes the implementation of the Stub" do
334
- double_definition_create.call(:foobar, 1, 2) {:baz}
335
- subject.foobar(1, 2).should == :baz
336
- end
337
- end
338
-
339
- describe "#subject.method_name being called with different arguments" do
340
- it "raises a DoubleNotFoundError" do
341
- double_definition_create.call(:foobar, 1, 2) {:baz}
342
- lambda do
343
- subject.foobar
344
- end.should raise_error(RR::Errors::DoubleNotFoundError)
345
- end
346
- end
347
- end
348
- end
349
-
350
- context "when #implementation_strategy is a Proxy" do
351
- before do
352
- def subject.foobar(*args)
353
- :original_return_value
354
- end
355
- double_definition_create.stub
356
- double_definition_create.proxy(subject)
357
- end
358
-
359
- context "when not passed a block" do
360
- describe "#subject.method_name being called" do
361
- it "invokes the original implementanion" do
362
- double_definition_create.call(:foobar)
363
- subject.foobar.should == :original_return_value
364
- end
365
- end
366
- end
367
-
368
- context "when passed a block" do
369
- describe "#subject.method_name being called" do
370
- it "invokes the original implementanion and invokes the block with the return value of the original implementanion" do
371
- passed_in_value = nil
372
- double_definition_create.call(:foobar) do |original_return_value|
373
- passed_in_value = original_return_value
374
- end
375
- subject.foobar
376
- passed_in_value.should == :original_return_value
377
- end
378
-
379
- it "returns the return value of the block" do
380
- double_definition_create.call(:foobar) do |original_return_value|
381
- :new_return_value
382
- end
383
- subject.foobar.should == :new_return_value
384
- end
385
- end
386
- end
387
-
388
- context "when passed args" do
389
- describe "#subject.method_name being called with the passed-in arguments" do
390
- it "invokes the implementation of the Stub" do
391
- double_definition_create.call(:foobar, 1, 2) {:baz}
392
- subject.foobar(1, 2).should == :baz
393
- end
394
- end
395
-
396
- describe "#subject.method_name being called with different arguments" do
397
- it "raises a DoubleNotFoundError" do
398
- double_definition_create.call(:foobar, 1, 2) {:baz}
399
- lambda do
400
- subject.foobar
401
- end.should raise_error(RR::Errors::DoubleNotFoundError)
402
- end
403
- end
404
- end
405
- end
406
- end
407
-
408
- context "when #verification_strategy is a DontAllow" do
409
- before do
410
- double_definition_create.dont_allow(subject)
411
- end
412
-
413
- context "when not passed args" do
414
- describe "#subject.method_name being called with any arguments" do
415
- it "raises a TimesCalledError" do
416
- double_definition_create.call(:foobar)
417
- lambda {subject.foobar}.should raise_error(RR::Errors::TimesCalledError)
418
- lambda {subject.foobar(1, 2)}.should raise_error(RR::Errors::TimesCalledError)
419
- end
420
- end
421
- end
422
-
423
- context "when passed args" do
424
- describe "#subject.method_name being called with the passed-in arguments" do
425
- it "raises a TimesCalledError" do
426
- double_definition_create.call(:foobar, 1, 2)
427
- lambda {subject.foobar(1, 2)}.should raise_error(RR::Errors::TimesCalledError)
428
- end
429
- end
430
-
431
- describe "#subject.method_name being called with different arguments" do
432
- it "raises a DoubleNotFoundError" do
433
- double_definition_create.call(:foobar, 1, 2)
434
- lambda {subject.foobar()}.should raise_error(RR::Errors::DoubleNotFoundError)
435
- end
436
- end
437
- end
438
- end
439
- end
440
- end
441
- end
442
- end
443
- end