rr 1.1.2 → 3.0.2

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 (157) hide show
  1. checksums.yaml +5 -5
  2. data/Appraisals +3 -43
  3. data/CHANGES.md +93 -0
  4. data/CREDITS.md +5 -0
  5. data/Gemfile +1 -17
  6. data/README.md +29 -32
  7. data/Rakefile +42 -40
  8. data/doc/02_syntax_comparison.md +1 -0
  9. data/lib/rr/class_instance_method_defined.rb +1 -1
  10. data/lib/rr/core_ext/array.rb +2 -0
  11. data/lib/rr/core_ext/hash.rb +2 -0
  12. data/lib/rr/deprecations.rb +97 -0
  13. data/lib/rr/double.rb +28 -10
  14. data/lib/rr/double_definitions/double_definition.rb +39 -16
  15. data/lib/rr/double_definitions/double_definition_create.rb +5 -5
  16. data/lib/rr/double_definitions/double_definition_create_blank_slate.rb +10 -4
  17. data/lib/rr/double_definitions/double_injections/any_instance_of.rb +1 -1
  18. data/lib/rr/double_definitions/double_injections/instance.rb +2 -2
  19. data/lib/rr/double_definitions/strategies/strategy.rb +27 -8
  20. data/lib/rr/double_definitions/strategies/verification/mock.rb +8 -2
  21. data/lib/rr/double_matches.rb +4 -3
  22. data/lib/rr/dsl.rb +152 -0
  23. data/lib/rr/expectations/any_argument_expectation.rb +4 -4
  24. data/lib/rr/expectations/argument_equality_expectation.rb +43 -5
  25. data/lib/rr/injections/double_injection.rb +85 -26
  26. data/lib/rr/injections/method_missing_injection.rb +37 -6
  27. data/lib/rr/integrations/minitest_4.rb +1 -1
  28. data/lib/rr/integrations/minitest_4_active_support.rb +1 -1
  29. data/lib/rr/integrations/rspec/invocation_matcher.rb +0 -8
  30. data/lib/rr/integrations/rspec_2.rb +20 -2
  31. data/lib/rr/keyword_arguments.rb +15 -0
  32. data/lib/rr/method_dispatches/base_method_dispatch.rb +22 -5
  33. data/lib/rr/method_dispatches/method_dispatch.rb +21 -10
  34. data/lib/rr/method_dispatches/method_missing_dispatch.rb +14 -5
  35. data/lib/rr/recorded_call.rb +35 -0
  36. data/lib/rr/recorded_calls.rb +23 -9
  37. data/lib/rr/space.rb +15 -5
  38. data/lib/rr/spy_verification.rb +13 -5
  39. data/lib/rr/version.rb +1 -1
  40. data/lib/rr/wildcard_matchers.rb +10 -10
  41. data/lib/rr/without_autohook.rb +7 -14
  42. data/rr.gemspec +8 -3
  43. data/spec/defines_spec_suite_tasks.rb +12 -0
  44. data/spec/global_helper.rb +5 -0
  45. data/spec/spec_suite_configuration.rb +1 -7
  46. data/spec/suites.yml +0 -14
  47. data/spec/suites/rspec_2/functional/any_instance_of_spec.rb +133 -33
  48. data/spec/suites/rspec_2/functional/dont_allow_spec.rb +13 -8
  49. data/spec/suites/rspec_2/functional/mock_bang_spec.rb +20 -0
  50. data/spec/suites/rspec_2/functional/mock_instance_of_spec.rb +14 -0
  51. data/spec/suites/rspec_2/functional/mock_instance_of_strong_spec.rb +15 -0
  52. data/spec/suites/rspec_2/functional/mock_proxy_instance_of_spec.rb +15 -0
  53. data/spec/suites/rspec_2/functional/mock_proxy_spec.rb +14 -0
  54. data/spec/suites/rspec_2/functional/mock_spec.rb +8 -232
  55. data/spec/suites/rspec_2/functional/mock_strong_spec.rb +14 -0
  56. data/spec/suites/rspec_2/functional/received_spec.rb +16 -0
  57. data/spec/suites/rspec_2/functional/spy_spec.rb +89 -28
  58. data/spec/suites/rspec_2/functional/stub_bang_spec.rb +20 -0
  59. data/spec/suites/rspec_2/functional/stub_instance_of_spec.rb +15 -0
  60. data/spec/suites/rspec_2/functional/stub_instance_of_strong_spec.rb +15 -0
  61. data/spec/suites/rspec_2/functional/stub_proxy_instance_of_spec.rb +16 -0
  62. data/spec/suites/rspec_2/functional/stub_proxy_spec.rb +45 -0
  63. data/spec/suites/rspec_2/functional/stub_spec.rb +42 -161
  64. data/spec/suites/rspec_2/functional/stub_strong_spec.rb +15 -0
  65. data/spec/suites/rspec_2/helper.rb +2 -2
  66. data/spec/suites/rspec_2/support/mixins/double_definition_creator_helpers.rb +173 -0
  67. data/spec/suites/rspec_2/support/mixins/mock_definition_creator_helpers.rb +45 -0
  68. data/spec/suites/rspec_2/support/mixins/proxy_definition_creator_helpers.rb +33 -0
  69. data/spec/suites/rspec_2/support/mixins/stub_creator_helpers.rb +43 -0
  70. data/spec/suites/rspec_2/support/mixins/stub_definition_creator_helpers.rb +45 -0
  71. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_with_never_called_qualifier.rb +39 -0
  72. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_with_times_called_qualifier.rb +50 -0
  73. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_without_qualifiers.rb +131 -0
  74. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/dont_allow.rb +148 -0
  75. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_instance_of.rb +26 -0
  76. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_instance_of_strong.rb +28 -0
  77. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_proxy.rb +11 -0
  78. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_strong.rb +37 -0
  79. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mocking.rb +107 -0
  80. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of.rb +32 -0
  81. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb +39 -0
  82. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_proxy.rb +11 -0
  83. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_strong.rb +37 -0
  84. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stubbing.rb +57 -0
  85. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/array_flatten_bug.rb +35 -0
  86. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/block_form.rb +31 -0
  87. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/comparing_arity.rb +63 -0
  88. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/object_is_proxy.rb +43 -0
  89. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/sequential_invocations.rb +26 -0
  90. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/setting_implementation.rb +51 -0
  91. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/yields.rb +81 -0
  92. data/spec/suites/rspec_2/unit/core_ext/enumerable_spec.rb +0 -28
  93. data/spec/suites/rspec_2/unit/deprecations_spec.rb +27 -0
  94. data/spec/suites/rspec_2/unit/double_definitions/double_definition_create_spec.rb +18 -18
  95. data/spec/suites/rspec_2/unit/dsl/double_creators_spec.rb +133 -0
  96. data/spec/suites/rspec_2/unit/dsl/space_spec.rb +99 -0
  97. data/spec/suites/rspec_2/unit/dsl/wildcard_matchers_spec.rb +67 -0
  98. data/spec/suites/rspec_2/unit/expectations/any_argument_expectation_spec.rb +9 -9
  99. data/spec/suites/rspec_2/unit/expectations/argument_equality_expectation_spec.rb +21 -21
  100. data/spec/suites/rspec_2/unit/expectations/boolean_argument_equality_expectation_spec.rb +4 -4
  101. data/spec/suites/rspec_2/unit/expectations/hash_including_argument_equality_expectation_spec.rb +31 -21
  102. data/spec/suites/rspec_2/unit/injections/double_injection/double_injection_spec.rb +0 -12
  103. data/spec/suites/rspec_2/unit/integrations/rspec_spec.rb +4 -19
  104. data/spec/suites/rspec_2/unit/space_spec.rb +7 -4
  105. data/spec/suites/rspec_2/unit/spy_verification_spec.rb +1 -1
  106. data/spec/support/adapter.rb +1 -1
  107. data/spec/support/adapter_tests/rspec.rb +19 -15
  108. data/spec/support/project/generator.rb +0 -4
  109. metadata +112 -57
  110. data/gemfiles/ruby_18_rspec_1.gemfile +0 -14
  111. data/gemfiles/ruby_18_rspec_1.gemfile.lock +0 -38
  112. data/gemfiles/ruby_18_rspec_1_rails_2.gemfile +0 -18
  113. data/gemfiles/ruby_18_rspec_1_rails_2.gemfile.lock +0 -64
  114. data/gemfiles/ruby_19_rspec_2_rails_3.gemfile +0 -15
  115. data/gemfiles/ruby_19_rspec_2_rails_3.gemfile.lock +0 -123
  116. data/lib/rr/adapters.rb +0 -34
  117. data/lib/rr/adapters/rr_methods.rb +0 -142
  118. data/lib/rr/integrations/rspec_1.rb +0 -46
  119. data/lib/rr/integrations/test_unit_1.rb +0 -63
  120. data/lib/rr/integrations/test_unit_2.rb +0 -17
  121. data/lib/rr/integrations/test_unit_200.rb +0 -27
  122. data/lib/rr/integrations/test_unit_200_active_support.rb +0 -25
  123. data/lib/rr/integrations/test_unit_2_active_support.rb +0 -38
  124. data/lib/rr/proc_from_block.rb +0 -11
  125. data/spec/suites/rspec_1/helper.rb +0 -24
  126. data/spec/suites/rspec_1/integration/rspec_1_spec.rb +0 -93
  127. data/spec/suites/rspec_1/integration/test_unit_1_spec.rb +0 -102
  128. data/spec/suites/rspec_1/integration/test_unit_2_spec.rb +0 -109
  129. data/spec/suites/rspec_1/spec_helper.rb +0 -3
  130. data/spec/suites/rspec_1_rails_2/integration/astc_rails_2_spec.rb +0 -141
  131. data/spec/suites/rspec_1_rails_2/integration/rspec_1_rails_2_spec.rb +0 -132
  132. data/spec/suites/rspec_1_rails_2/integration/test_unit_1_rails_2_spec.rb +0 -141
  133. data/spec/suites/rspec_1_rails_2/integration/test_unit_2_rails_2_spec.rb +0 -148
  134. data/spec/suites/rspec_1_rails_2/spec_helper.rb +0 -3
  135. data/spec/suites/rspec_2/functional/dsl_spec.rb +0 -13
  136. data/spec/suites/rspec_2/functional/instance_of_spec.rb +0 -14
  137. data/spec/suites/rspec_2/functional/proxy_spec.rb +0 -136
  138. data/spec/suites/rspec_2/functional/strong_spec.rb +0 -79
  139. data/spec/suites/rspec_2/integration/rspec_2_spec.rb +0 -133
  140. data/spec/suites/rspec_2/integration/test_unit_200_spec.rb +0 -102
  141. data/spec/suites/rspec_2/integration/test_unit_2_spec.rb +0 -109
  142. data/spec/suites/rspec_2/unit/adapters/rr_methods/double_creators_spec.rb +0 -135
  143. data/spec/suites/rspec_2/unit/adapters/rr_methods/space_spec.rb +0 -101
  144. data/spec/suites/rspec_2/unit/adapters/rr_methods/wildcard_matchers_spec.rb +0 -69
  145. data/spec/suites/rspec_2/unit/proc_from_block_spec.rb +0 -14
  146. data/spec/suites/rspec_2_rails_3/integration/astc_rails_3_spec.rb +0 -141
  147. data/spec/suites/rspec_2_rails_3/integration/minitest_4_rails_3_spec.rb +0 -148
  148. data/spec/suites/rspec_2_rails_3/integration/rspec_2_rails_3_spec.rb +0 -172
  149. data/spec/suites/rspec_2_rails_3/integration/test_unit_200_rails_3_spec.rb +0 -141
  150. data/spec/suites/rspec_2_rails_3/integration/test_unit_2_rails_3_spec.rb +0 -148
  151. data/spec/suites/rspec_2_rails_3/spec_helper.rb +0 -3
  152. data/spec/suites/rspec_2_rails_4/integration/astc_rails_4_spec.rb +0 -142
  153. data/spec/suites/rspec_2_rails_4/integration/minitest_4_rails_4_spec.rb +0 -149
  154. data/spec/suites/rspec_2_rails_4/integration/rspec_2_rails_4_spec.rb +0 -173
  155. data/spec/suites/rspec_2_rails_4/integration/test_unit_200_rails_4_spec.rb +0 -142
  156. data/spec/suites/rspec_2_rails_4/integration/test_unit_2_rails_4_spec.rb +0 -149
  157. data/spec/suites/rspec_2_rails_4/spec_helper.rb +0 -3
