Method: Minitest::Moar::Stubbing#stub

Defined in:
lib/minitest/moar/stubbing.rb

#stub(klass, name, val_or_callable = nil, *block_args, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/minitest/moar/stubbing.rb', line 2

def stub klass, name, val_or_callable = nil, *block_args, &block
  @invocations ||= Hash.new { |h, k| h[k] = Hash.new { |_h, _k| _h[_k] = 0 } }

  metaclass = class << klass; self; end

  if metaclass.respond_to? name and not metaclass.instance_methods.map(&:to_s).include? name.to_s then
    metaclass.send :define_method, name do |*args|
      super(*args)
    end
  end
  __stub__ metaclass, name, val_or_callable, block_args, &block
end