module Mocha::ClassMethods

Methods added to all classes to allow mocking and stubbing on real (i.e. non-mock) objects.

Public Instance Methods

__method_exists__?(method, include_public_methods = true)

rubocop:enable Metrics/CyclomaticComplexity

__method_visibility__(method, include_public_methods = true) click to toggle source

@private rubocop:disable Metrics/CyclomaticComplexity

# File lib/mocha/class_methods.rb, line 54
def __method_visibility__(method, include_public_methods = true)
  (include_public_methods && public_method_defined?(method) && :public) ||
    (protected_method_defined?(method) && :protected) ||
    (private_method_defined?(method) && :private)
end
Also aliased as: __method_exists__?
any_instance() click to toggle source

@return [Mock] a mock object which will detect calls to any instance of this class. @raise [StubbingError] if attempting to stub method which is not allowed.

@example Return false to invocation of +Product#save+ for any instance of Product.

Product.any_instance.stubs(:save).returns(false)
product_1 = Product.new
assert_equal false, product_1.save
product_2 = Product.new
assert_equal false, product_2.save
# File lib/mocha/class_methods.rb, line 45
def any_instance
  if frozen?
    raise StubbingError.new("can't stub method on frozen object: #{mocha_inspect}.any_instance", caller)
  end
  @any_instance ||= AnyInstance.new(self)
end