File: proxy.rb

package info (click to toggle)
ruby-rr 3.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,424 kB
  • sloc: ruby: 11,405; makefile: 7
file content (60 lines) | stat: -rw-r--r-- 2,108 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module RR
  module DoubleDefinitions
    module Strategies
      module Implementation
        # This method add proxy capabilities to the Double. proxy can be called
        # with mock or stub.
        #
        #   mock.proxy(controller.template).render(:partial => "my/socks")
        #
        #   stub.proxy(controller.template).render(:partial => "my/socks") do |html|
        #     html.should include("My socks are wet")
        #     html
        #   end
        #
        #   mock.proxy(controller.template).render(:partial => "my/socks") do |html|
        #     html.should include("My socks are wet")
        #     "My new return value"
        #   end
        #
        # mock.proxy also takes a block for definitions.
        #   mock.proxy(subject) do
        #     render(:partial => "my/socks")
        #
        #     render(:partial => "my/socks") do |html|
        #       html.should include("My socks are wet")
        #       html
        #     end
        #
        #     render(:partial => "my/socks") do |html|
        #       html.should include("My socks are wet")
        #       html
        #     end
        #
        #     render(:partial => "my/socks") do |html|
        #       html.should include("My socks are wet")
        #       "My new return value"
        #     end
        #   end
        #
        # Passing a block to the Double (after the method name and arguments)
        # allows you to intercept the return value.
        # The return value can be modified, validated, and/or overridden by
        # passing in a block. The return value of the block will replace
        # the actual return value.
        #
        #   mock.proxy(controller.template).render(:partial => "my/socks") do |html|
        #     html.should include("My socks are wet")
        #     "My new return value"
        #   end        
        class Proxy < ImplementationStrategy
          protected
          def do_call
            definition.implemented_by_original_method
            definition.after_call(&handler) if handler
          end
        end
      end
    end
  end
end