Parent

Files

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 = stubbee
11:       @method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym
12:     end

Public Instance Methods

==(other) click to toggle source
Alias for: eql?
define_new_method() click to toggle source
    # File lib/mocha/class_method.rb, line 39
39:     def define_new_method
40:       stubbee.__metaclass__.class_eval(%{
41:         def #{method}(*args, &block)
42:           mocha.method_missing(:#{method}, *args, &block)
43:         end
44:       }, __FILE__, __LINE__)
45:     end
eql?(other) click to toggle source
    # File lib/mocha/class_method.rb, line 72
72:     def eql?(other)
73:       return false unless (other.class == self.class)
74:       (stubbee.object_id == other.stubbee.object_id) and (method == other.method)
75:     end
Also aliased as: ==
hidden_method() click to toggle source
    # File lib/mocha/class_method.rb, line 62
62:     def hidden_method
63:       if RUBY_VERSION < '1.9'
64:         method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s[0]}_" }
65:       else
66:         method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s.ord}_" }
67:       end
68:       hidden_method = "__stubba__#{method_name}__stubba__"
69:       RUBY_VERSION < '1.9' ? hidden_method.to_s : hidden_method.to_sym
70:     end
hide_original_method() click to toggle source
    # File lib/mocha/class_method.rb, line 29
29:     def hide_original_method
30:       if method_exists?(method)
31:         begin
32:           stubbee.__metaclass__.send(:alias_method, hidden_method, method)
33:         rescue NameError
34:           # deal with nasties like ActiveRecord::Associations::AssociationProxy
35:         end
36:       end
37:     end
method_exists?(method) click to toggle source
    # File lib/mocha/class_method.rb, line 83
83:     def method_exists?(method)
84:       symbol = method.to_sym
85:       metaclass = stubbee.__metaclass__
86:       metaclass.public_method_defined?(symbol) || metaclass.protected_method_defined?(symbol) || metaclass.private_method_defined?(symbol)
87:     end
mock() click to toggle source
    # File lib/mocha/class_method.rb, line 25
25:     def mock
26:       stubbee.mocha
27:     end
remove_new_method() click to toggle source
    # File lib/mocha/class_method.rb, line 47
47:     def remove_new_method
48:       stubbee.__metaclass__.send(:remove_method, method)
49:     end
restore_original_method() click to toggle source
    # File lib/mocha/class_method.rb, line 51
51:     def restore_original_method
52:       if method_exists?(hidden_method)
53:         begin
54:           stubbee.__metaclass__.send(:alias_method, method, hidden_method)
55:           stubbee.__metaclass__.send(:remove_method, hidden_method)
56:         rescue NameError
57:           # deal with nasties like ActiveRecord::Associations::AssociationProxy
58:         end
59:       end
60:     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 79
79:     def to_s
80:       "#{stubbee}.#{method}"
81:     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:       stubbee.reset_mocha
23:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.