Вход Регистрация
Файл: framework/thirdparty/jasmine/src/Env.js
Строк: 381
<?php
/**
 * Environment for Jasmine
 *
 * @constructor
 */
jasmine.Env = function() {
  
this.currentSpec null;
  
this.currentSuite null;
  
this.currentRunner_ = new jasmine.Runner(this);

  
this.reporter = new jasmine.MultiReporter();

  
this.updateInterval jasmine.DEFAULT_UPDATE_INTERVAL;
  
this.defaultTimeoutInterval jasmine.DEFAULT_TIMEOUT_INTERVAL;
  
this.lastUpdate 0;
  
this.specFilter = function() {
    return 
true;
  };

  
this.nextSpecId_ 0;
  
this.nextSuiteId_ 0;
  
this.equalityTesters_ = [];

  
// wrap matchers
  
this.matchersClass = function() {
    
jasmine.Matchers.apply(thisarguments);
  };
  
jasmine.util.inherit(this.matchersClassjasmine.Matchers);

  
jasmine.Matchers.wrapInto_(jasmine.Matchers.prototypethis.matchersClass);
};


jasmine.Env.prototype.setTimeout jasmine.setTimeout;
jasmine.Env.prototype.clearTimeout jasmine.clearTimeout;
jasmine.Env.prototype.setInterval jasmine.setInterval;
jasmine.Env.prototype.clearInterval jasmine.clearInterval;

/**
 * @returns an object containing jasmine version build info, if set.
 */
jasmine.Env.prototype.version = function () {
  if (
jasmine.version_) {
    return 
jasmine.version_;
  } else {
    throw new 
Error('Version not set');
  }
};

/**
 * @returns string containing jasmine version build info, if set.
 */
jasmine.Env.prototype.versionString = function() {
  if (
jasmine.version_) {
    var 
version this.version();
    return 
version.major "." version.minor "." version.build " revision " version.revision;
  } else {
    return 
"version unknown";
  }
};

/**
 * @returns a sequential integer starting at 0
 */
jasmine.Env.prototype.nextSpecId = function () {
  return 
this.nextSpecId_++;
};

/**
 * @returns a sequential integer starting at 0
 */
jasmine.Env.prototype.nextSuiteId = function () {
  return 
this.nextSuiteId_++;
};

/**
 * Register a reporter to receive status updates from Jasmine.
 * @param {jasmine.Reporter} reporter An object which will receive status updates.
 */
jasmine.Env.prototype.addReporter = function(reporter) {
  
this.reporter.addReporter(reporter);
};

jasmine.Env.prototype.execute = function() {
  
this.currentRunner_.execute();
};

jasmine.Env.prototype.describe = function(descriptionspecDefinitions) {
  var 
suite = new jasmine.Suite(thisdescriptionspecDefinitionsthis.currentSuite);

  var 
parentSuite this.currentSuite;
  if (
parentSuite) {
    
parentSuite.add(suite);
  } else {
    
this.currentRunner_.add(suite);
  }

  
this.currentSuite suite;

  var 
declarationError null;
  try {
    
specDefinitions.call(suite);
  } catch(
e) {
    
declarationError e;
  }

  
this.currentSuite parentSuite;

  if (
declarationError) {
    
this.it("encountered a declaration exception", function() {
      throw 
declarationError;
    });
  }

  return 
suite;
};

jasmine.Env.prototype.beforeEach = function(beforeEachFunction) {
  if (
this.currentSuite) {
    
this.currentSuite.beforeEach(beforeEachFunction);
  } else {
    
this.currentRunner_.beforeEach(beforeEachFunction);
  }
};

jasmine.Env.prototype.currentRunner = function () {
  return 
this.currentRunner_;
};

jasmine.Env.prototype.afterEach = function(afterEachFunction) {
  if (
this.currentSuite) {
    
this.currentSuite.afterEach(afterEachFunction);
  } else {
    
this.currentRunner_.afterEach(afterEachFunction);
  }

};