@@ -42,34 +42,6 @@ describe Enumerable do
42
42
  end
43
43
  end
44
44
 
45
- if RUBY_VERSION =~ /^1.8/
46
- context 'when the Enumerable is a String' do
47
- subject { 'foo' }
48
-
49
- it "returns true if the String is exactly equal to the given String" do
50
- should wildcard_match('foo')
51
- end
52
-
53
- it "returns false if the string is not exactly equal to the given String" do
54
- should_not wildcard_match('bar')
55
- end
56
-
57
- context 'whose #== method has been proxied' do
58
- before do
59
- @r1 = 'x'
60
- @r2 = 'y'
61
- mock.proxy(@r1) == @r1
62
- mock.proxy(@r1) == @r2
63
- end
64
-
65
- it "doesn't blow up with a recursive loop error" do
66
- @r1 == @r1
67
- @r1 == @r2
68
- end
69
- end
70
- end
71
- end
72
-
73
45
  context 'when not given an Enumerable' do
74
46
  subject { klass.new({:foo => 'bar'}) }
75
47
 
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe 'Deprecations' do
4
+ before do
5
+ stub(RR::Deprecations).show_warning
6
+ end
7
+
8
+ specify 'RR::Adapters::MiniTest still works' do
9
+ expect { RR::Adapters::MiniTest }.not_to raise_error
10
+ end
11
+
12
+ specify 'RR::Adapters::TestUnit still works' do
13
+ expect { RR::Adapters::TestUnit }.not_to raise_error
14
+ end
15
+
16
+ specify 'RR::Adapters::Rspec::InvocationMatcher still works' do
17
+ expect { RR::Adapters::Rspec::InvocationMatcher }.not_to raise_error
18
+ end
19
+
20
+ specify 'RR::Adapters::RRMethods should still work' do
21
+ expect { RR::Adapters::RRMethods }.not_to raise_error
22
+ end
23
+
24
+ specify 'RR::Extensions::InstanceMethods should still work' do
25
+ expect { RR::Extensions::InstanceMethods }.not_to raise_error
26
+ end
27
+ end
@@ -223,7 +223,7 @@ module RR
223
223
 
