Module: Crspec::Mock::Interceptor
- Defined in:
- lib/crspec/mock/interceptor.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, **kwargs, &block) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/crspec/mock/interceptor.rb', line 6
def method_missing(method_name, *args, **kwargs, &block)
space = Fiber[Space::STORAGE_KEY]
if space && (stub = space.fetch_stub(self, method_name))
stub.call(*args, **kwargs, &block)
else
super
end
end
|
Class Method Details
.add_intercept_method(method_name) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/crspec/mock/interceptor.rb', line 20
def self.add_intercept_method(method_name)
method_sym = method_name.to_sym
return if instance_methods(false).include?(method_sym) || private_instance_methods(false).include?(method_sym)
define_method(method_sym) do |*args, **kwargs, &block|
space = Fiber[Space::STORAGE_KEY]
if space && (stub = space.fetch_stub(self, method_sym))
stub.call(*args, **kwargs, &block)
else
super(*args, **kwargs, &block)
end
end
end
|
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
15
16
17
18
|
# File 'lib/crspec/mock/interceptor.rb', line 15
def respond_to_missing?(method_name, include_private = false)
space = Fiber[Space::STORAGE_KEY]
space&.fetch_stub(self, method_name) || super
end
|