rr 1.1.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) hide show
  1. checksums.yaml +5 -5
  2. data/Appraisals +6 -0
  3. data/CHANGES.md +102 -1
  4. data/CREDITS.md +5 -0
  5. data/Gemfile +3 -0
  6. data/README.md +91 -110
  7. data/Rakefile +43 -0
  8. data/doc/02_syntax_comparison.md +1 -0
  9. data/gemfiles/ruby_19_rspec_2.gemfile +14 -0
  10. data/gemfiles/ruby_19_rspec_2.gemfile.lock +49 -0
  11. data/gemfiles/ruby_19_rspec_2_rails_4.gemfile +15 -0
  12. data/gemfiles/ruby_19_rspec_2_rails_4.gemfile.lock +119 -0
  13. data/lib/rr/class_instance_method_defined.rb +1 -1
  14. data/lib/rr/core_ext/array.rb +2 -0
  15. data/lib/rr/core_ext/hash.rb +2 -0
  16. data/lib/rr/deprecations.rb +97 -0
  17. data/lib/rr/double.rb +28 -10
  18. data/lib/rr/double_definitions/double_definition.rb +39 -16
  19. data/lib/rr/double_definitions/double_definition_create.rb +5 -5
  20. data/lib/rr/double_definitions/double_definition_create_blank_slate.rb +10 -4
  21. data/lib/rr/double_definitions/double_injections/any_instance_of.rb +1 -1
  22. data/lib/rr/double_definitions/double_injections/instance.rb +2 -2
  23. data/lib/rr/double_definitions/strategies/strategy.rb +27 -8
  24. data/lib/rr/double_definitions/strategies/verification/mock.rb +8 -2
  25. data/lib/rr/double_matches.rb +4 -3
  26. data/lib/rr/dsl.rb +152 -0
  27. data/lib/rr/expectations/any_argument_expectation.rb +4 -4
  28. data/lib/rr/expectations/argument_equality_expectation.rb +43 -5
  29. data/lib/rr/injections/double_injection.rb +67 -19
  30. data/lib/rr/injections/method_missing_injection.rb +37 -6
  31. data/lib/rr/integrations.rb +13 -12
  32. data/lib/rr/integrations/decorator.rb +4 -1
  33. data/lib/rr/integrations/minitest_4.rb +1 -1
  34. data/lib/rr/integrations/minitest_4_active_support.rb +1 -1
  35. data/lib/rr/integrations/rspec/invocation_matcher.rb +0 -8
  36. data/lib/rr/integrations/rspec_2.rb +28 -3
  37. data/lib/rr/keyword_arguments.rb +15 -0
  38. data/lib/rr/method_dispatches/base_method_dispatch.rb +22 -5
  39. data/lib/rr/method_dispatches/method_dispatch.rb +21 -10
  40. data/lib/rr/method_dispatches/method_missing_dispatch.rb +14 -5
  41. data/lib/rr/recorded_call.rb +35 -0
  42. data/lib/rr/recorded_calls.rb +23 -9
  43. data/lib/rr/space.rb +15 -5
  44. data/lib/rr/spy_verification.rb +13 -5
  45. data/lib/rr/version.rb +1 -2
  46. data/lib/rr/wildcard_matchers.rb +10 -10
  47. data/lib/rr/without_autohook.rb +7 -14
  48. data/rr.gemspec +14 -5
  49. data/spec/custom_formatter_for_rspec.rb +18 -0
  50. data/spec/custom_formatter_for_rspec_2.rb +40 -0
  51. data/spec/defines_spec_suite_tasks.rb +57 -0
  52. data/spec/fixtures/rubygems_patch_for_187.rb +598 -0
  53. data/spec/global_helper.rb +38 -0
  54. data/spec/spec.opts +3 -0
  55. data/spec/spec_suite_configuration.rb +126 -0
  56. data/spec/spec_suite_runner.rb +47 -0
  57. data/spec/suites.yml +10 -0
  58. data/spec/suites/rspec_2/functional/any_instance_of_spec.rb +147 -0
  59. data/spec/suites/rspec_2/functional/dont_allow_spec.rb +17 -0
  60. data/spec/suites/rspec_2/functional/mock_bang_spec.rb +20 -0
  61. data/spec/suites/rspec_2/functional/mock_instance_of_spec.rb +14 -0
  62. data/spec/suites/rspec_2/functional/mock_instance_of_strong_spec.rb +15 -0
  63. data/spec/suites/rspec_2/functional/mock_proxy_instance_of_spec.rb +15 -0
  64. data/spec/suites/rspec_2/functional/mock_proxy_spec.rb +14 -0
  65. data/spec/suites/rspec_2/functional/mock_spec.rb +17 -0
  66. data/spec/suites/rspec_2/functional/mock_strong_spec.rb +14 -0
  67. data/spec/suites/rspec_2/functional/received_spec.rb +16 -0
  68. data/spec/suites/rspec_2/functional/spy_spec.rb +102 -0
  69. data/spec/suites/rspec_2/functional/stub_bang_spec.rb +20 -0
  70. data/spec/suites/rspec_2/functional/stub_instance_of_spec.rb +15 -0
  71. data/spec/suites/rspec_2/functional/stub_instance_of_strong_spec.rb +15 -0
  72. data/spec/suites/rspec_2/functional/stub_proxy_instance_of_spec.rb +16 -0
  73. data/spec/suites/rspec_2/functional/stub_proxy_spec.rb +45 -0
  74. data/spec/suites/rspec_2/functional/stub_spec.rb +71 -0
  75. data/spec/suites/rspec_2/functional/stub_strong_spec.rb +15 -0
  76. data/spec/suites/rspec_2/functional/wildcard_matchers_spec.rb +128 -0
  77. data/spec/suites/rspec_2/helper.rb +28 -0
  78. data/spec/suites/rspec_2/integration/minitest_4_spec.rb +109 -0
  79. data/spec/suites/rspec_2/integration/minitest_spec.rb +109 -0
  80. data/spec/suites/rspec_2/spec_helper.rb +3 -0
  81. data/spec/suites/rspec_2/support/matchers/wildcard_matcher_matchers.rb +32 -0
  82. data/spec/suites/rspec_2/support/mixins/double_definition_creator_helpers.rb +173 -0
  83. data/spec/suites/rspec_2/support/mixins/mock_definition_creator_helpers.rb +45 -0
  84. data/spec/suites/rspec_2/support/mixins/proxy_definition_creator_helpers.rb +33 -0
  85. data/spec/suites/rspec_2/support/mixins/stub_creator_helpers.rb +43 -0
  86. data/spec/suites/rspec_2/support/mixins/stub_definition_creator_helpers.rb +45 -0
  87. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_with_never_called_qualifier.rb +39 -0
  88. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_with_times_called_qualifier.rb +50 -0
  89. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_without_qualifiers.rb +131 -0
  90. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/dont_allow.rb +148 -0
  91. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_instance_of.rb +26 -0
  92. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_instance_of_strong.rb +28 -0
  93. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_proxy.rb +11 -0
  94. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_strong.rb +37 -0
  95. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mocking.rb +107 -0
  96. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of.rb +32 -0
  97. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb +39 -0
  98. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_proxy.rb +11 -0
  99. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_strong.rb +37 -0
  100. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stubbing.rb +57 -0
  101. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/array_flatten_bug.rb +35 -0
  102. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/block_form.rb +31 -0
  103. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/comparing_arity.rb +63 -0
  104. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/object_is_proxy.rb +43 -0
  105. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/sequential_invocations.rb +26 -0
  106. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/setting_implementation.rb +51 -0
  107. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/yields.rb +81 -0
  108. data/spec/suites/rspec_2/support/shared_examples/space.rb +13 -0
  109. data/spec/suites/rspec_2/support/shared_examples/times_called_expectation.rb +9 -0
  110. data/spec/suites/rspec_2/unit/core_ext/array_spec.rb +39 -0
  111. data/spec/suites/rspec_2/unit/core_ext/enumerable_spec.rb +53 -0
  112. data/spec/suites/rspec_2/unit/core_ext/hash_spec.rb +55 -0
  113. data/spec/suites/rspec_2/unit/core_ext/range_spec.rb +41 -0
  114. data/spec/suites/rspec_2/unit/core_ext/regexp_spec.rb +41 -0
  115. data/spec/suites/rspec_2/unit/deprecations_spec.rb +27 -0
  116. data/spec/suites/rspec_2/unit/double_definitions/child_double_definition_create_spec.rb +114 -0
  117. data/spec/suites/rspec_2/unit/double_definitions/double_definition_create_blank_slate_spec.rb +93 -0
  118. data/spec/suites/rspec_2/unit/double_definitions/double_definition_create_spec.rb +446 -0
  119. data/spec/suites/rspec_2/unit/dsl/double_creators_spec.rb +133 -0
  120. data/spec/suites/rspec_2/unit/dsl/space_spec.rb +99 -0
  121. data/spec/suites/rspec_2/unit/dsl/wildcard_matchers_spec.rb +67 -0
  122. data/spec/suites/rspec_2/unit/errors/rr_error_spec.rb +67 -0
  123. data/spec/suites/rspec_2/unit/expectations/any_argument_expectation_spec.rb +48 -0
  124. data/spec/suites/rspec_2/unit/expectations/anything_argument_equality_expectation_spec.rb +14 -0
  125. data/spec/suites/rspec_2/unit/expectations/argument_equality_expectation_spec.rb +135 -0
  126. data/spec/suites/rspec_2/unit/expectations/boolean_argument_equality_expectation_spec.rb +30 -0
  127. data/spec/suites/rspec_2/unit/expectations/hash_including_argument_equality_expectation_spec.rb +92 -0
  128. data/spec/suites/rspec_2/unit/expectations/satisfy_argument_equality_expectation_spec.rb +61 -0
  129. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/any_times_matcher_spec.rb +22 -0
  130. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/at_least_matcher_spec.rb +37 -0
  131. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/at_most_matcher_spec.rb +43 -0
  132. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb +58 -0
  133. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/proc_matcher_spec.rb +35 -0
  134. data/spec/suites/rspec_2/unit/expectations/times_called_expectation/range_matcher_spec.rb +39 -0
  135. data/spec/suites/rspec_2/unit/hash_with_object_id_key_spec.rb +88 -0
  136. data/spec/suites/rspec_2/unit/injections/double_injection/double_injection_spec.rb +533 -0
  137. data/spec/suites/rspec_2/unit/injections/double_injection/double_injection_verify_spec.rb +32 -0
  138. data/spec/suites/rspec_2/unit/integrations/rspec/invocation_matcher_spec.rb +297 -0
  139. data/spec/suites/rspec_2/unit/integrations/rspec_spec.rb +70 -0
  140. data/spec/suites/rspec_2/unit/rr_spec.rb +28 -0
  141. data/spec/suites/rspec_2/unit/space_spec.rb +598 -0
  142. data/spec/suites/rspec_2/unit/spy_verification_spec.rb +133 -0
  143. data/spec/suites/rspec_2/unit/times_called_matchers/any_times_matcher_spec.rb +46 -0
  144. data/spec/suites/rspec_2/unit/times_called_matchers/at_least_matcher_spec.rb +54 -0
  145. data/spec/suites/rspec_2/unit/times_called_matchers/at_most_matcher_spec.rb +69 -0
  146. data/spec/suites/rspec_2/unit/times_called_matchers/integer_matcher_spec.rb +69 -0
  147. data/spec/suites/rspec_2/unit/times_called_matchers/proc_matcher_spec.rb +54 -0
  148. data/spec/suites/rspec_2/unit/times_called_matchers/range_matcher_spec.rb +75 -0
  149. data/spec/suites/rspec_2/unit/times_called_matchers/times_called_matcher_spec.rb +117 -0
  150. data/spec/suites/rspec_2/unit/wildcard_matchers/anything_spec.rb +33 -0
  151. data/spec/suites/rspec_2/unit/wildcard_matchers/boolean_spec.rb +45 -0
  152. data/spec/suites/rspec_2/unit/wildcard_matchers/duck_type_spec.rb +64 -0
  153. data/spec/suites/rspec_2/unit/wildcard_matchers/hash_including_spec.rb +64 -0
  154. data/spec/suites/rspec_2/unit/wildcard_matchers/is_a_spec.rb +55 -0
  155. data/spec/suites/rspec_2/unit/wildcard_matchers/numeric_spec.rb +46 -0
  156. data/spec/suites/rspec_2/unit/wildcard_matchers/satisfy_spec.rb +57 -0
  157. data/spec/support/adapter.rb +22 -0
  158. data/spec/support/adapter_tests/base.rb +45 -0
  159. data/spec/support/adapter_tests/minitest.rb +7 -0
  160. data/spec/support/adapter_tests/rspec.rb +70 -0
  161. data/spec/support/adapter_tests/test_unit.rb +47 -0
  162. data/spec/support/command_runner.rb +105 -0
  163. data/spec/support/generator.rb +56 -0
  164. data/spec/support/integration_tests/base.rb +64 -0
  165. data/spec/support/integration_tests/rails.rb +60 -0
  166. data/spec/support/integration_tests/rails_minitest.rb +13 -0
  167. data/spec/support/integration_tests/rails_rspec.rb +13 -0
  168. data/spec/support/integration_tests/rails_test_unit.rb +13 -0
  169. data/spec/support/integration_tests/rails_test_unit_like.rb +13 -0
  170. data/spec/support/integration_tests/ruby.rb +7 -0
  171. data/spec/support/integration_tests/ruby_minitest.rb +13 -0
  172. data/spec/support/integration_tests/ruby_rspec.rb +13 -0
  173. data/spec/support/integration_tests/ruby_test_unit.rb +13 -0
  174. data/spec/support/matchers/be_a_subset_of_matcher.rb +24 -0
  175. data/spec/support/project/cucumber.rb +50 -0
  176. data/spec/support/project/generator.rb +348 -0
  177. data/spec/support/project/minitest.rb +39 -0
  178. data/spec/support/project/rails.rb +199 -0
  179. data/spec/support/project/rails_minitest.rb +17 -0
  180. data/spec/support/project/rails_rspec.rb +50 -0
  181. data/spec/support/project/rails_test_unit.rb +17 -0
  182. data/spec/support/project/rails_test_unit_like.rb +17 -0
  183. data/spec/support/project/rspec.rb +69 -0
  184. data/spec/support/project/ruby.rb +34 -0
  185. data/spec/support/project/ruby_minitest.rb +11 -0
  186. data/spec/support/project/ruby_rspec.rb +29 -0
  187. data/spec/support/project/ruby_test_unit.rb +11 -0
  188. data/spec/support/project/ruby_test_unit_like.rb +21 -0
  189. data/spec/support/project/test_unit.rb +29 -0
  190. data/spec/support/project/test_unit_like.rb +7 -0
  191. data/spec/support/project/tests_runner.rb +22 -0
  192. data/spec/support/test.sqlite3 +0 -0
  193. data/spec/support/test_case/generator.rb +53 -0
  194. data/spec/support/test_case/minitest.rb +13 -0
  195. data/spec/support/test_case/rspec.rb +19 -0
  196. data/spec/support/test_case/test_unit.rb +21 -0
  197. data/spec/support/test_file/generator.rb +120 -0
  198. data/spec/support/test_file/minitest.rb +19 -0
  199. data/spec/support/test_file/rails_minitest.rb +7 -0
  200. data/spec/support/test_file/rails_rspec.rb +12 -0
  201. data/spec/support/test_file/rails_test_unit.rb +25 -0
  202. data/spec/support/test_file/rspec.rb +33 -0
  203. data/spec/support/test_file/test_unit.rb +36 -0
  204. data/spec/support/test_helper/generator.rb +27 -0
  205. data/spec/support/test_helper/minitest.rb +7 -0
  206. data/spec/support/test_helper/rails.rb +31 -0
  207. data/spec/support/test_helper/rails_minitest.rb +7 -0
  208. data/spec/support/test_helper/rails_rspec.rb +25 -0
  209. data/spec/support/test_helper/rails_test_unit.rb +23 -0
  210. data/spec/support/test_helper/rspec.rb +7 -0
  211. data/spec/support/test_helper/ruby.rb +31 -0
  212. data/spec/support/test_helper/test_unit.rb +7 -0
  213. metadata +240 -19
  214. data/VERSION +0 -1
  215. data/lib/rr/adapters.rb +0 -44
  216. data/lib/rr/adapters/rr_methods.rb +0 -142
  217. data/lib/rr/integrations/rspec_1.rb +0 -46
  218. data/lib/rr/integrations/test_unit_1.rb +0 -63
  219. data/lib/rr/integrations/test_unit_2.rb +0 -15
  220. data/lib/rr/integrations/test_unit_200.rb +0 -27
  221. data/lib/rr/integrations/test_unit_200_active_support.rb +0 -25
  222. data/lib/rr/integrations/test_unit_2_active_support.rb +0 -38
  223. data/lib/rr/proc_from_block.rb +0 -11