224
224
  describe "#subject.method_name being called" do
225
225
  it "returns the return value of the Double#returns block" do
226
- double_definition_create.call(:foobar, 1, 2) {:baz}
226
+ double_definition_create.call(:foobar, [1, 2], {}) {:baz}
227
227
  expect(subject.foobar(1, 2)).to eq :baz
228
228
  end
229
229
  end
@@ -254,7 +254,7 @@ module RR
254
254
  original_method_called = true
255
255
  end
256
256
  end
257
- double_definition_create.call(:foobar, 1, 2)
257
+ double_definition_create.call(:foobar, [1, 2], {})
258
258
  subject.foobar(1, 2)
259
259
  expect(original_method_called).to be_true
260
260
  end
@@ -264,7 +264,7 @@ module RR
264
264
  def subject.foobar(*args)
265
265
  :baz;
266
266
  end
267
- double_definition_create.call(:foobar, 1, 2)
267
+ double_definition_create.call(:foobar, [1, 2], {})
268
268
  expect(subject.foobar(1, 2)).to eq :baz
269
269
  end
270
270
  end
@@ -279,7 +279,7 @@ module RR
279
279
  end
280
280
 
281
281
  it "calls the block with the return value of the original method" do
282
- double_definition_create.call(:foobar, 1, 2) do |value|
282
+ double_definition_create.call(:foobar, [1, 2], {}) do |value|
283
283
  mock(value).a_method {99}
