mcmire-rr 1.0.5.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/CHANGES +269 -0
  2. data/Gemfile +16 -0
  3. data/Gemfile.lock +47 -0
  4. data/LICENSE +22 -0
  5. data/README.rdoc +390 -0
  6. data/Rakefile +49 -0
  7. data/VERSION +1 -0
  8. data/lib/rr.rb +101 -0
  9. data/lib/rr/adapters/minitest.rb +31 -0
  10. data/lib/rr/adapters/rr_methods.rb +146 -0
  11. data/lib/rr/adapters/rspec.rb +61 -0
  12. data/lib/rr/adapters/rspec2.rb +22 -0
  13. data/lib/rr/adapters/test_unit.rb +31 -0
  14. data/lib/rr/blank_slate.rb +17 -0
  15. data/lib/rr/class_instance_method_defined.rb +9 -0
  16. data/lib/rr/double.rb +154 -0
  17. data/lib/rr/double_definitions/child_double_definition_create.rb +27 -0
  18. data/lib/rr/double_definitions/double_definition.rb +365 -0
  19. data/lib/rr/double_definitions/double_definition_create.rb +139 -0
  20. data/lib/rr/double_definitions/double_definition_create_blank_slate.rb +26 -0
  21. data/lib/rr/double_definitions/double_injections/any_instance_of.rb +28 -0
  22. data/lib/rr/double_definitions/double_injections/instance.rb +16 -0
  23. data/lib/rr/double_definitions/strategies/double_injection/any_instance_of.rb +30 -0
  24. data/lib/rr/double_definitions/strategies/double_injection/double_injection_strategy.rb +10 -0
  25. data/lib/rr/double_definitions/strategies/double_injection/instance.rb +17 -0
  26. data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +10 -0
  27. data/lib/rr/double_definitions/strategies/implementation/proxy.rb +60 -0
  28. data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
  29. data/lib/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation.rb +15 -0
  30. data/lib/rr/double_definitions/strategies/strategy.rb +43 -0
  31. data/lib/rr/double_definitions/strategies/strategy_methods.rb +53 -0
  32. data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +31 -0
  33. data/lib/rr/double_definitions/strategies/verification/mock.rb +42 -0
  34. data/lib/rr/double_definitions/strategies/verification/stub.rb +43 -0
  35. data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +10 -0
  36. data/lib/rr/double_matches.rb +42 -0
  37. data/lib/rr/errors/argument_equality_error.rb +6 -0
  38. data/lib/rr/errors/double_definition_error.rb +6 -0
  39. data/lib/rr/errors/double_not_found_error.rb +6 -0
  40. data/lib/rr/errors/double_order_error.rb +6 -0
  41. data/lib/rr/errors/rr_error.rb +20 -0
  42. data/lib/rr/errors/spy_verification_errors/double_injection_not_found_error.rb +8 -0
  43. data/lib/rr/errors/spy_verification_errors/invocation_count_error.rb +8 -0
  44. data/lib/rr/errors/spy_verification_errors/spy_verification_error.rb +8 -0
  45. data/lib/rr/errors/subject_does_not_implement_method_error.rb +6 -0
  46. data/lib/rr/errors/subject_has_different_arity_error.rb +6 -0
  47. data/lib/rr/errors/times_called_error.rb +6 -0
  48. data/lib/rr/expectations/any_argument_expectation.rb +21 -0
  49. data/lib/rr/expectations/argument_equality_expectation.rb +41 -0
  50. data/lib/rr/expectations/times_called_expectation.rb +57 -0
  51. data/lib/rr/hash_with_object_id_key.rb +46 -0
  52. data/lib/rr/injections/double_injection.rb +220 -0
  53. data/lib/rr/injections/injection.rb +33 -0
  54. data/lib/rr/injections/method_missing_injection.rb +73 -0
  55. data/lib/rr/injections/singleton_method_added_injection.rb +72 -0
  56. data/lib/rr/method_dispatches/base_method_dispatch.rb +84 -0
  57. data/lib/rr/method_dispatches/method_dispatch.rb +59 -0
  58. data/lib/rr/method_dispatches/method_missing_dispatch.rb +61 -0
  59. data/lib/rr/proc_from_block.rb +7 -0
  60. data/lib/rr/recorded_calls.rb +103 -0
  61. data/lib/rr/space.rb +119 -0
  62. data/lib/rr/spy_verification.rb +48 -0
  63. data/lib/rr/spy_verification_proxy.rb +13 -0
  64. data/lib/rr/times_called_matchers/any_times_matcher.rb +18 -0
  65. data/lib/rr/times_called_matchers/at_least_matcher.rb +15 -0
  66. data/lib/rr/times_called_matchers/at_most_matcher.rb +23 -0
  67. data/lib/rr/times_called_matchers/integer_matcher.rb +19 -0
  68. data/lib/rr/times_called_matchers/never_matcher.rb +23 -0
  69. data/lib/rr/times_called_matchers/non_terminal.rb +27 -0
  70. data/lib/rr/times_called_matchers/proc_matcher.rb +11 -0
  71. data/lib/rr/times_called_matchers/range_matcher.rb +21 -0
  72. data/lib/rr/times_called_matchers/terminal.rb +20 -0
  73. data/lib/rr/times_called_matchers/times_called_matcher.rb +44 -0
  74. data/lib/rr/wildcard_matchers.rb +158 -0
  75. data/lib/rr/wildcard_matchers/anything.rb +18 -0
  76. data/lib/rr/wildcard_matchers/boolean.rb +23 -0
  77. data/lib/rr/wildcard_matchers/duck_type.rb +32 -0
  78. data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
  79. data/lib/rr/wildcard_matchers/is_a.rb +25 -0
  80. data/lib/rr/wildcard_matchers/numeric.rb +13 -0
  81. data/lib/rr/wildcard_matchers/range.rb +7 -0
  82. data/lib/rr/wildcard_matchers/regexp.rb +7 -0
  83. data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
  84. data/spec/api/any_instance_of/all_instances_of_spec.rb +12 -0
  85. data/spec/api/any_instance_of/any_instance_of_spec.rb +47 -0
  86. data/spec/api/any_instance_of/instance_of_spec.rb +12 -0
  87. data/spec/api/dont_allow/dont_allow_after_stub_spec.rb +14 -0
  88. data/spec/api/mock/mock_spec.rb +193 -0
  89. data/spec/api/proxy/proxy_spec.rb +86 -0
  90. data/spec/api/spy/spy_spec.rb +49 -0
  91. data/spec/api/strong/strong_spec.rb +87 -0
  92. data/spec/api/stub/stub_spec.rb +152 -0
  93. data/spec/core_spec_suite.rb +18 -0
  94. data/spec/environment_fixture_setup.rb +7 -0
  95. data/spec/minitest_spec_suite.rb +21 -0
  96. data/spec/proc_from_block_spec.rb +14 -0
  97. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
  98. data/spec/rr/adapters/rr_methods_creator_spec.rb +137 -0
  99. data/spec/rr/adapters/rr_methods_space_spec.rb +98 -0
  100. data/spec/rr/adapters/rr_methods_spec_helper.rb +7 -0
  101. data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +13 -0
  102. data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +112 -0
  103. data/spec/rr/double_definitions/double_definition_create_blank_slate_spec.rb +91 -0
  104. data/spec/rr/double_definitions/double_definition_create_spec.rb +443 -0
  105. data/spec/rr/double_injection/double_injection_spec.rb +546 -0
  106. data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
  107. data/spec/rr/errors/rr_error_spec.rb +67 -0
  108. data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
  109. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +14 -0
  110. data/spec/rr/expectations/argument_equality_expectation_spec.rb +135 -0
  111. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +34 -0
  112. data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
  113. data/spec/rr/expectations/hash_including_spec.rb +17 -0
  114. data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
  115. data/spec/rr/expectations/satisfy_spec.rb +14 -0
  116. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +22 -0
  117. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +37 -0
  118. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +43 -0
  119. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +11 -0
  120. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +58 -0
  121. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +35 -0
  122. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +39 -0
  123. data/spec/rr/minitest/minitest_integration_test.rb +59 -0
  124. data/spec/rr/minitest/test_helper.rb +7 -0
  125. data/spec/rr/rspec/invocation_matcher_spec.rb +279 -0
  126. data/spec/rr/rspec/rspec_adapter_spec.rb +63 -0
  127. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +21 -0
  128. data/spec/rr/rspec/rspec_backtrace_tweaking_spec_fixture.rb +11 -0
  129. data/spec/rr/rspec/rspec_usage_spec.rb +86 -0
  130. data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
  131. data/spec/rr/space/space_spec.rb +596 -0
  132. data/spec/rr/test_unit/test_helper.rb +7 -0
  133. data/spec/rr/test_unit/test_unit_backtrace_test.rb +36 -0
  134. data/spec/rr/test_unit/test_unit_integration_test.rb +59 -0
  135. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
  136. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
  137. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
  138. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
  139. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
  140. data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
  141. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
  142. data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
  143. data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
  144. data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
  145. data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
  146. data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
  147. data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
  148. data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
  149. data/spec/rr_spec.rb +28 -0
  150. data/spec/rspec_spec_suite.rb +16 -0
  151. data/spec/spec_helper.rb +40 -0
  152. data/spec/spec_suite.rb +50 -0
  153. data/spec/spy_verification_spec.rb +129 -0
  154. data/spec/test_unit_spec_suite.rb +20 -0
  155. metadata +220 -0