@@ -0,0 +1,41 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ describe Range do
4
+ include WildcardMatcherMatchers
5
+
6
+ describe '#wildcard_match?' do
7
+ subject { 1..5 }
8
+
9
+ it "returns true when given Range is exactly equal to this Range" do
10
+ should wildcard_match(1..5)
11
+ end
12
+
13
+ it "returns true when given number falls within the range" do
14
+ should wildcard_match(3)
15
+ end
16
+
17
+ it "returns false when given number falls outside the range" do
18
+ should_not wildcard_match(8)
19
+ end
20
+ end
21
+
22
+ describe '#==' do
23
+ subject { 1..5 }
24
+
25
+ it "returns true when given Range is exactly equal to this Range" do
26
+ should equal_match(1..5)
27
+ end
28
+
29
+ it "returns false when given Range is not exactly equal to this Range" do
30
+ should_not equal_match(3..5)
31
+ end
32
+
33
+ it "returns false even when given an object that wildcard matches this Range" do
34
+ should_not equal_match(3)
35
+ end
36
+
37
+ it "returns false when given object isn't even a Range" do
38
+ should_not equal_match(:something_else)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe Regexp do
4
+ include WildcardMatcherMatchers
5
+
6
+ describe '#wildcard_match?' do
7
+ subject { /foo/ }
8
+
9
+ it "returns true when given Regexp is exactly equal to this Regexp" do
10
+ should wildcard_match(/foo/)
11
+ end
12
+
13
+ it "returns true if given string matches the regexp" do
14
+ should wildcard_match('foobarbaz')
15
+ end
16
+
17
+ it "returns false if given string does not match the regexp" do
18
+ should_not wildcard_match('aslkj')
19
+ end
20
+ end
21
+
22
+ describe '#==' do
23
+ subject { /foo/ }
24
+
25
+ it "returns true when given Regexp is exactly equal to this Regexp" do
26
+ should equal_match(/foo/)
27
+ end
28
+
29
+ it "returns false when given Regexp is not exactly equal to this Regexp" do
30
+ should_not equal_match(/alkj/)
31
+ end
32
+
33
+ it "returns false even when given an object that wildcard matches this Regexp" do
34
+ should_not equal_match('foobarbaz')
35
+ end
36
+
37
+ it "returns false when not even given a Regexp" do
38
+ should_not equal_match(:something_else)
39
+ end
40
+ end
41
+ end
@@ -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
@@ -0,0 +1,114 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module DoubleDefinitions
5
+ describe ChildDoubleDefinitionCreate do
6
+ attr_reader :parent_subject, :parent_double_definition_create, :parent_double_definition, :child_double_definition_create
7
+
8
+ include_examples "Swapped Space"
9
+
10
+ before(:each) do
11
+ @parent_subject = Object.new
12
+ @parent_double_definition_create = DoubleDefinitionCreate.new
13
+ @parent_double_definition = DoubleDefinition.new(parent_double_definition_create)
14
+ @child_double_definition_create = ChildDoubleDefinitionCreate.new(parent_double_definition)
15
+ end
16
+
17
+ describe "#root_subject" do
18
+ it "returns the #parent_double_definition.root_subject" do
19
+ child_subject = Object.new
20
+ parent_double_definition_create.stub(parent_subject)
21
+ child_double_definition_create.stub(child_subject)
22
+ expect(child_double_definition_create.root_subject).to eq parent_subject
23
+ end
24
+ end
25
+
26
+ describe "Strategies::Verification definitions" do
27
+ describe "methods without !" do
28
+ attr_reader :child_subject
29
+ before do
30
+ @child_subject = Object.new
31
+ end
32
+
33
+ describe "#mock" do
34
+ context "when passed a subject" do
35
+ it "sets #parent_double_definition.implementation to a Proc returning the passed-in subject" do
36
+ expect(parent_double_definition.implementation).to be_nil
37
+ child_double_definition_create.mock(child_subject)
38
+ expect(parent_double_definition.implementation.call).to eq child_subject
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "#stub" do
44
+ context "when passed a subject" do
45
+ it "sets #parent_double_definition.implementation to a Proc returning the passed-in subject" do
46
+ expect(parent_double_definition.implementation).to be_nil
47
+ child_double_definition_create.stub(child_subject)
48
+ expect(parent_double_definition.implementation.call).to eq child_subject
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "#dont_allow" do
54
+ context "when passed a subject" do
55
+ it "sets #parent_double_definition.implementation to a Proc returning the passed-in subject" do
56
+ expect(parent_double_definition.implementation).to be_nil
57
+ child_double_definition_create.dont_allow(child_subject)
58
+ expect(parent_double_definition.implementation.call).to eq child_subject
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "methods with !" do
65
+ describe "#mock!" do
66
+ it "sets #parent_double_definition.implementation to a Proc returning the #subject" do
67
+ expect(parent_double_definition.implementation).to be_nil
68
+ child_subject = child_double_definition_create.mock!.__double_definition_create__.subject
69
+ expect(parent_double_definition.implementation.call).to eq child_subject
70
+ end
71
+ end
72
+
73
+ describe "#stub!" do
74
+ it "sets #parent_double_definition.implementation to a Proc returning the #subject" do
75
+ expect(parent_double_definition.implementation).to be_nil
76
+ child_subject = child_double_definition_create.stub!.__double_definition_create__.subject
77
+ expect(parent_double_definition.implementation.call).to eq child_subject
78
+ end
79
+ end
80
+
81
+ describe "#dont_allow!" do
82
+ it "sets #parent_double_definition.implementation to a Proc returning the #subject" do
83
+ expect(parent_double_definition.implementation).to be_nil
84
+ child_subject = child_double_definition_create.dont_allow!.__double_definition_create__.subject
85
+ expect(parent_double_definition.implementation.call).to eq child_subject
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ describe "Strategies::DoubleInjection definitions" do
92
+ describe "methods without !" do
93
+ describe "#instance_of" do
94
+ it "raises a NoMethodError" do
95
+ expect {
96
+ child_double_definition_create.instance_of
97
+ }.to raise_error(NoMethodError)
98
+ end
99
+ end
100
+ end
101
+
102
+ describe "methods with !" do
103
+ describe "#instance_of!" do
104
+ it "raises a NoMethodError" do
105
+ expect {
106
+ child_double_definition_create.instance_of!
107
+ }.to raise_error(NoMethodError)
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,93 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module DoubleDefinitions
5
+ describe DoubleDefinitionCreateBlankSlate do
6
+ attr_reader :double_definition_create, :blank_slate
7
+
8
+ include_examples "Swapped Space"
9
+
10
+ subject { Object.new }
11
+
12
+ before(:each) do
13
+ @double_definition_create = DoubleDefinitionCreate.new
14
+ double_definition_create.mock(subject)
15
+ end
16
+
17
+ describe ".new" do
18
+ it "does not undefine object_id" do
19
+ blank_slate = DoubleDefinitionCreateBlankSlate.new(double_definition_create)
20
+ expect(blank_slate.object_id.class).to eq Fixnum
21
+ end
22
+
23
+ context "without block" do
24
+ before do
25
+ @blank_slate = DoubleDefinitionCreateBlankSlate.new(double_definition_create)
26
+ end
27
+
28
+ it "clears out all methods from proxy" do
29
+ expect(stub(subject).i_should_be_a_double).to be_instance_of(DoubleDefinition)
30
+ end
31
+ end
32
+
33
+ context "when passed a block" do
34
+ context "when the block has an arity of 1" do
35
+ attr_reader :passed_in_argument
36
+ before do
37
+ passed_in_argument = nil
38
+ stub(subject) do |b|
39
+ passed_in_argument = b
40
+ b.foobar(1, 2) {:one_two}
41
+ b.foobar(1) {:one}
42
+ b.foobar.with_any_args {:default}
43
+ b.baz() {:baz_result}
44
+ end
45
+ @passed_in_argument = passed_in_argument
46
+ end
47
+
48
+ it "creates double_injections" do
49
+ expect(subject.foobar(1, 2)).to eq :one_two
50
+ expect(subject.foobar(1)).to eq :one
51
+ expect(subject.foobar(:something)).to eq :default
52
+ expect(subject.baz).to eq :baz_result
53
+ end
54
+
55
+ it "passes the self into the block" do
56
+ expect(passed_in_argument.__double_definition_create__).to be_instance_of(
57
+ ::RR::DoubleDefinitions::DoubleDefinitionCreate
58
+ )
59
+ end
60
+ end
61
+
62
+ context "when the block has an arity of 0" do
63
+ attr_reader :self_value
64
+ before do
65
+ self_value = nil
66
+ stub(subject) do ||
67
+ self_value = self
68
+ foobar(1, 2) {:one_two}
69
+ foobar(1) {:one}
70
+ foobar.with_any_args {:default}
71
+ baz() {:baz_result}
72
+ end
73
+ @self_value = self_value
74
+ end
75
+
76
+ it "creates double_injections" do
77
+ expect(subject.foobar(1, 2)).to eq :one_two
78
+ expect(subject.foobar(1)).to eq :one
79
+ expect(subject.foobar(:something)).to eq :default
80
+ expect(subject.baz).to eq :baz_result
81
+ end
82
+
83
+ it "evaluates the block with the context of self" do
84
+ expect(self_value.__double_definition_create__).to be_instance_of(
85
+ ::RR::DoubleDefinitions::DoubleDefinitionCreate
86
+ )
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,446 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module DoubleDefinitions
5
+ describe DoubleDefinitionCreate do
6
+ subject { Object.new }
7
+
8
+ attr_reader :double_definition_create, :strategy_method_name
9
+
10
+ include_examples "Swapped Space"
11
+
12
+ before(:each) do
13
+ @double_definition_create = DoubleDefinitionCreate.new
14
+ end
15
+
16
+ describe "#root_subject" do
17
+ it "returns #subject" do
18
+ double_definition_create.stub(subject).foobar
19
+ expect(double_definition_create.root_subject).to eq subject
20
+ end
21
+ end
22
+
23
+ describe "StrategySetupMethods" do
24
+ describe "normal strategy definitions" do
25
+ def call_strategy(*args, &block)
26
+ double_definition_create.__send__(strategy_method_name, *args, &block)
27
+ end
28
+
29
+ describe "#mock" do
30
+ before do
31
+ @strategy_method_name = :mock
32
+ end
33
+
34
+ context "when passing no args" do
35
+ it "returns self" do
36
+ expect(call_strategy).to equal double_definition_create
37
+ end
38
+ end
39
+
40
+ context "when passed a subject and a method_name argument" do
41
+ it "creates a mock Double for method" do
42
+ double_definition = double_definition_create.mock(subject, :foobar).returns {:baz}
43
+ expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::IntegerMatcher.new(1)
44
+ expect(double_definition.argument_expectation.class).to eq RR::Expectations::ArgumentEqualityExpectation
45
+ expect(double_definition.argument_expectation.expected_arguments).to eq []
46
+ expect(subject.foobar).to eq :baz
47
+ end
48
+ end
49
+ end
50
+
51
+ describe "#stub" do
52
+ before do
53
+ @strategy_method_name = :stub
54
+ end
55
+
56
+ context "when passing no args" do
57
+ it "returns self" do
58
+ expect(call_strategy).to equal double_definition_create
59
+ end
60
+ end
61
+
62
+ context "when passed subject and a method_name argument" do
63
+ it "creates a stub Double for method when passed a method_name argument" do
64
+ double_definition = double_definition_create.stub(subject, :foobar).returns {:baz}
65
+ expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::AnyTimesMatcher.new
66
+ expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
67
+ expect(subject.foobar).to eq :baz
68
+ end
69
+ end
70
+ end
71
+
72
+ describe "#dont_allow" do
73
+ before do
74
+ @strategy_method_name = :dont_allow
75
+ end
76
+
77
+ context "when passing no args" do
78
+ it "returns self" do
79
+ expect(call_strategy).to equal double_definition_create
80
+ end
81
+ end
82
+
83
+ context "when passed a subject and a method_name argument_expectation" do
84
+ it "creates a mock Double for method" do
85
+ double_definition = double_definition_create.dont_allow(subject, :foobar)
86
+ expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::NeverMatcher.new
87
+ expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
88
+
89
+ expect {
90
+ subject.foobar
91
+ }.to raise_error(RR::Errors::TimesCalledError)
92
+ RR.reset
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ describe "! strategy definitions" do
99
+ attr_reader :strategy_method_name
100
+ def call_strategy(*args, &definition_eval_block)
101
+ double_definition_create.__send__(strategy_method_name, *args, &definition_eval_block)
102
+ end
103
+
104
+ describe "#mock!" do
105
+ before do
106
+ @strategy_method_name = :mock!
107
+ end
108
+
109
+ context "when passed a method_name argument" do
110
+ it "sets #verification_strategy to Mock" do
111
+ double_definition_create.mock!(:foobar)
112
+ expect(double_definition_create.verification_strategy.class).to eq Strategies::Verification::Mock
113
+ expect { RR.verify }.to raise_error(::RR::Errors::TimesCalledError)
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "#stub!" do
119
+ before do
120
+ @strategy_method_name = :stub!
121
+ end
122
+
123
+ context "when passed a method_name argument" do
124
+ it "sets #verification_strategy to Stub" do
125
+ double_definition_create.stub!(:foobar)
126
+ expect(double_definition_create.verification_strategy.class).to eq Strategies::Verification::Stub
127
+ end
128
+ end
129
+ end
130
+
131
+ describe "#dont_allow!" do
132
+ before do
133
+ @strategy_method_name = :dont_allow!
134
+ end
135
+
136
+ context "when passed a method_name argument" do
137
+ it "sets #verification_strategy to DontAllow" do
138
+ double_definition_create.dont_allow!(:foobar)
139
+ expect(double_definition_create.verification_strategy.class).to eq Strategies::Verification::DontAllow
140
+ end
141
+ end
142
+ end
143
+ end
144
+
145
+ describe "#stub.proxy" do
146
+ before do
147
+ class << subject
148
+ def foobar(*args)
149
+ :original_foobar
150
+ end
151
+ end
152
+ end
153
+
154
+ context "when passed a method_name argument" do
155
+ it "creates a proxy Double for method" do
156
+ double_definition = double_definition_create.stub.proxy(subject, :foobar).after_call {:baz}
157
+ expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::AnyTimesMatcher.new
158
+ expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
159
+ expect(subject.foobar).to eq :baz
160
+ end
161
+ end
162
+ end
163
+
164
+ describe "#instance_of" do
165
+ context "when not passed a class" do
166
+ it "raises an ArgumentError" do
167
+ expect {
168
+ double_definition_create.instance_of(Object.new).foobar
169
+ }.to raise_error(ArgumentError, "instance_of only accepts class objects")
170
+ end
171
+ end
172
+
173
+ context "when passed a method_name argument" do
174
+ it "creates a proxy Double for method" do
175
+ klass = Class.new
176
+ double_definition = double_definition_create.stub.instance_of(klass, :foobar).returns {:baz}
177
+ expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::AnyTimesMatcher.new
178
+ expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
179
+ expect(klass.new.foobar).to eq :baz
180
+ end
181
+ end
182
+ end
183
+
184
+ describe "#instance_of.mock" do
185
+ before do
186
+ @klass = Class.new
187
+ end
188
+
189
+ # context "when passed no arguments" do
190
+ # it "returns a DoubleDefinitiondouble_definition_create" do
191
+ # expect(instance_of.instance_of).to be_instance_of(DoubleDefinitionCreate)
192
+ # end
193
+ # end
194
+
195
+ context "when passed a method_name argument" do
196
+ it "creates a instance_of Double for method" do
197
+ double_definition = instance_of.mock(@klass, :foobar)
198
+ double_definition.with(1, 2) {:baz}
199
+ expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::IntegerMatcher.new(1)
200
+ expect(double_definition.argument_expectation.class).to eq RR::Expectations::ArgumentEqualityExpectation
201
+ expect(double_definition.argument_expectation.expected_arguments).to eq [1, 2]
202
+
203
+ expect(@klass.new.foobar(1, 2)).to eq :baz
204
+ end
205
+ end
206
+ end
207
+ end
208
+
209
+ describe "StrategyExecutionMethods" do
210
+ describe "#create" do
211
+ context "when #verification_strategy is a Mock" do
212
+ context "when #implementation_strategy is a Reimplementation" do
213
+ before do
214
+ double_definition_create.mock(subject)
215
+ end
216
+
217
+ it "sets expectation on the #subject that it will be sent the method_name once with the passed-in arguments" do
218
+ mock(subject).foobar(1, 2)
219
+ subject.foobar(1, 2)
220
+ expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
221
+ expect { RR.verify }.to raise_error(RR::Errors::TimesCalledError)
222
+ end
223
+
224
+ describe "#subject.method_name being called" do
225
+ it "returns the return value of the Double#returns block" do
226
+ double_definition_create.call(:foobar, [1, 2], {}) {:baz}
227
+ expect(subject.foobar(1, 2)).to eq :baz
228
+ end
229
+ end
230
+ end
231
+
232
+ context "when #implementation_strategy is a Proxy" do
233
+ before do
234
+ double_definition_create.mock
235
+ double_definition_create.proxy(subject)
236
+ end
237
+
238
+ it "sets expectation on the #subject that it will be sent the method_name once with the passed-in arguments" do
239
+ def subject.foobar(*args)
240
+ :baz
241
+ end
242
+ mock(subject).foobar(1, 2)
243
+
244
+ subject.foobar(1, 2)
245
+ expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
246
+ expect { RR.verify }.to raise_error(RR::Errors::TimesCalledError)
247
+ end
248
+
249
+ describe "#subject.method_name being called" do
250
+ it "calls the original method" do
251
+ original_method_called = false
252
+ (class << subject; self; end).class_eval do
253
+ define_method(:foobar) do |*args|
254
+ original_method_called = true
255
+ end
256
+ end
257
+ double_definition_create.call(:foobar, [1, 2], {})
258
+ subject.foobar(1, 2)
259
+ expect(original_method_called).to be_true
260
+ end
261
+
262
+ context "when not passed a block" do
263
+ it "returns the value of the original method" do
264
+ def subject.foobar(*args)
265
+ :baz;
266
+ end
267
+ double_definition_create.call(:foobar, [1, 2], {})
268
+ expect(subject.foobar(1, 2)).to eq :baz
269
+ end
270
+ end
271
+
272
+ context "when passed a block" do
273
+ attr_reader :real_value
274
+ before do
275
+ @real_value = real_value = Object.new
276
+ (class << subject; self; end).class_eval do
277
+ define_method(:foobar) {|arg1, arg2| real_value}
278
+ end
279
+ end
280
+
281
+ it "calls the block with the return value of the original method" do
282
+ double_definition_create.call(:foobar, [1, 2], {}) do |value|
283
+ mock(value).a_method {99}
284
+ value
285
+ end
286
+ subject.foobar(1, 2)
287
+ expect(real_value.a_method).to eq 99
288
+ end
289
+
290
+ it "returns the return value of the block" do
291
+ double_definition_create.call(:foobar, [1, 2], {}) do |value|
292
+ :something_else
293
+ end
294
+ expect(subject.foobar(1, 2)).to eq :something_else
295
+ end
296
+ end
297
+ end
298
+ end
299
+ end
300
+
301
+ context "when #verification_strategy is a Stub" do
302
+ context "when #implementation_strategy is a Reimplementation" do
303
+ before do
304
+ double_definition_create.stub(subject)
305
+ end
306
+
307
+ context "when not passed a block" do
308
+ it "returns nil" do
309
+ double_definition_create.call(:foobar, [], {})
310
+ expect(subject.foobar).to be_nil
311
+ end
312
+ end
313
+
314
+ context "when passed a block" do
315
+ describe "#subject.method_name being called" do
316
+ it "returns the return value of the block" do
317
+ double_definition_create.call(:foobar, [], {}) {:baz}
318
+ expect(subject.foobar).to eq :baz
319
+ end
320
+ end
321
+ end
322
+
323
+ context "when not passed args" do
324
+ describe "#subject.method_name being called with any arguments" do
325
+ it "invokes the implementation of the Stub" do
326
+ double_definition_create.call(:foobar, [], {}) {:baz}
327
+ expect(subject.foobar(1, 2)).to eq :baz
328
+ expect(subject.foobar()).to eq :baz
329
+ expect(subject.foobar([])).to eq :baz
330
+ end
331
+ end
332
+ end
333
+
334
+ context "when passed args" do
335
+ describe "#subject.method_name being called with the passed-in arguments" do
336
+ it "invokes the implementation of the Stub" do
337
+ double_definition_create.call(:foobar, [1, 2], {}) {:baz}
338
+ expect(subject.foobar(1, 2)).to eq :baz
339
+ end
340
+ end
341
+
342
+ describe "#subject.method_name being called with different arguments" do
343
+ it "raises a DoubleNotFoundError" do
344
+ double_definition_create.call(:foobar, [1, 2], {}) {:baz}
345
+ expect {
346
+ subject.foobar
347
+ }.to raise_error(RR::Errors::DoubleNotFoundError)
348
+ end
349
+ end
350
+ end
351
+ end
352
+
353
+ context "when #implementation_strategy is a Proxy" do
354
+ before do
355
+ def subject.foobar(*args)
356
+ :original_return_value
357
+ end
358
+ double_definition_create.stub
359
+ double_definition_create.proxy(subject)
360
+ end
361
+
362
+ context "when not passed a block" do
363
+ describe "#subject.method_name being called" do
364
+ it "invokes the original implementanion" do
365
+ double_definition_create.call(:foobar, [], {})
366
+ expect(subject.foobar).to eq :original_return_value
367
+ end
368
+ end
369
+ end
370
+
371
+ context "when passed a block" do
372
+ describe "#subject.method_name being called" do
373
+ it "invokes the original implementanion and invokes the block with the return value of the original implementanion" do
374
+ passed_in_value = nil
375
+ double_definition_create.call(:foobar, [], {}) do |original_return_value|
376
+ passed_in_value = original_return_value
377
+ end
378
+ subject.foobar
379
+ expect(passed_in_value).to eq :original_return_value
380
+ end
381
+
382
+ it "returns the return value of the block" do
383
+ double_definition_create.call(:foobar, [], {}) do |original_return_value|
384
+ :new_return_value
385
+ end
386
+ expect(subject.foobar).to eq :new_return_value
387
+ end
388
+ end
389
+ end
390
+
391
+ context "when passed args" do
392
+ describe "#subject.method_name being called with the passed-in arguments" do
393
+ it "invokes the implementation of the Stub" do
394
+ double_definition_create.call(:foobar, [1, 2], {}) {:baz}
395
+ expect(subject.foobar(1, 2)).to eq :baz
396
+ end
397
+ end
398
+
399
+ describe "#subject.method_name being called with different arguments" do
400
+ it "raises a DoubleNotFoundError" do
401
+ double_definition_create.call(:foobar, [1, 2], {}) {:baz}
402
+ expect {
403
+ subject.foobar
404
+ }.to raise_error(RR::Errors::DoubleNotFoundError)
405
+ end
406
+ end
407
+ end
408
+ end
409
+ end
410
+
411
+ context "when #verification_strategy is a DontAllow" do
412
+ before do
413
+ double_definition_create.dont_allow(subject)
414
+ end
415
+
416
+ context "when not passed args" do
417
+ describe "#subject.method_name being called with any arguments" do
418
+ it "raises a TimesCalledError" do
419
+ double_definition_create.call(:foobar, [], {})
420
+ expect { subject.foobar }.to raise_error(RR::Errors::TimesCalledError)
421
+ expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
422
+ end
423
+ end
424
+ end
425
+
426
+ context "when passed args" do
427
+ describe "#subject.method_name being called with the passed-in arguments" do
428
+ it "raises a TimesCalledError" do
429
+ double_definition_create.call(:foobar, [1, 2], {})
430
+ expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
431
+ end
432
+ end
433
+
434
+ describe "#subject.method_name being called with different arguments" do
435
+ it "raises a DoubleNotFoundError" do
436
+ double_definition_create.call(:foobar, [1, 2], {})
437
+ expect { subject.foobar() }.to raise_error(RR::Errors::DoubleNotFoundError)
438
+ end
439
+ end
440
+ end
441
+ end
442
+ end
443
+ end
444
+ end
445
+ end
446
+ end