284
284
  value
285
285
  end
@@ -288,7 +288,7 @@ module RR
288
288
  end
289
289
 
290
290
  it "returns the return value of the block" do
291
- double_definition_create.call(:foobar, 1, 2) do |value|
291
+ double_definition_create.call(:foobar, [1, 2], {}) do |value|
292
292
  :something_else
293
293
  end
294
294
  expect(subject.foobar(1, 2)).to eq :something_else
@@ -306,7 +306,7 @@ module RR
306
306
 
307
307
  context "when not passed a block" do
308
308
  it "returns nil" do
309
- double_definition_create.call(:foobar)
309
+ double_definition_create.call(:foobar, [], {})
310
310
  expect(subject.foobar).to be_nil
311
311
  end
312
312
  end
@@ -314,7 +314,7 @@ module RR
314
314
  context "when passed a block" do
315
315
  describe "#subject.method_name being called" do
316
316
  it "returns the return value of the block" do
317
- double_definition_create.call(:foobar) {:baz}
317
+ double_definition_create.call(:foobar, [], {}) {:baz}
318
318
  expect(subject.foobar).to eq :baz
319
319
  end
320
320
  end
@@ -323,7 +323,7 @@ module RR
323
323
  context "when not passed args" do
324
324
  describe "#subject.method_name being called with any arguments" do
