text: 'use strict';
  
  exports.__esModule = true;
  exports.createSpy = createSpy;
  exports.spyOn = spyOn;
  exports.isSpy = isSpy;
  exports.restoreSpies = restoreSpies;
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  
  var _assert = require('./assert');
  
  var _assert2 = _interopRequireDefault(_assert);
  
  var _isFunction = require('./isFunction');
  
  var _isFunction2 = _interopRequireDefault(_isFunction);
  
  function noop() {}
  
  var spies = [];
  
  function createSpy(fn) {
    var restore = arguments.length <= 1 || arguments[1] === undefined ? noop : arguments[1];
  
    if (fn == null) fn = noop;
  
    _assert2['default'](_isFunction2['default'](fn), 'createSpy needs a function');
  
    var targetFn = undefined,
        thrownValue = undefined,
        returnValue = undefined;
  
    var spy = function spy() {
      spy.calls.push({
        context: this,
        arguments: Array.prototype.slice.call(arguments, 0)
      });
  
      if (targetFn) return targetFn.apply(this, arguments);
  
      if (thrownValue) throw thrownValue;
  
      return returnValue;
    };
  
    spy.calls = [];
  
    spy.andCall = function (fn) {
      targetFn = fn;
      return spy;
    };
  
    spy.andCallThrough = function () {
      return spy.andCall(fn);
    };
  
    spy.andThrow = function (object) {
      thrownValue = object;
      return spy;
    };
  
    spy.andReturn = function (value) {
      returnValue = value;
      return spy;
    };
  
    spy.getLastCall = function () {
      return spy.calls[spy.calls.length - 1];
    };
  
    spy.restore = spy.destroy = restore;
  
    spy.__isSpy = true;
  
    spies.push(spy);
  
    return spy;
  }
  
  function spyOn(object, methodName) {
    var original = object[methodName];
  
    if (!isSpy(original)) {
      _assert2['default'](_isFunction2['default'](original), 'Cannot spyOn the %s property; it is not a function', methodName);
  
      object[methodName] = createSpy(original, function () {
        object[methodName] = original;
      });
    }
  
    return object[methodName];
  }
  
  function isSpy(object) {
    return object && object.__isSpy === true;
  }
  
  function restoreSpies() {
    for (var i = spies.length - 1; i >= 0; i--) {
      spies[i].restore();
    }spies = [];
  }