jasmine.Env.prototype.xdescribe = function(descspecDefinitions) {
  return {
    
execute: function() {
    }
  };
};

jasmine.Env.prototype.it = function(descriptionfunc) {
  var 
spec = new jasmine.Spec(thisthis.currentSuitedescription);
  
this.currentSuite.add(spec);
  
this.currentSpec spec;

  if (
func) {
    
spec.runs(func);
  }

  return 
spec;
};

jasmine.Env.prototype.xit = function(descfunc) {
  return {
    
idthis.nextSpecId(),
    
runs: function() {
    }
  };
};

jasmine.Env.prototype.compareObjects_ = function(abmismatchKeysmismatchValues) {
  if (
a.__Jasmine_been_here_before__ === && b.__Jasmine_been_here_before__ === a) {
    return 
true;
  }

  
a.__Jasmine_been_here_before__ b;
  
b.__Jasmine_been_here_before__ a;

  var 
hasKey = function(objkeyName) {
    return 
obj != null && obj[keyName] !== jasmine.undefined;
  };

  for (var 
property in b) {
    if (!
hasKey(aproperty) && hasKey(bproperty)) {
      
mismatchKeys.push("expected has key '" property "', but missing from actual.");
    }
  }
  for (
property in a) {
    if (!
hasKey(bproperty) && hasKey(aproperty)) {
      
mismatchKeys.push("expected missing key '" property "', but present in actual.");
    }
  }
  for (
property in b) {
    if (
property == '__Jasmine_been_here_before__') continue;
    if (!
this.equals_(a[property], b[property], mismatchKeysmismatchValues)) {
      
mismatchValues.push("'" property "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual.");
    }
  }

  if (
jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) {
    
mismatchValues.push("arrays were not the same length");
  }

  
delete a.__Jasmine_been_here_before__;
  
delete b.__Jasmine_been_here_before__;
  return (
mismatchKeys.length == && mismatchValues.length == 0);
};

jasmine.Env.prototype.equals_ = function(abmismatchKeysmismatchValues) {
  
mismatchKeys mismatchKeys || [];
  
mismatchValues mismatchValues || [];

  for (var 
0this.equalityTesters_.lengthi++) {
    var 
equalityTester this.equalityTesters_[i];
    var 
result equalityTester(abthismismatchKeysmismatchValues);
    if (
result !== jasmine.undefined) return result;
  }

  if (
=== b) return true;

  if (
=== jasmine.undefined || === null || === jasmine.undefined || === null) {
    return (
== jasmine.undefined && == jasmine.undefined);
  }

  if (
jasmine.isDomNode(a) && jasmine.isDomNode(b)) {
    return 
=== b;
  }

  if (
instanceof Date && instanceof Date) {
    return 
a.getTime() == b.getTime();
  }

  if (
instanceof jasmine.Matchers.Any) {
    return 
a.matches(b);
  }

  if (
instanceof jasmine.Matchers.Any) {
    return 
b.matches(a);
  }

  if (
jasmine.isString_(a) && jasmine.isString_(b)) {
    return (
== b);
  }

  if (
jasmine.isNumber_(a) && jasmine.isNumber_(b)) {
    return (
== b);
  }

  if (
typeof a === "object" && typeof b === "object") {
    return 
this.compareObjects_(abmismatchKeysmismatchValues);
  }

  
//Straight check
  
return (=== b);
};

jasmine.Env.prototype.contains_ = function(haystackneedle) {
  if (
jasmine.isArray_(haystack)) {
    for (var 
0haystack.lengthi++) {
      if (
this.equals_(haystack[i], needle)) return true;
    }
    return 
false;
  }
  return 
haystack.indexOf(needle) >= 0;
};

jasmine.Env.prototype.addEqualityTester = function(equalityTester) {
  
this.equalityTesters_.push(equalityTester);
};
?>
Онлайн: 1
Реклама