325
325
  it "invokes the implementation of the Stub" do
326
- double_definition_create.call(:foobar) {:baz}
326
+ double_definition_create.call(:foobar, [], {}) {:baz}
327
327
  expect(subject.foobar(1, 2)).to eq :baz
328
328
  expect(subject.foobar()).to eq :baz
329
329
  expect(subject.foobar([])).to eq :baz
@@ -334,14 +334,14 @@ module RR
334
334
  context "when passed args" do
335
335
  describe "#subject.method_name being called with the passed-in arguments" do
336
336
  it "invokes the implementation of the Stub" do
337
- double_definition_create.call(:foobar, 1, 2) {:baz}
337
+ double_definition_create.call(:foobar, [1, 2], {}) {:baz}
338
338
  expect(subject.foobar(1, 2)).to eq :baz
339
339
  end
340
340
  end
341
341
 
342
342
  describe "#subject.method_name being called with different arguments" do
343
343
  it "raises a DoubleNotFoundError" do
344
- double_definition_create.call(:foobar, 1, 2) {:baz}
344
+ double_definition_create.call(:foobar, [1, 2], {}) {:baz}
345
345
  expect {
346
346
  subject.foobar
347
347
  }.to raise_error(RR::Errors::DoubleNotFoundError)
@@ -362,7 +362,7 @@ module RR
362
362
  context "when not passed a block" do
363
363
  describe "#subject.method_name being called" do
364
364
  it "invokes the original implementanion" do
365
- double_definition_create.call(:foobar)
365
+ double_definition_create.call(:foobar, [], {})
366
366
  expect(subject.foobar).to eq :original_return_value
367
367
  end
368
368
  end
@@ -372,7 +372,7 @@ module RR
372
372
  describe "#subject.method_name being called" do
373
373
  it "invokes the original implementanion and invokes the block with the return value of the original implementanion" do
374
374
  passed_in_value = nil
375
- double_definition_create.call(:foobar) do |original_return_value|
375
+ double_definition_create.call(:foobar, [], {}) do |original_return_value|
376
376
  passed_in_value = original_return_value
377
377
  end
378
378
  subject.foobar
@@ -380,7 +380,7 @@ module RR
380
380
  end
381
381
 
382
382
  it "returns the return value of the block" do
383
- double_definition_create.call(:foobar) do |original_return_value|
383
+ double_definition_create.call(:foobar, [], {}) do |original_return_value|
384
384
  :new_return_value
385
385
  end
386
386
  expect(subject.foobar).to eq :new_return_value
@@ -391,14 +391,14 @@ module RR
391
391
  context "when passed args" do
392
392
  describe "#subject.method_name being called with the passed-in arguments" do
393
393
  it "invokes the implementation of the Stub" do
394
- double_definition_create.call(:foobar, 1, 2) {:baz}
394
+ double_definition_create.call(:foobar, [1, 2], {}) {:baz}
395
395
  expect(subject.foobar(1, 2)).to eq :baz
396
396
  end
397
397
  end
398
398
 
399
399
  describe "#subject.method_name being called with different arguments" do
400
400
  it "raises a DoubleNotFoundError" do
401
- double_definition_create.call(:foobar, 1, 2) {:baz}
401
+ double_definition_create.call(:foobar, [1, 2], {}) {:baz}
402
402
  expect {
403
403
  subject.foobar
404
404
  }.to raise_error(RR::Errors::DoubleNotFoundError)
@@ -416,7 +416,7 @@ module RR
416
416
  context "when not passed args" do
417
417
  describe "#subject.method_name being called with any arguments" do
418
418
  it "raises a TimesCalledError" do
419
- double_definition_create.call(:foobar)
419
+ double_definition_create.call(:foobar, [], {})
420
420
  expect { subject.foobar }.to raise_error(RR::Errors::TimesCalledError)