@@ -0,0 +1,139 @@
1
+ module RR
2
+ module DoubleDefinitions
3
+ class DoubleDefinitionCreate # :nodoc
4
+ extend(Module.new do
5
+ def default_double_injection_strategy
6
+ @default_double_injection_strategy ||= lambda do |double_injection_create|
7
+ Strategies::DoubleInjection::Instance.new(double_injection_create)
8
+ end
9
+ end
10
+
11
+ def set_default_double_injection_strategy(strategy_lambda)
12
+ original_strategy_lambda = default_double_injection_strategy
13
+ begin
14
+ @default_double_injection_strategy = strategy_lambda
15
+ yield
16
+ ensure
17
+ @default_double_injection_strategy = original_strategy_lambda
18
+ end
19
+ end
20
+ end)
21
+
22
+ attr_reader :subject, :verification_strategy, :implementation_strategy, :double_injection_strategy
23
+ NO_SUBJECT = Object.new
24
+
25
+ include Space::Reader
26
+
27
+ def initialize
28
+ @verification_strategy = Strategies::Verification::Stub.new(self)
29
+ @implementation_strategy = Strategies::Implementation::Reimplementation.new(self)
30
+ @double_injection_strategy = self.class.default_double_injection_strategy.call(self)
31
+ end
32
+
33
+ def call(method_name, *args, &handler)
34
+ definition = DoubleDefinition.new(self)
35
+ verification_strategy.call(definition, method_name, args, handler)
36
+ implementation_strategy.call(definition, method_name, args, handler)
37
+ double_injection_strategy.call(definition, method_name, args, handler)
38
+ definition
39
+ end
40
+
41
+ def root_subject
42
+ subject
43
+ end
44
+
45
+ def method_name
46
+ @verification_strategy.method_name
47
+ end
48
+
49
+ module StrategySetupMethods
50
+ def no_subject?
51
+ subject.__id__ === NO_SUBJECT.__id__
52
+ end
53
+
54
+ protected
55
+ def add_verification_strategy(verification_strategy_class, subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
56
+ add_strategy(subject, method_name, definition_eval_block) do
57
+ self.verification_strategy = verification_strategy_class.new(self)
58
+ end
59
+ end
60
+
61
+ def add_implementation_strategy(implementation_strategy_class, subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
62
+ add_strategy(subject, method_name, definition_eval_block) do
63
+ self.implementation_strategy = implementation_strategy_class.new(self)
64
+ end
65
+ end
66
+
67
+ def add_double_injection_strategy(double_injection_strategy_class, subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
68
+ add_strategy(subject, method_name, definition_eval_block) do
69
+ self.double_injection_strategy = double_injection_strategy_class.new(self)
70
+ end
71
+ end
72
+
73
+ def add_strategy(subject, method_name, definition_eval_block)
74
+ if method_name && definition_eval_block
75
+ raise ArgumentError, "Cannot pass in a method name and a block"
76
+ end
77
+ @subject = subject
78
+ yield
79
+ # TODO: Allow hash argument to simulate a Struct.
80
+ if no_subject?
81
+ self
82
+ elsif method_name
83
+ # TODO: Pass in arguments.
84
+ call(method_name)
85
+ else
86
+ DoubleDefinitionCreateBlankSlate.new(self, &definition_eval_block)
87
+ end
88
+ end
89
+
90
+ def verification_strategy=(verification_strategy)
91
+ @verification_strategy = verification_strategy
92
+ verification_strategy
93
+ end
94
+
95
+ def implementation_strategy=(implementation_strategy)
96
+ @implementation_strategy = implementation_strategy
97
+ end
98
+
99
+ def double_injection_strategy=(double_injection_strategy)
100
+ @double_injection_strategy = double_injection_strategy
101
+ end
102
+ end
103
+ include StrategySetupMethods
104
+
105
+ class DoubleDefinitionCreateError < Errors::RRError
106
+ end
107
+
108
+ # Verification Strategies
109
+ include ::RR::DoubleDefinitions::Strategies::StrategyMethods
110
+ def mock(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
111
+ self.add_verification_strategy(::RR::DoubleDefinitions::Strategies::Verification::Mock, subject, method_name, &definition_eval_block)
112
+ end
113
+
114
+ def stub(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
115
+ self.add_verification_strategy(::RR::DoubleDefinitions::Strategies::Verification::Stub, subject, method_name, &definition_eval_block)
116
+ end
117
+
118
+ def dont_allow(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
119
+ self.add_verification_strategy(::RR::DoubleDefinitions::Strategies::Verification::DontAllow, subject, method_name, &definition_eval_block)
120
+ end
121
+
122
+ # Implementation Strategies
123
+ def proxy(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
124
+ self.add_implementation_strategy(::RR::DoubleDefinitions::Strategies::Implementation::Proxy, subject, method_name, &definition_eval_block)
125
+ end
126
+
127
+ def strong(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
128
+ self.add_implementation_strategy(::RR::DoubleDefinitions::Strategies::Implementation::StronglyTypedReimplementation, subject, method_name, &definition_eval_block)
129
+ end
130
+
131
+ # DoubleInjection Strategies
132
+ def instance_of(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
133
+ self.add_double_injection_strategy(::RR::DoubleDefinitions::Strategies::DoubleInjection::AnyInstanceOf, subject, method_name, &definition_eval_block)
134
+ end
135
+ alias_method :any_instance_of, :instance_of
136
+ alias_method :all_instances_of, :instance_of
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,26 @@
1
+ module RR
2
+ module DoubleDefinitions
3
+ class DoubleDefinitionCreateBlankSlate
4
+ def initialize(double_definition_create, &block) #:nodoc:
5
+ @double_definition_create = double_definition_create
6
+ BlankSlate.call(respond_to?(:class) ? self.class : __blank_slated_class)
7
+
8
+ if block_given?
9
+ if block.arity == 1
10
+ yield(self)
11
+ else
12
+ respond_to?(:instance_eval) ? instance_eval(&block) : __blank_slated_instance_eval(&block)
13
+ end
14
+ end
15
+ end
16
+
17
+ def method_missing(method_name, *args, &block)
18
+ @double_definition_create.call(method_name, *args, &block)
19
+ end
20
+
21
+ def __double_definition_create__
22
+ @double_definition_create
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ module RR
2
+ module DoubleDefinitions
3
+ module DoubleInjections
4
+ class AnyInstanceOf
5
+ extend(Module.new do
6
+ include RR::Adapters::RRMethods
7
+
8
+ def call(subject_class, stubbed_methods=nil, &block)
9
+ ::RR::DoubleDefinitions::DoubleDefinitionCreate.set_default_double_injection_strategy(lambda do |double_definition_create|
10
+ ::RR::DoubleDefinitions::Strategies::DoubleInjection::AnyInstanceOf.new(double_definition_create)
11
+ end) do
12
+ if stubbed_methods
13
+ subject_class.class_eval do
14
+ stubbed_methods.each do |name, value|
15
+ value_proc = value.is_a?(Proc) ? value : lambda {value}
16
+ RR.stub(subject_class, name).returns(&value_proc)
17
+ end
18
+ end
19
+ else
20
+ block.call(subject_class)
21
+ end
22
+ end
23
+ end
24
+ end)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ module RR
2
+ module DoubleDefinitions
3
+ module DoubleInjections
4
+ class Instance
5
+ extend(Module.new do
6
+ include ::RR::Adapters::RRMethods
7
+
8
+ def call(double_method_name, *args, &definition_eval_block)
9
+ double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
10
+ double_definition_create.send(double_method_name, *args, &definition_eval_block)
11
+ end
12
+ end)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,30 @@
1
+ module RR
2
+ module DoubleDefinitions
3
+ module Strategies
4
+ module DoubleInjection
5
+ # This class is Deprecated.
6
+ # Calling instance_of will cause all instances of the passed in Class
7
+ # to have the Double defined.
8
+ #
9
+ # The following example mocks all User's valid? method and return false.
10
+ # mock.instance_of(User).valid? {false}
11
+ #
12
+ # The following example mocks and proxies User#projects and returns the
13
+ # first 3 projects.
14
+ # mock.instance_of(User).projects do |projects|
15
+ # projects[0..2]
16
+ # end
17
+ class AnyInstanceOf < DoubleInjectionStrategy
18
+ protected
19
+ def do_call
20
+ if !double_definition_create.no_subject? && !double_definition_create.subject.is_a?(Class)
21
+ raise ArgumentError, "instance_of only accepts class objects"
22
+ end
23
+ double_injection = Injections::DoubleInjection.find_or_create(subject, method_name)
24
+ Double.new(double_injection, definition)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ module RR
2
+ module DoubleDefinitions
3
+ module Strategies
4
+ module DoubleInjection
5
+ class DoubleInjectionStrategy < Strategy
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ module RR
2
+ module DoubleDefinitions
3
+ module Strategies
4
+ module DoubleInjection
5
+ class Instance < DoubleInjectionStrategy
6
+ protected
7
+ def do_call
8
+ double_injection = Injections::DoubleInjection.find_or_create(
9
+ (class << subject; self; end), method_name
10
+ )
11
+ Double.new(double_injection, definition)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module RR
2
+ module DoubleDefinitions
3
+ module Strategies
4
+ module Implementation
5
+ class ImplementationStrategy < Strategy
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,60 @@
1
+ module RR
2
+ module DoubleDefinitions
3
+ module Strategies
4
+ module Implementation
5
+ # This method add proxy capabilities to the Double. proxy can be called
6
+ # with mock or stub.
7
+ #
8
+ # mock.proxy(controller.template).render(:partial => "my/socks")
9
+ #
10
+ # stub.proxy(controller.template).render(:partial => "my/socks") do |html|
11
+ # html.should include("My socks are wet")
12
+ # html
13
+ # end
14
+ #
15
+ # mock.proxy(controller.template).render(:partial => "my/socks") do |html|
16
+ # html.should include("My socks are wet")
17
+ # "My new return value"
18
+ # end
19
+ #
20
+ # mock.proxy also takes a block for definitions.
21
+ # mock.proxy(subject) do
22
+ # render(:partial => "my/socks")
23
+ #
24
+ # render(:partial => "my/socks") do |html|
25
+ # html.should include("My socks are wet")
26
+ # html
27
+ # end
28
+ #
29
+ # render(:partial => "my/socks") do |html|
30
+ # html.should include("My socks are wet")
31
+ # html
32
+ # end
33
+ #
34
+ # render(:partial => "my/socks") do |html|
35
+ # html.should include("My socks are wet")
36
+ # "My new return value"
37
+ # end
38
+ # end
39
+ #
40
+ # Passing a block to the Double (after the method name and arguments)
41
+ # allows you to intercept the return value.
42
+ # The return value can be modified, validated, and/or overridden by
43
+ # passing in a block. The return value of the block will replace
44
+ # the actual return value.
45
+ #
46
+ # mock.proxy(controller.template).render(:partial => "my/socks") do |html|
47
+ # html.should include("My socks are wet")
48
+ # "My new return value"
49
+ # end
50
+ class Proxy < ImplementationStrategy
51
+ protected
52
+ def do_call
53
+ definition.implemented_by_original_method
54
+ definition.after_call(&handler) if handler
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,14 @@
1
+ module RR
2
+ module DoubleDefinitions
3
+ module Strategies
4
+ module Implementation
5
+ class Reimplementation < ImplementationStrategy
6
+ protected
7
+ def do_call
8
+ reimplementation
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module RR
2
+ module DoubleDefinitions
3
+ module Strategies
4
+ module Implementation
5
+ class StronglyTypedReimplementation < Reimplementation
6
+ protected
7
+ def do_call
8
+ super
9
+ definition.verify_method_signature
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,43 @@
1
+ module RR
2
+ module DoubleDefinitions
3
+ module Strategies
4
+ class Strategy
5
+ attr_reader :double_definition_create, :definition, :method_name, :args, :handler
6
+ include Space::Reader
7
+
8
+ def initialize(double_definition_create)
9
+ @double_definition_create = double_definition_create
10
+ end
11
+
12
+ def call(definition, method_name, args, handler)
13
+ @definition, @method_name, @args, @handler = definition, method_name, args, handler
14
+ do_call
15
+ end
16
+
17
+ def verify_subject(subject)
18
+ end
19
+
20
+ protected
21
+ def do_call
22
+ raise NotImplementedError
23
+ end
24
+
25
+ def permissive_argument
26
+ if args.empty?
27
+ definition.with_any_args
28
+ else
29
+ definition.with(*args)
30
+ end
31
+ end
32
+
33
+ def reimplementation
34
+ definition.returns(&handler)
35
+ end
36
+
37
+ def subject
38
+ definition.subject
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,53 @@
1
+ module RR
2
+ module DoubleDefinitions
3
+ module Strategies
4
+ module StrategyMethods
5
+ extend(Module.new do
6
+ def lately_bound_alias_method(target_method_name, source_method_name)
7
+ module_eval((<<-METHOD), __FILE__, __LINE__+1)
8
+ def #{target_method_name}(*args, &block)
9
+ #{source_method_name}(*args, &block)
10
+ end
11
+ METHOD
12
+ end
13
+ end)
14
+
15
+ def mock!(method_name=nil, &definition_eval_block)
16
+ mock(Object.new, method_name, &definition_eval_block)
17
+ end
18
+
19
+ def stub!(method_name=nil, &definition_eval_block)
20
+ stub(Object.new, method_name, &definition_eval_block)
21
+ end
22
+
23
+ def dont_allow!(method_name=nil, &definition_eval_block)
24
+ dont_allow(Object.new, method_name, &definition_eval_block)
25
+ end
26
+ lately_bound_alias_method :do_not_allow, :dont_allow
27
+ lately_bound_alias_method :do_not_allow!, :dont_allow!
28
+
29
+ def proxy!(method_name=nil, &definition_eval_block)
30
+ proxy(Object.new, method_name, &definition_eval_block)
31
+ end
32
+ lately_bound_alias_method :probe, :proxy
33
+ lately_bound_alias_method :probe!, :proxy!
34
+
35
+ def strong!(method_name=nil, &definition_eval_block)
36
+ strong(Object.new, method_name, &definition_eval_block)
37
+ end
38
+
39
+ def any_instance_of!(method_name=nil, &definition_eval_block)
40
+ any_instance_of(Object.new, method_name, &definition_eval_block)
41
+ end
42
+ lately_bound_alias_method :all_instances_of, :any_instance_of
43
+ lately_bound_alias_method :all_instances_of!, :any_instance_of!
44
+
45
+ def instance_of!(method_name=nil, &definition_eval_block)
46
+ instance_of(Object.new, method_name, &definition_eval_block)
47
+ end
48
+ lately_bound_alias_method :new_instance_of, :instance_of
49
+ lately_bound_alias_method :new_instance_of!, :instance_of!
50
+ end
51
+ end
52
+ end
53
+ end