Вход Регистрация
Файл: framework/thirdparty/jasmine/src/Spec.js
Строк: 310
<?php
/**
 * Internal representation of a Jasmine specification, or test.
 *
 * @constructor
 * @param {jasmine.Env} env
 * @param {jasmine.Suite} suite
 * @param {String} description
 */
jasmine.Spec = function(envsuitedescription) {
  if (!
env) {
    throw new 
Error('jasmine.Env() required');
  }
  if (!
suite) {
    throw new 
Error('jasmine.Suite() required');
  }
  var 
spec this;
  
spec.id env.nextSpecId env.nextSpecId() : null;
  
spec.env env;
  
spec.suite suite;
  
spec.description description;
  
spec.queue = new jasmine.Queue(env);

  
spec.afterCallbacks = [];
  
spec.spies_ = [];

  
spec.results_ = new jasmine.NestedResults();
  
spec.results_.description description;
  
spec.matchersClass null;
};

jasmine.Spec.prototype.getFullName = function() {
  return 
this.suite.getFullName() + ' ' this.description '.';
};


jasmine.Spec.prototype.results = function() {
  return 
this.results_;
};

/**
 * All parameters are pretty-printed and concatenated together, then written to the spec's output.
 *
 * Be careful not to leave calls to <code>jasmine.log</code> in production code.
 */
jasmine.Spec.prototype.log = function() {
  return 
this.results_.log(arguments);
};

jasmine.Spec.prototype.runs = function (func) {
  var 
block = new jasmine.Block(this.envfuncthis);
  
this.addToQueue(block);
  return 
this;
};

jasmine.Spec.prototype.addToQueue = function (block) {
  if (
this.queue.isRunning()) {
    
this.queue.insertNext(block);
  } else {
    
this.queue.add(block);
  }
};

/**
 * @param {jasmine.ExpectationResult} result
 */
jasmine.Spec.prototype.addMatcherResult = function(result) {
  
this.results_.addResult(result);
};

jasmine.Spec.prototype.expect = function(actual) {
  var 
positive = new (this.getMatchersClass_())(this.envactualthis);
  
positive.not = new (this.getMatchersClass_())(this.envactualthistrue);
  return 
positive;
};

/**
 * Waits a fixed time period before moving to the next block.
 *
 * @deprecated Use waitsFor() instead
 * @param {Number} timeout milliseconds to wait
 */
jasmine.Spec.prototype.waits = function(timeout) {
  var 
waitsFunc = new jasmine.WaitsBlock(this.envtimeoutthis);
  
this.addToQueue(waitsFunc);
  return 
this;
};

/**
 * Waits for the latchFunction to return true before proceeding to the next block.
 *
 * @param {Function} latchFunction
 * @param {String} optional_timeoutMessage
 * @param {Number} optional_timeout
 */
jasmine.Spec.prototype.waitsFor = function(latchFunctionoptional_timeoutMessageoptional_timeout) {
  var 
latchFunction_ null;
  var 
optional_timeoutMessage_ null;
  var 
optional_timeout_ null;

  for (var 
0arguments.lengthi++) {
    var 
arg arguments[i];
    switch (
typeof arg) {
      case 
'function':
        
latchFunction_ arg;
        break;
      case 
'string':
        
optional_timeoutMessage_ arg;
        break;
      case 
'number':
        
optional_timeout_ arg;
        break;
    }
  }

  var 
waitsForFunc = new jasmine.WaitsForBlock(this.envoptional_timeout_latchFunction_optional_timeoutMessage_this);
  
this.addToQueue(waitsForFunc);
  return 
this;
};

jasmine.Spec.prototype.fail = function (e) {
  var 
expectationResult = new jasmine.ExpectationResult({
    
passedfalse,
    
messagejasmine.util.formatException(e) : 'Exception'
  
});
  
this.results_.addResult(expectationResult);
};

jasmine.Spec.prototype.getMatchersClass_ = function() {
  return 
this.matchersClass || this.env.matchersClass;
};

jasmine.Spec.prototype.addMatchers = function(matchersPrototype) {
  var 
parent this.getMatchersClass_();
  var 
newMatchersClass = function() {
    
parent.apply(thisarguments);
  };
  
jasmine.util.inherit(newMatchersClassparent);
  
jasmine.Matchers.wrapInto_(matchersPrototypenewMatchersClass);
  
this.matchersClass newMatchersClass;
};

jasmine.Spec.prototype.finishCallback = function() {
  
this.env.reporter.reportSpecResults(this);
};

jasmine.Spec.prototype.finish = function(onComplete) {
  
this.removeAllSpies();
  
this.finishCallback();
  if (
onComplete) {
    
onComplete();
  }
};

jasmine.Spec.prototype.after = function(doAfter) {
  if (
this.queue.isRunning()) {
    
this.queue.add(new jasmine.Block(this.envdoAfterthis));
  } else {
    
this.afterCallbacks.unshift(doAfter);
  }
};

jasmine.Spec.prototype.execute = function(onComplete) {
  var 
spec this;
  if (!
spec.env.specFilter(spec)) {
    
spec.results_.skipped true;
    
spec.finish(onComplete);
    return;
  }

  
this.env.reporter.reportSpecStarting(this);

  
spec.env.currentSpec spec;

  
spec.addBeforesAndAftersToQueue();

  
spec.queue.start(function () {
    
spec.finish(onComplete);
  });
};

jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
  var 
runner this.env.currentRunner();
  var 
i;

  for (var 
suite this.suitesuitesuite suite.parentSuite) {
    for (
0suite.before_.lengthi++) {
      
this.queue.addBefore(new jasmine.Block(this.envsuite.before_[i], this));
    }
  }
  for (
0runner.before_.lengthi++) {
    
this.queue.addBefore(new jasmine.Block(this.envrunner.before_[i], this));
  }
  for (
0this.afterCallbacks.lengthi++) {
    
this.queue.add(new jasmine.Block(this.envthis.afterCallbacks[i], this));
  }
  for (
suite this.suitesuitesuite suite.parentSuite) {
    for (
0suite.after_.lengthi++) {
      
this.queue.add(new jasmine.Block(this.envsuite.after_[i], this));
    }
  }
  for (
0runner.after_.lengthi++) {
    
this.queue.add(new jasmine.Block(this.envrunner.after_[i], this));
  }
};

jasmine.Spec.prototype.explodes = function() {
  throw 
'explodes function should not have been called';
};

jasmine.Spec.prototype.spyOn = function(objmethodNameignoreMethodDoesntExist) {
  if (
obj == jasmine.undefined) {
    throw 
"spyOn could not find an object to spy upon for " methodName "()";
  }

  if (!
ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) {
    throw 
methodName '() method does not exist';
  }

  if (!
ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) {
    throw new 
Error(methodName ' has already been spied upon');
  }

  var 
spyObj jasmine.createSpy(methodName);

  
this.spies_.push(spyObj);
  
spyObj.baseObj obj;
  
spyObj.methodName methodName;
  
spyObj.originalValue obj[methodName];

  
obj[methodName] = spyObj;

  return 
spyObj;
};

jasmine.Spec.prototype.removeAllSpies = function() {
  for (var 
0this.spies_.lengthi++) {
    var 
spy this.spies_[i];
    
spy.baseObj[spy.methodName] = spy.originalValue;
  }
  
this.spies_ = [];
};
?>
Онлайн: 0
Реклама