GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: RR (Double Ruby) is a test double framework that features a rich selection of double techniques and a terse syntax.
Homepage: http://rubyforge.org/projects/double-ruby
Clone URL: git://github.com/btakita/rr.git
Extracted Strategy .domain_name methods into .domain_name. @domain_name is 
set in Strategy.register.
btakita (author)
Tue Oct 07 21:49:37 -0700 2008
commit  a07a0a00ac7138781fb8dec5c04cb7a2da1757fd
tree    67ed2a48c88c874b721907b13fab9c22d770b5c7
parent  5e6e689d0a036d0368ab474b7042ed1f6962a7ba
...
2
3
4
5
 
6
7
 
8
9
10
...
12
13
14
15
16
 
 
17
18
19
20
21
 
22
23
 
24
25
26
...
28
29
30
31
32
 
 
33
34
35
36
37
 
38
39
 
40
41
42
...
44
45
46
47
48
 
 
49
50
51
...
2
3
4
 
5
6
 
7
8
9
10
...
12
13
14
 
 
15
16
17
18
19
20
 
21
22
 
23
24
25
26
...
28
29
30
 
 
31
32
33
34
35
36
 
37
38
 
39
40
41
42
...
44
45
46
 
 
47
48
49
50
51
0
@@ -2,9 +2,9 @@ module RR
0
   module DoubleDefinitions
0
     class DoubleDefinitionCreator # :nodoc
0
       class << self
0
- def register_verification_strategy_class(strategy_class)
0
+ def register_verification_strategy_class(strategy_class, method_name)
0
           class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
0
- def #{strategy_class.domain_name}(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
0
+ def #{method_name}(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
0
             add_strategy(subject, method_name, definition_eval_block) do
0
               self.verification_strategy = #{strategy_class.name}.new(self)
0
             end
0
@@ -12,15 +12,15 @@ module RR
0
           CLASS
0
 
0
           class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
0
- def #{strategy_class.domain_name}!(method_name=nil, &definition_eval_block)
0
- #{strategy_class.domain_name}(Object.new, method_name, &definition_eval_block)
0
+ def #{method_name}!(method_name=nil, &definition_eval_block)
0
+ #{method_name}(Object.new, method_name, &definition_eval_block)
0
           end
0
           CLASS
0
         end
0
 
0
- def register_implementation_strategy_class(strategy_class)
0
+ def register_implementation_strategy_class(strategy_class, method_name)
0
           class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
0
- def #{strategy_class.domain_name}(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
0
+ def #{method_name}(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
0
             add_strategy(subject, method_name, definition_eval_block) do
0
               self.implementation_strategy = #{strategy_class.name}.new(self)
0
             end
0
@@ -28,15 +28,15 @@ module RR
0
           CLASS
0
 
0
           class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
0
- def #{strategy_class.domain_name}!(method_name=nil, &definition_eval_block)
0
- #{strategy_class.domain_name}(Object.new, method_name, &definition_eval_block)
0
+ def #{method_name}!(method_name=nil, &definition_eval_block)
0
+ #{method_name}(Object.new, method_name, &definition_eval_block)
0
           end
0
           CLASS
0
         end
0
 
0
- def register_scope_strategy_class(strategy_class)
0
+ def register_scope_strategy_class(strategy_class, method_name)
0
           class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
0
- def #{strategy_class.domain_name}(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
0
+ def #{method_name}(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
0
             add_strategy(subject, method_name, definition_eval_block) do
0
               self.scope_strategy = #{strategy_class.name}.new(self)
0
             end
0
@@ -44,8 +44,8 @@ module RR
0
           CLASS
0
 
0
           class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
0
- def #{strategy_class.domain_name}!(method_name=nil, &definition_eval_block)
0
- #{strategy_class.domain_name}(Object.new, method_name, &definition_eval_block)
0
+ def #{method_name}!(method_name=nil, &definition_eval_block)
0
+ #{method_name}(Object.new, method_name, &definition_eval_block)
0
           end
0
           CLASS
0
         end
...
4
5
6
7
8
9
 
 
10
11
12
...
4
5
6
 
 
 
7
8
9
10
11
0
@@ -4,9 +4,8 @@ module RR
0
       module Implementation
0
         class ImplementationStrategy < Strategy
0
           class << self
0
- def register(*alias_method_names)
0
- DoubleDefinitionCreator.register_implementation_strategy_class(self)
0
- super
0
+ def register_self_at_external_object(domain_name)
0
+ DoubleDefinitionCreator.register_implementation_strategy_class(self, domain_name)
0
             end
0
           end
0
         end
...
48
49
50
51
52
53
54
55
56
 
57
58
59
...
48
49
50
 
 
 
 
 
 
51
52
53
54
0
@@ -48,12 +48,7 @@ module RR
0
         # "My new return value"
0
         # end
0
         class Proxy < ImplementationStrategy
0
- class << self
0
- def domain_name
0
- "proxy"
0
- end
0
- end
0
- register(:probe)
0
+ register("proxy", :probe)
0
 
0
           protected
0
           def do_call
