Parent

Class Index [+]

Quicksearch

Mocha::ClassMethod

Attributes

stubbee[R]
method[R]

Public Class Methods

new(stubbee, method) click to toggle source
    # File lib/mocha/class_method.rb, line 9
 9:     def initialize(stubbee, method)
10:       @stubbee, @original_method = stubbee, nil
11:       @method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym
12:     end

Public Instance Methods

define_new_method() click to toggle source
    # File lib/mocha/class_method.rb, line 55
55:     def define_new_method
56:       stubbee.__metaclass__.class_eval(%{
57:         def #{method}(*args, &block)
58:           mocha.method_missing(:#{method}, *args, &block)
59:         end
60:       }, __FILE__, __LINE__)
61:     end
hide_original_method() click to toggle source
    # File lib/mocha/class_method.rb, line 36
36:     def hide_original_method
37:       if method_exists?(method)
38:         begin
39:           @original_method = stubbee._method(method)
40:           if @original_method && @original_method.owner == stubbee.__metaclass__
41:             @original_visibility = :public
42:             if stubbee.__metaclass__.protected_instance_methods.include?(method)
43:               @original_visibility = :protected
44:             elsif stubbee.__metaclass__.private_instance_methods.include?(method)
45:               @original_visibility = :private
46:             end
47:             stubbee.__metaclass__.send(:remove_method, method)
48:           end
49:         rescue NameError
50:           # deal with nasties like ActiveRecord::Associations::AssociationProxy
51:         end
52:       end
53:     end
matches?(other) click to toggle source
    # File lib/mocha/class_method.rb, line 77
77:     def matches?(other)
78:       return false unless (other.class == self.class)
79:       (stubbee.object_id == other.stubbee.object_id) and (method == other.method)
80:     end
method_exists?(method) click to toggle source
    # File lib/mocha/class_method.rb, line 88
88:     def method_exists?(method)
89:       symbol = method.to_sym
90:       __metaclass__ = stubbee.__metaclass__
91:       __metaclass__.public_method_defined?(symbol) || __metaclass__.protected_method_defined?(symbol) || __metaclass__.private_method_defined?(symbol)
92:     end
mock() click to toggle source
    # File lib/mocha/class_method.rb, line 28
28:     def mock
29:       stubbee.mocha
30:     end
remove_new_method() click to toggle source
    # File lib/mocha/class_method.rb, line 63
63:     def remove_new_method
64:       stubbee.__metaclass__.send(:remove_method, method)
65:     end
reset_mocha() click to toggle source
    # File lib/mocha/class_method.rb, line 32
32:     def reset_mocha
33:       stubbee.reset_mocha
34:     end
restore_original_method() click to toggle source
    # File lib/mocha/class_method.rb, line 67
67:     def restore_original_method
68:       if @original_method && @original_method.owner == stubbee.__metaclass__
69:         original_method = @original_method
70:         stubbee.__metaclass__.send(:define_method, method) do |*args, &block|
71:           original_method.call(*args, &block)
72:         end
73:         stubbee.__metaclass__.send(@original_visibility, method)
74:       end
75:     end
stub() click to toggle source
    # File lib/mocha/class_method.rb, line 14
14:     def stub
15:       hide_original_method
16:       define_new_method
17:     end
to_s() click to toggle source
    # File lib/mocha/class_method.rb, line 84
84:     def to_s
85:       "#{stubbee}.#{method}"
86:     end
unstub() click to toggle source
    # File lib/mocha/class_method.rb, line 19
19:     def unstub
20:       remove_new_method
21:       restore_original_method
22:       mock.unstub(method.to_sym)
23:       unless mock.any_expectations?
24:         reset_mocha
25:       end
26:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.