Module: TzuMock::ClassMethods

Included in:
TzuMock
Defined in:
lib/tzu_mock/class_methods.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



3
4
5
6
# File 'lib/tzu_mock/class_methods.rb', line 3

def method_missing(method, *args)
  return super(method) unless [:success, :invalid, :failure].include? method
  prepare(method, *args)
end

Instance Method Details

#prepare(type, klass, method = nil) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/tzu_mock/class_methods.rb', line 8

def prepare(type, klass, method = nil)
  # Get the rspec block context. Will not work if you call TzuMock#prepare directly.
  # Call TzuMock#success, TzuMock#invalid, or TzuMock#failure instead
  rspec_context = binding.of_caller(2).eval('self')

  Mocker.new(type, klass, rspec_context, method).mock
end