...
3
4
5
6
7
8
9
10
11
12
13
14
...
3
4
5
 
 
 
 
 
 
6
7
8
0
@@ -3,12 +3,6 @@ module RR
0
     module Strategies
0
       module Implementation
0
         class Reimplementation < ImplementationStrategy
0
- class << self
0
- def domain_name
0
- "reimplementation"
0
- end
0
- end
0
-
0
           protected
0
           def do_call
0
             reimplementation
...
3
4
5
6
7
8
9
10
11
12
13
14
...
3
4
5
 
 
 
 
 
 
6
7
8
0
@@ -3,12 +3,6 @@ module RR
0
     module Strategies
0
       module Scope
0
         class Instance < ScopeStrategy
0
- class << self
0
- def domain_name
0
- "instance"
0
- end
0
- end
0
-
0
           protected
0
           def do_call
0
             double_injection = space.double_injection(subject, method_name)
...
14
15
16
17
18
19
20
21
22
 
23
24
25
...
14
15
16
 
 
 
 
 
 
17
18
19
20
0
@@ -14,12 +14,7 @@ module RR
0
         # projects[0..2]
0
         # end
0
         class InstanceOfClass < ScopeStrategy
0
- class << self
0
- def domain_name
0
- "instance_of"
0
- end
0
- end
0
- register
0
+ register "instance_of"
0
 
0
           def initialize(*args)
0
             super
...
4
5
6
7
8
9
 
 
10
11
12
...
4
5
6
 
 
 
7
8
9
10
11
0
@@ -4,9 +4,8 @@ module RR
0
       module Scope
0
         class ScopeStrategy < Strategy
0
           class << self
0
- def register(*alias_method_names)
0
- DoubleDefinitionCreator.register_scope_strategy_class(self)
0
- super
0
+ def register_self_at_external_object(domain_name)
0
+ DoubleDefinitionCreator.register_scope_strategy_class(self, domain_name)
0
             end
0
           end
0
         end
...
3
4
5
6
7
 
 
 
 
8
9
10
 
11
12
13
 
 
 
14
15
16
...
3
4
5
 
 
6
7
8
9
10
11
 
12
13
14
15
16
17
18
19
20
21
0
@@ -3,14 +3,19 @@ module RR
0
     module Strategies
0
       class Strategy
0
         class << self
0
- def register(*alias_method_names)
0
- strategy = self
0
+ attr_reader :domain_name
0
+ def register(domain_name, *alias_method_names)
0
+ @domain_name = domain_name
0
+ register_self_at_external_object(domain_name)
0
             DoubleDefinitionCreator.class_eval do
0
               alias_method_names.each do |alias_method_name|
0
- alias_method alias_method_name, strategy.domain_name
0
+ alias_method alias_method_name, domain_name
0
               end
0
             end
0
           end
0
+
0
+ def register_self_at_external_object
0
+ end
0
         end
0
 
0
         attr_reader :double_definition_creator, :definition, :method_name, :args, :handler
...
19
20
21
22
23
24
25
26
27
 
28
29
30
...
19
20
21
 
 
 
 
 
 
22
23
24
25
0
@@ -19,12 +19,7 @@ module RR
0
         # m.method3.with_no_args # Do not allow method3 with no arguments
0
         # end
0
         class DontAllow < VerificationStrategy
0
- class << self
0
- def domain_name
0
- "dont_allow"
0
- end
0
- end
0
- register(:do_not_allow, :dont_call, :do_not_call)
0
+ register("dont_allow", :do_not_allow, :dont_call, :do_not_call)
0
 
0
           protected
0
           def do_call
...
31
32
33
34
35
36
37
38
39
 
40
41
42
...
31
32
33
 
 
 
 
 
 
34
35
36
37
0
@@ -31,12 +31,7 @@ module RR
0
         # method_name_2(arg_1, arg_2) {return_value_2}
0
         # end
0
         class Mock < VerificationStrategy
0
- class << self
0
- def domain_name
0
- "mock"
0
- end
0
- end
0
- register
0
+ register "mock"
0
 
0
           protected
0
           def do_call
...
31
32
33
34
35
36
37
38
39
 
40
41
42
...
31
32
33
 
 
 
 
 
 
34
35
36
37
0
@@ -31,12 +31,7 @@ module RR
0
         # method_name_2(arg_1, arg_2) {return_value_2}
0
         # end
0
         class Stub < VerificationStrategy
0
- class << self
0
- def domain_name
0
- "stub"
0
- end
0
- end
0
- register
0
+ register "stub"
0
 
0
           protected
0
           def do_call
...
4
5
6
7
8
9
 
 
10
11
12
...
4
5
6
 
 
 
7
8
9
10
11
0
@@ -4,9 +4,8 @@ module RR
0
       module Verification
0
         class VerificationStrategy < Strategy
0
           class << self
0
- def register(*alias_method_names)
0
- DoubleDefinitionCreator.register_verification_strategy_class(self)
0
- super
0
+ def register_self_at_external_object(domain_name)
0
+ DoubleDefinitionCreator.register_verification_strategy_class(self, domain_name)
0
             end
0
           end
0
         end

Comments

    No one has commented yet.