421
421
  expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
422
422
  end
@@ -426,14 +426,14 @@ module RR
426
426
  context "when passed args" do
427
427
  describe "#subject.method_name being called with the passed-in arguments" do
428
428
  it "raises a TimesCalledError" do
429
- double_definition_create.call(:foobar, 1, 2)
429
+ double_definition_create.call(:foobar, [1, 2], {})
430
430
  expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
431
431
  end
432
432
  end
433
433
 
434
434
  describe "#subject.method_name being called with different arguments" do
435
435
  it "raises a DoubleNotFoundError" do
436
- double_definition_create.call(:foobar, 1, 2)
436
+ double_definition_create.call(:foobar, [1, 2], {})
437
437
  expect { subject.foobar() }.to raise_error(RR::Errors::DoubleNotFoundError)
438
438
  end
439
439
  end
@@ -0,0 +1,133 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ describe DSL do
5
+ subject { Object.new }
6
+
7
+ after(:each) do
8
+ RR.reset
9
+ end
10
+
11
+ describe "normal strategy definitions" do
12
+ attr_reader :strategy_method_name
13
+
14
+ def call_strategy(*args, &block)
15
+ __send__(strategy_method_name, *args, &block)
16
+ end
17
+
18
+ describe "#mock" do
19
+ before do
20
+ @strategy_method_name = :mock
21
+ end
22
+
23
+ context "when passing no args" do
24
+ it "returns a DoubleDefinitionCreate" do
25
+ expect(call_strategy.class).to eq RR::DoubleDefinitions::DoubleDefinitionCreate
26
+ end
27
+ end
28
+
29
+ context "when passed a method_name argument" do
30
+ it "creates a mock Double for method" do
31
+ double_definition = mock(subject, :foobar).returns {:baz}
32
+ expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::IntegerMatcher.new(1)
33
+ expect(double_definition.argument_expectation.class).to eq RR::Expectations::ArgumentEqualityExpectation
34
+ expect(double_definition.argument_expectation.expected_arguments).to eq []
35
+ expect(subject.foobar).to eq :baz
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "#stub" do
41
+ before do
42
+ @strategy_method_name = :stub
43
+ end
44
+
45
+ context "when passing no args" do
46
+ it "returns a DoubleDefinitionCreate" do
47
+ expect(call_strategy.class).to eq RR::DoubleDefinitions::DoubleDefinitionCreate
48
+ end
49
+ end
50
+
51
+ context "when passed a method_name argument" do
52
+ it "creates a stub Double for method when passed a method_name argument" do
53
+ double_definition = stub(subject, :foobar).returns {:baz}
54
+ expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::AnyTimesMatcher.new
55
+ expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
56
+ expect(subject.foobar).to eq :baz
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "#dont_allow" do
62
+ before do
63
+ @strategy_method_name = :dont_allow
64
+ end
65
+
66
+ context "when passing no args" do
67
+ it "returns a DoubleDefinitionCreate" do
68
+ expect(call_strategy.class).to eq RR::DoubleDefinitions::DoubleDefinitionCreate
69
+ end
70
+ end
71
+
72
+ context "when passed a method_name argument_expectation" do
73
+ it "creates a mock Double for method" do
74
+ double_definition = dont_allow(subject, :foobar)
75
+ expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::NeverMatcher.new
76
+ expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
77
+
78
+ expect {
79
+ subject.foobar
80
+ }.to raise_error(RR::Errors::TimesCalledError)
81
+ RR.reset
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ describe "! strategy definitions" do
88
+ attr_reader :strategy_method_name
89
+ def call_strategy(*args, &definition_eval_block)
90
+ __send__(strategy_method_name, *args, &definition_eval_block)
91
+ end
92
+
93
+ describe "#mock!" do
94
+ before do
95
+ @strategy_method_name = :mock!
96
+ end
97
+
98
+ context "when passed a method_name argument" do
99
+ it "sets #verification_strategy to Mock" do
100
+ proxy = mock!(:foobar)
101
+ expect(proxy.double_definition_create.verification_strategy.class).to eq RR::DoubleDefinitions::Strategies::Verification::Mock
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "#stub!" do
107
+ before do
108
+ @strategy_method_name = :stub!
109
+ end
110
+
111
+ context "when passed a method_name argument" do
112
+ it "sets #verification_strategy to Stub" do
113
+ proxy = stub!(:foobar)
114
+ expect(proxy.double_definition_create.verification_strategy.class).to eq RR::DoubleDefinitions::Strategies::Verification::Stub
115
+ end
116
+ end
117
+ end
118
+
119
+ describe "#dont_allow!" do
120
+ before do
121
+ @strategy_method_name = :dont_allow!
122
+ end
123
+
124
+ context "when passed a method_name argument" do
125
+ it "sets #verification_strategy to DontAllow" do
126
+ proxy = dont_allow!(:foobar)
127
+ expect(proxy.double_definition_create.verification_strategy.class).to eq RR::DoubleDefinitions::Strategies::Verification::DontAllow
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,99 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ describe DSL do
5
+ attr_reader :space, :subject_1, :subject_2, :method_name
6
+
7
+ include_examples "Swapped Space"
8
+
9
+ include RR::DSL
10
+
11
+ before do
12
+ @subject_1 = Object.new
13
+ @subject_2 = Object.new
14
+ @method_name = :foobar
15
+ end
16
+
17
+ describe "#verify" do
18
+ it "aliases #rr_verify" do
19
+ expect(DSL.instance_method("verify")).to eq DSL.instance_method("rr_verify")
20
+ end
21
+ end
22
+
23
+ describe "#rr_verify" do
24
+ it "verifies and deletes the double_injections" do
25
+ double_1 = ::RR::Injections::DoubleInjection.find_or_create_by_subject(subject_1, method_name)
26
+ double_1_verify_calls = 0
27
+ double_1_reset_calls = 0
28
+ (
29
+ class << double_1;
30
+ self;
31
+ end).class_eval do
32
+ define_method(:verify) do ||
33
+ double_1_verify_calls += 1
34
+ end
35
+ define_method(:reset) do ||
36
+ double_1_reset_calls += 1
37
+ end
38
+ end
39
+ double_2 = ::RR::Injections::DoubleInjection.find_or_create_by_subject(subject_2, method_name)
40
+ double_2_verify_calls = 0
41
+ double_2_reset_calls = 0
42
+ ( class << double_2; self; end).class_eval do
43
+ define_method(:verify) do ||
44
+ double_2_verify_calls += 1
45
+ end
46
+ define_method(:reset) do ||
47
+ double_2_reset_calls += 1
48
+ end
49
+ end
50
+
51
+ rr_verify
52
+ expect(double_1_verify_calls).to eq 1
53
+ expect(double_2_verify_calls).to eq 1
54
+ expect(double_1_reset_calls).to eq 1
55
+ expect(double_1_reset_calls).to eq 1
56
+ end
57
+ end
58
+
59
+ describe "#reset" do
60
+ it "aliases #rr_reset" do
61
+ expect(DSL.instance_method("reset")).to eq DSL.instance_method("rr_reset")
62
+ end
63
+ end
64
+
65
+ describe "#rr_reset" do
66
+ it "removes the ordered doubles" do
67
+ mock(subject_1).foobar1.ordered
68
+ mock(subject_2).foobar2.ordered
69
+
70
+ ::RR::Injections::DoubleInjection.instances.should_not be_empty
71
+
72
+ rr_reset
73
+ ::RR::Injections::DoubleInjection.instances
74
+ expect(::RR::Injections::DoubleInjection.instances).to be_empty
75
+ end
76
+
77
+ it "resets all double_injections" do
78
+ double_1 = ::RR::Injections::DoubleInjection.find_or_create_by_subject(subject_1, method_name)
79
+ double_1_reset_calls = 0
80
+ ( class << double_1; self; end).class_eval do
81
+ define_method(:reset) do ||
82
+ double_1_reset_calls += 1
83
+ end
84
+ end
85
+ double_2 = ::RR::Injections::DoubleInjection.find_or_create_by_subject(subject_2, method_name)
86
+ double_2_reset_calls = 0
87
+ ( class << double_2; self; end).class_eval do
88
+ define_method(:reset) do ||
89
+ double_2_reset_calls += 1
90
+ end
91
+ end
92
+
93
+ rr_reset
94
+ expect(double_1_reset_calls).to eq 1
95
+ expect(double_2_reset_calls).to eq 1
96
+ end
97
+ end
98
+ end
99
+ end