def mock object, method, visibility = nil, &proc
      if method.is_a?(Hash)
        proc && raise(ArgumentError, 'Both Hash and block given. Please use either one.')
        method.each_pair {|m,r| mock(object, m, visibility, &proc {r})}
        return MiniSpec::Mocks::HashedStub
      end
      visibility ||= MiniSpec::Utils.method_visibility(object, method) || :public
      # IMPORTANT! stub should be defined before expectation
      stub = stub(object, method, visibility, &proc)
      expect(object).to_receive(method)
      stub
    end
def mock object, method, visibility = nil, &proc
      if method.is_a?(Hash)
        proc && raise(ArgumentError, 'Both Hash and block given. Please use either one.')
        method.each_pair {|m,r| mock(object, m, visibility, &proc {r})}
        return MiniSpec::Mocks::HashedStub
      end
      visibility ||= MiniSpec::Utils.method_visibility(object, method) || :public
      # IMPORTANT! stub should be defined before expectation
      stub = stub(object, method, visibility, &proc)
      expect(object).to_receive(method)
      stub
    end
the mock is basically a stub with difference it will also add a expectation.
 that's it, a mock will stub a method on a object and
 will expect that stub to be called before test finished.

 the `mock` method will return the actual stub
 so you can build chained constraints on it.

 @note  if mocked method exists it's visibility will be kept

 @example  make `some_object` to respond to `:some_method`
           and expect `:some_method` to be called before current test finished.
           also make `:some_method` to behave differently depending on given arguments.
           so if called with [:a, :b] arguments it will return 'called with a, b'.
           called with [:x, :y] arguments it will return 'called with x, y'.
           called with any other arguments or without arguments at all it returns 'whatever'.

   mock(some_object, :some_method).
     with(:a, :b) { 'called with a, b' }.
     with(:x, :y) { 'called with x, y' }.
     with_any { 'whatever' }