RSpec::Mocks

Attributes

space[RW]

Public Class Methods

setup(host) click to toggle source
    # File lib/rspec/mocks.rb, line 10
10:       def setup(host)
11:         add_extensions unless extensions_added?
12:         (class << host; self; end

Public Instance Methods

add_expectation(error_generator, expectation_ordering, expected_from, opts, &implementation) click to toggle source

@private

     # File lib/rspec/mocks/method_double.rb, line 134
134:       def add_expectation(error_generator, expectation_ordering, expected_from, opts, &implementation)
135:         configure_method
136:         expectation = if existing_stub = stubs.first
137:                         existing_stub.build_child(expected_from, 1, opts, &implementation)
138:                       else
139:                         MessageExpectation.new(error_generator, expectation_ordering, expected_from, @method_name, 1, opts, &implementation)
140:                       end
141:         expectations << expectation
142:         expectation
143:       end
add_negative_expectation(error_generator, expectation_ordering, expected_from, &implementation) click to toggle source

@private

     # File lib/rspec/mocks/method_double.rb, line 146
146:       def add_negative_expectation(error_generator, expectation_ordering, expected_from, &implementation)
147:         configure_method
148:         expectation = NegativeMessageExpectation.new(error_generator, expectation_ordering, expected_from, @method_name, &implementation)
149:         expectations.unshift expectation
150:         expectation
151:       end
add_stub(error_generator, expectation_ordering, expected_from, opts={}, &implementation) click to toggle source

@private

     # File lib/rspec/mocks/method_double.rb, line 154
154:       def add_stub(error_generator, expectation_ordering, expected_from, opts={}, &implementation)
155:         configure_method
156:         stub = MessageExpectation.new(error_generator, expectation_ordering, expected_from, @method_name, :any, opts, &implementation)
157:         stubs.unshift stub
158:         stub
159:       end
clear() click to toggle source

@private

     # File lib/rspec/mocks/method_double.rb, line 128
128:       def clear
129:         expectations.clear
130:         stubs.clear
131:       end
configure_method() click to toggle source

@private

    # File lib/rspec/mocks/method_double.rb, line 68
68:       def configure_method
69:         RSpec::Mocks::space.add(@object) if RSpec::Mocks::space
70:         warn_if_nil_class
71:         unless @stashed
72:           stash_original_method
73:           define_proxy_method
74:         end
75:       end
define_proxy_method() click to toggle source

@private

    # File lib/rspec/mocks/method_double.rb, line 88
88:       def define_proxy_method
89:         method_name = @method_name
90:         visibility_for_method = "#{visibility} :#{method_name}"
91:         object_singleton_class.class_eval(          def #{method_name}(*args, &block)            __mock_proxy.message_received :#{method_name}, *args, &block          end        #{visibility_for_method}, __FILE__, __LINE__)
92:       end
obfuscate(method_name) click to toggle source

@private

    # File lib/rspec/mocks/method_double.rb, line 47
47:       def obfuscate(method_name)
48:         "obfuscated_by_rspec_mocks__#{method_name}"
49:       end
object_responds_to?(method_name) click to toggle source

@private

    # File lib/rspec/mocks/method_double.rb, line 57
57:       def object_responds_to?(method_name)
58:         if @proxy.already_proxied_respond_to?
59:           @object.__send__(obfuscate(:respond_to?), method_name)
60:         elsif method_name == :respond_to?
61:           @proxy.already_proxied_respond_to
62:         else
63:           @object.respond_to?(method_name, true)
64:         end
65:       end
proxy_for_nil_class?() click to toggle source

@private

     # File lib/rspec/mocks/method_double.rb, line 168
168:       def proxy_for_nil_class?
169:         @object.nil?
170:       end
raise_method_not_stubbed_error() click to toggle source

@private

     # File lib/rspec/mocks/method_double.rb, line 180
180:       def raise_method_not_stubbed_error
181:         raise MockExpectationError, "The method `#{method_name}` was not stubbed or was already unstubbed" 
182:       end
remove_stub() click to toggle source

@private

     # File lib/rspec/mocks/method_double.rb, line 162
162:       def remove_stub
163:         raise_method_not_stubbed_error if stubs.empty?
164:         expectations.empty? ? reset : stubs.clear
165:       end
reset() click to toggle source

@private

     # File lib/rspec/mocks/method_double.rb, line 121
121:       def reset
122:         reset_nil_expectations_warning
123:         restore_original_method
124:         clear
125:       end
reset_nil_expectations_warning() click to toggle source

@private

     # File lib/rspec/mocks/method_double.rb, line 185
185:       def reset_nil_expectations_warning
186:         RSpec::Mocks::Proxy.warn_about_expectations_on_nil = true if proxy_for_nil_class?
187:       end
restore_original_method() click to toggle source

@private

     # File lib/rspec/mocks/method_double.rb, line 100
100:       def restore_original_method
101:         if @stashed
102:           method_name = @method_name
103:           stashed_method_name = self.stashed_method_name
104:           object_singleton_class.instance_eval do
105:             remove_method method_name
106:             if method_defined?(stashed_method_name) || private_method_defined?(stashed_method_name)
107:               alias_method method_name, stashed_method_name
108:               remove_method stashed_method_name
109:             end
110:           end
111:           @stashed = false
112:         end
113:       end
stash_original_method() click to toggle source

@private

    # File lib/rspec/mocks/method_double.rb, line 78
78:       def stash_original_method
79:         stashed = stashed_method_name
80:         orig = @method_name
81:         object_singleton_class.class_eval do
82:           alias_method(stashed, orig) if method_defined?(orig) || private_method_defined?(orig)
83:         end
84:         @stashed = true
85:       end
stashed_method_name() click to toggle source

@private

    # File lib/rspec/mocks/method_double.rb, line 52
52:       def stashed_method_name
53:         obfuscate(method_name)
54:       end
teardown() click to toggle source
    # File lib/rspec/mocks.rb, line 22
22:       def teardown
23:         space.reset_all
24:       end
verify() click to toggle source

@private

     # File lib/rspec/mocks/method_double.rb, line 116
116:       def verify
117:         expectations.each {|e| e.verify_messages_received}
118:       end
verify() click to toggle source
    # File lib/rspec/mocks.rb, line 18
18:       def verify
19:         space.verify_all
20:       end
warn_if_nil_class() click to toggle source

@private

     # File lib/rspec/mocks/method_double.rb, line 173
173:       def warn_if_nil_class
174:         if proxy_for_nil_class? & RSpec::Mocks::Proxy.warn_about_expectations_on_nil
175:           Kernel.warn("An expectation of :#{@method_name} was set on nil. Called from #{caller[4]}. Use allow_message_expectations_on_nil to disable warnings.")
176:         end
177:       end

Private Instance Methods

add_extensions() click to toggle source
    # File lib/rspec/mocks.rb, line 28
28:       def add_extensions
29:         Object.class_eval { include RSpec::Mocks::Methods }
30:         Class.class_eval  { include RSpec::Mocks::AnyInstance }
31:         $_rspec_mocks_extensions_added = true
32:       end
extensions_added?() click to toggle source
    # File lib/rspec/mocks.rb, line 34
34:       def extensions_added?
35:         defined?($_rspec_mocks_extensions_added)
36:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.