redinger-rr 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +221 -0
- data/README.rdoc +343 -0
- data/Rakefile +88 -0
- data/VERSION.yml +4 -0
- data/lib/rr.rb +88 -0
- data/lib/rr/adapters/rr_methods.rb +122 -0
- data/lib/rr/adapters/rspec.rb +59 -0
- data/lib/rr/adapters/test_unit.rb +29 -0
- data/lib/rr/double.rb +152 -0
- data/lib/rr/double_definitions/child_double_definition_creator.rb +27 -0
- data/lib/rr/double_definitions/double_definition.rb +348 -0
- data/lib/rr/double_definitions/double_definition_creator.rb +167 -0
- data/lib/rr/double_definitions/double_definition_creator_proxy.rb +37 -0
- data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +15 -0
- data/lib/rr/double_definitions/strategies/implementation/proxy.rb +62 -0
- data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
- data/lib/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation.rb +17 -0
- data/lib/rr/double_definitions/strategies/scope/instance.rb +15 -0
- data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +50 -0
- data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +15 -0
- data/lib/rr/double_definitions/strategies/strategy.rb +70 -0
- data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +34 -0
- data/lib/rr/double_definitions/strategies/verification/mock.rb +44 -0
- data/lib/rr/double_definitions/strategies/verification/stub.rb +45 -0
- data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +15 -0
- data/lib/rr/double_injection.rb +180 -0
- data/lib/rr/double_matches.rb +51 -0
- data/lib/rr/errors/argument_equality_error.rb +6 -0
- data/lib/rr/errors/double_definition_error.rb +6 -0
- data/lib/rr/errors/double_not_found_error.rb +6 -0
- data/lib/rr/errors/double_order_error.rb +6 -0
- data/lib/rr/errors/rr_error.rb +20 -0
- data/lib/rr/errors/spy_verification_errors/double_injection_not_found_error.rb +8 -0
- data/lib/rr/errors/spy_verification_errors/invocation_count_error.rb +8 -0
- data/lib/rr/errors/spy_verification_errors/spy_verification_error.rb +8 -0
- data/lib/rr/errors/subject_does_not_implement_method_error.rb +6 -0
- data/lib/rr/errors/subject_has_different_arity_error.rb +6 -0
- data/lib/rr/errors/times_called_error.rb +6 -0
- data/lib/rr/expectations/any_argument_expectation.rb +21 -0
- data/lib/rr/expectations/argument_equality_expectation.rb +41 -0
- data/lib/rr/expectations/times_called_expectation.rb +57 -0
- data/lib/rr/hash_with_object_id_key.rb +44 -0
- data/lib/rr/method_dispatches/base_method_dispatch.rb +108 -0
- data/lib/rr/method_dispatches/method_dispatch.rb +61 -0
- data/lib/rr/method_dispatches/method_missing_dispatch.rb +49 -0
- data/lib/rr/proc_from_block.rb +7 -0
- data/lib/rr/recorded_calls.rb +103 -0
- data/lib/rr/space.rb +123 -0
- data/lib/rr/spy_verification.rb +48 -0
- data/lib/rr/spy_verification_proxy.rb +18 -0
- data/lib/rr/times_called_matchers/any_times_matcher.rb +18 -0
- data/lib/rr/times_called_matchers/at_least_matcher.rb +15 -0
- data/lib/rr/times_called_matchers/at_most_matcher.rb +23 -0
- data/lib/rr/times_called_matchers/integer_matcher.rb +19 -0
- data/lib/rr/times_called_matchers/non_terminal.rb +27 -0
- data/lib/rr/times_called_matchers/proc_matcher.rb +11 -0
- data/lib/rr/times_called_matchers/range_matcher.rb +21 -0
- data/lib/rr/times_called_matchers/terminal.rb +20 -0
- data/lib/rr/times_called_matchers/times_called_matcher.rb +44 -0
- data/lib/rr/wildcard_matchers.rb +158 -0
- data/lib/rr/wildcard_matchers/anything.rb +18 -0
- data/lib/rr/wildcard_matchers/boolean.rb +23 -0
- data/lib/rr/wildcard_matchers/duck_type.rb +32 -0
- data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
- data/lib/rr/wildcard_matchers/is_a.rb +25 -0
- data/lib/rr/wildcard_matchers/numeric.rb +13 -0
- data/lib/rr/wildcard_matchers/range.rb +7 -0
- data/lib/rr/wildcard_matchers/regexp.rb +7 -0
- data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
- data/spec/core_spec_suite.rb +19 -0
- data/spec/environment_fixture_setup.rb +7 -0
- data/spec/high_level_spec.rb +398 -0
- data/spec/proc_from_block_spec.rb +14 -0
- data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
- data/spec/rr/adapters/rr_methods_creator_spec.rb +149 -0
- data/spec/rr/adapters/rr_methods_space_spec.rb +115 -0
- data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
- data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +17 -0
- data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +112 -0
- data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +155 -0
- data/spec/rr/double_definitions/double_definition_creator_spec.rb +502 -0
- data/spec/rr/double_definitions/double_definition_spec.rb +1165 -0
- data/spec/rr/double_injection/double_injection_spec.rb +339 -0
- data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
- data/spec/rr/double_spec.rb +352 -0
- data/spec/rr/errors/rr_error_spec.rb +67 -0
- data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
- data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +14 -0
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +135 -0
- data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +34 -0
- data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
- data/spec/rr/expectations/hash_including_spec.rb +17 -0
- data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
- data/spec/rr/expectations/satisfy_spec.rb +14 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +46 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +69 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +23 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +104 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +81 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +83 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +38 -0
- data/spec/rr/rspec/invocation_matcher_spec.rb +279 -0
- data/spec/rr/rspec/rspec_adapter_spec.rb +66 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +31 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec_fixture.rb +11 -0
- data/spec/rr/rspec/rspec_usage_spec.rb +86 -0
- data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
- data/spec/rr/space/space_spec.rb +550 -0
- data/spec/rr/test_unit/test_helper.rb +7 -0
- data/spec/rr/test_unit/test_unit_backtrace_test.rb +36 -0
- data/spec/rr/test_unit/test_unit_integration_test.rb +57 -0
- data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
- data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
- data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
- data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
- data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
- data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
- data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
- data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
- data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
- data/spec/rr_spec.rb +28 -0
- data/spec/rspec_spec_suite.rb +17 -0
- data/spec/spec_helper.rb +109 -0
- data/spec/spec_suite.rb +31 -0
- data/spec/spy_verification_spec.rb +129 -0
- data/spec/test_unit_spec_suite.rb +21 -0
- metadata +193 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
module RR
|
2
|
+
module DoubleDefinitions
|
3
|
+
class DoubleDefinitionCreatorProxy
|
4
|
+
class << self
|
5
|
+
def blank_slate_methods
|
6
|
+
instance_methods.each do |m|
|
7
|
+
unless m =~ /^_/ || m.to_s == 'object_id' || m.to_s == 'respond_to?' || m.to_s == 'method_missing' || m.to_s == 'instance_eval' || m.to_s == 'instance_exec'
|
8
|
+
alias_method "__blank_slated_#{m}", m
|
9
|
+
undef_method m
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(creator, &block) #:nodoc:
|
16
|
+
@creator = creator
|
17
|
+
respond_to?(:class) ? self.class.blank_slate_methods : __blank_slated_class.blank_slate_methods
|
18
|
+
|
19
|
+
if block_given?
|
20
|
+
if block.arity == 1
|
21
|
+
yield(self)
|
22
|
+
else
|
23
|
+
respond_to?(:instance_eval) ? instance_eval(&block) : __blank_slated_instance_eval(&block)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing(method_name, *args, &block)
|
29
|
+
@creator.create(method_name, *args, &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def __creator__
|
33
|
+
@creator
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RR
|
2
|
+
module DoubleDefinitions
|
3
|
+
module Strategies
|
4
|
+
module Implementation
|
5
|
+
class ImplementationStrategy < Strategy
|
6
|
+
class << self
|
7
|
+
def register_self_at_double_definition_creator(domain_name)
|
8
|
+
DoubleDefinitionCreator.register_implementation_strategy_class(self, domain_name)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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
|
+
register("proxy", :probe)
|
52
|
+
|
53
|
+
protected
|
54
|
+
def do_call
|
55
|
+
definition.implemented_by_original_method
|
56
|
+
definition.after_call(&handler) if handler
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RR
|
2
|
+
module DoubleDefinitions
|
3
|
+
module Strategies
|
4
|
+
module Implementation
|
5
|
+
class StronglyTypedReimplementation < Reimplementation
|
6
|
+
register("strong")
|
7
|
+
|
8
|
+
protected
|
9
|
+
def do_call
|
10
|
+
super
|
11
|
+
definition.verify_method_signature
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RR
|
2
|
+
module DoubleDefinitions
|
3
|
+
module Strategies
|
4
|
+
module Scope
|
5
|
+
class Instance < ScopeStrategy
|
6
|
+
protected
|
7
|
+
def do_call
|
8
|
+
double_injection = space.double_injection(subject, method_name)
|
9
|
+
Double.new(double_injection, definition)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module RR
|
2
|
+
module DoubleDefinitions
|
3
|
+
module Strategies
|
4
|
+
module Scope
|
5
|
+
# Calling instance_of will cause all instances of the passed in Class
|
6
|
+
# to have the Double defined.
|
7
|
+
#
|
8
|
+
# The following example mocks all User's valid? method and return false.
|
9
|
+
# mock.instance_of(User).valid? {false}
|
10
|
+
#
|
11
|
+
# The following example mocks and proxies User#projects and returns the
|
12
|
+
# first 3 projects.
|
13
|
+
# mock.instance_of(User).projects do |projects|
|
14
|
+
# projects[0..2]
|
15
|
+
# end
|
16
|
+
class InstanceOfClass < ScopeStrategy
|
17
|
+
register "instance_of"
|
18
|
+
|
19
|
+
def initialize(*args)
|
20
|
+
super
|
21
|
+
|
22
|
+
if !double_definition_creator.no_subject? && !double_definition_creator.subject.is_a?(Class)
|
23
|
+
raise ArgumentError, "instance_of only accepts class objects"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
def do_call
|
29
|
+
instance_of_subject_creator = DoubleDefinitionCreator.new
|
30
|
+
instance_of_subject_creator.strong if definition.verify_method_signature?
|
31
|
+
instance_of_subject_creator.stub(subject)
|
32
|
+
instance_of_subject_creator.create(:new) do |*args|
|
33
|
+
#####
|
34
|
+
instance = subject.allocate
|
35
|
+
double_injection = space.double_injection(instance, method_name)
|
36
|
+
Double.new(double_injection, definition)
|
37
|
+
#####
|
38
|
+
if args.last.is_a?(ProcFromBlock)
|
39
|
+
instance.__send__(:initialize, *args[0..(args.length-2)], &args.last)
|
40
|
+
else
|
41
|
+
instance.__send__(:initialize, *args)
|
42
|
+
end
|
43
|
+
instance
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RR
|
2
|
+
module DoubleDefinitions
|
3
|
+
module Strategies
|
4
|
+
module Scope
|
5
|
+
class ScopeStrategy < Strategy
|
6
|
+
class << self
|
7
|
+
def register_self_at_double_definition_creator(domain_name)
|
8
|
+
DoubleDefinitionCreator.register_scope_strategy_class(self, domain_name)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module RR
|
2
|
+
module DoubleDefinitions
|
3
|
+
module Strategies
|
4
|
+
class Strategy
|
5
|
+
class << self
|
6
|
+
attr_reader :domain_name
|
7
|
+
def register(domain_name, *alias_method_names)
|
8
|
+
@domain_name = domain_name
|
9
|
+
register_self_at_double_definition_creator(domain_name)
|
10
|
+
DoubleDefinitionCreator.class_eval do
|
11
|
+
alias_method_names.each do |alias_method_name|
|
12
|
+
alias_method alias_method_name, domain_name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
RR::Adapters::RRMethods.register_strategy_class(self, domain_name)
|
16
|
+
DoubleDefinition.register_strategy_class(self, domain_name)
|
17
|
+
RR::Adapters::RRMethods.class_eval do
|
18
|
+
alias_method_names.each do |alias_method_name|
|
19
|
+
alias_method alias_method_name, domain_name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def register_self_at_double_definition_creator
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_reader :double_definition_creator, :definition, :method_name, :args, :handler
|
29
|
+
include Space::Reader
|
30
|
+
|
31
|
+
def initialize(double_definition_creator)
|
32
|
+
@double_definition_creator = double_definition_creator
|
33
|
+
end
|
34
|
+
|
35
|
+
def call(definition, method_name, args, handler)
|
36
|
+
@definition, @method_name, @args, @handler = definition, method_name, args, handler
|
37
|
+
do_call
|
38
|
+
end
|
39
|
+
|
40
|
+
def name
|
41
|
+
self.class.domain_name
|
42
|
+
end
|
43
|
+
|
44
|
+
def verify_subject(subject)
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
def do_call
|
49
|
+
raise NotImplementedError
|
50
|
+
end
|
51
|
+
|
52
|
+
def permissive_argument
|
53
|
+
if args.empty?
|
54
|
+
definition.with_any_args
|
55
|
+
else
|
56
|
+
definition.with(*args)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def reimplementation
|
61
|
+
definition.returns(&handler)
|
62
|
+
end
|
63
|
+
|
64
|
+
def subject
|
65
|
+
definition.subject
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RR
|
2
|
+
module DoubleDefinitions
|
3
|
+
module Strategies
|
4
|
+
module Verification
|
5
|
+
# This method sets the Double to have a dont_allow strategy.
|
6
|
+
# A dont_allow strategy sets the default state of the Double
|
7
|
+
# to expect never to be called. The Double's expectations can be
|
8
|
+
# changed.
|
9
|
+
#
|
10
|
+
# The following example sets the expectation that subject.method_name
|
11
|
+
# will never be called with arg1 and arg2.
|
12
|
+
#
|
13
|
+
# do_not_allow(subject).method_name(arg1, arg2)
|
14
|
+
#
|
15
|
+
# dont_allow also supports a block sytnax.
|
16
|
+
# dont_allow(subject) do |m|
|
17
|
+
# m.method1 # Do not allow method1 with any arguments
|
18
|
+
# m.method2(arg1, arg2) # Do not allow method2 with arguments arg1 and arg2
|
19
|
+
# m.method3.with_no_args # Do not allow method3 with no arguments
|
20
|
+
# end
|
21
|
+
class DontAllow < VerificationStrategy
|
22
|
+
register("dont_allow", :do_not_allow, :dont_call, :do_not_call)
|
23
|
+
|
24
|
+
protected
|
25
|
+
def do_call
|
26
|
+
definition.never
|
27
|
+
permissive_argument
|
28
|
+
reimplementation
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module RR
|
2
|
+
module DoubleDefinitions
|
3
|
+
module Strategies
|
4
|
+
module Verification
|
5
|
+
# This method sets the Double to have a mock strategy. A mock strategy
|
6
|
+
# sets the default state of the Double to expect the method call
|
7
|
+
# with arguments exactly one time. The Double's expectations can be
|
8
|
+
# changed.
|
9
|
+
#
|
10
|
+
# This method can be chained with proxy.
|
11
|
+
# mock.proxy(subject).method_name_1
|
12
|
+
# or
|
13
|
+
# proxy.mock(subject).method_name_1
|
14
|
+
#
|
15
|
+
# When passed the subject, a DoubleDefinitionCreatorProxy is returned. Passing
|
16
|
+
# a method with arguments to the proxy will set up expectations that
|
17
|
+
# the a call to the subject's method with the arguments will happen,
|
18
|
+
# and return the prescribed value.
|
19
|
+
# mock(subject).method_name_1 {return_value_1}
|
20
|
+
# mock(subject).method_name_2(arg1, arg2) {return_value_2}
|
21
|
+
#
|
22
|
+
# When passed the subject and the method_name, this method returns
|
23
|
+
# a mock Double with the method already set.
|
24
|
+
#
|
25
|
+
# mock(subject, :method_name_1) {return_value_1}
|
26
|
+
# mock(subject, :method_name_2).with(arg1, arg2) {return_value_2}
|
27
|
+
#
|
28
|
+
# mock also takes a block for definitions.
|
29
|
+
# mock(subject) do
|
30
|
+
# method_name_1 {return_value_1}
|
31
|
+
# method_name_2(arg_1, arg_2) {return_value_2}
|
32
|
+
# end
|
33
|
+
class Mock < VerificationStrategy
|
34
|
+
register "mock"
|
35
|
+
|
36
|
+
protected
|
37
|
+
def do_call
|
38
|
+
definition.with(*args).once
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module RR
|
2
|
+
module DoubleDefinitions
|
3
|
+
module Strategies
|
4
|
+
module Verification
|
5
|
+
# This method sets the Double to have a stub strategy. A stub strategy
|
6
|
+
# sets the default state of the Double to expect the method call
|
7
|
+
# with any arguments any number of times. The Double's
|
8
|
+
# expectations can be changed.
|
9
|
+
#
|
10
|
+
# This method can be chained with proxy.
|
11
|
+
# stub.proxy(subject).method_name_1
|
12
|
+
# or
|
13
|
+
# proxy.stub(subject).method_name_1
|
14
|
+
#
|
15
|
+
# When passed the subject, a DoubleDefinitionCreatorProxy is returned. Passing
|
16
|
+
# a method with arguments to the proxy will set up expectations that
|
17
|
+
# the a call to the subject's method with the arguments will happen,
|
18
|
+
# and return the prescribed value.
|
19
|
+
# stub(subject).method_name_1 {return_value_1}
|
20
|
+
# stub(subject).method_name_2(arg_1, arg_2) {return_value_2}
|
21
|
+
#
|
22
|
+
# When passed the subject and the method_name, this method returns
|
23
|
+
# a stub Double with the method already set.
|
24
|
+
#
|
25
|
+
# mock(subject, :method_name_1) {return_value_1}
|
26
|
+
# mock(subject, :method_name_2).with(arg1, arg2) {return_value_2}
|
27
|
+
#
|
28
|
+
# stub also takes a block for definitions.
|
29
|
+
# stub(subject) do
|
30
|
+
# method_name_1 {return_value_1}
|
31
|
+
# method_name_2(arg_1, arg_2) {return_value_2}
|
32
|
+
# end
|
33
|
+
class Stub < VerificationStrategy
|
34
|
+
register "stub"
|
35
|
+
|
36
|
+
protected
|
37
|
+
def do_call
|
38
|
+
definition.any_number_of_times
|
39
|
+
permissive_argument
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RR
|
2
|
+
module DoubleDefinitions
|
3
|
+
module Strategies
|
4
|
+
module Verification
|
5
|
+
class VerificationStrategy < Strategy
|
6
|
+
class << self
|
7
|
+
def register_self_at_double_definition_creator(domain_name)
|
8
|
+
DoubleDefinitionCreator.register_verification_strategy_class(self, domain_name)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|