Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Minor cleanups #207

Closed
wants to merge 5 commits into from

3 participants

@jlaire

Fix some typos and simplify a few code snippets.

jlaire added some commits
@jlaire jlaire fix a few typos in comments
4f5e1d9
@jlaire jlaire simplify code with ||
0775aa5
@jlaire jlaire make coding style more consistent
This doesn't change semantics, but usually loop variables that are used
in more than one loop seem to be declared before them.
c2a8772
@jlaire jlaire use Array#join instead of String concatenation
d3e4ad1
@jlaire jlaire remove unnecessary conditionals
In code like this:

    if (arr.length > 0) {
      for (var i = 0; i < arr.length; ++i) { ... }
    }

The check is pointless and adds unnecessary indentation.
4c7f9d1
@ragaskar
Owner

Looks good. Can't be auto-merged so it may take a bit before we come back and merge it in. Thanks!

@infews
Owner

If you're still interested in these, can you please re-apply to HEAD? Thanks for your help.

@infews
Owner

Closing due to inactivity.

@infews infews closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 30, 2012
  1. @jlaire

    fix a few typos in comments

    jlaire authored
  2. @jlaire

    simplify code with ||

    jlaire authored
  3. @jlaire

    make coding style more consistent

    jlaire authored
    This doesn't change semantics, but usually loop variables that are used
    in more than one loop seem to be declared before them.
  4. @jlaire
  5. @jlaire

    remove unnecessary conditionals

    jlaire authored
    In code like this:
    
        if (arr.length > 0) {
          for (var i = 0; i < arr.length; ++i) { ... }
        }
    
    The check is pointless and adds unnecessary indentation.
This page is out of date. Refresh to see the latest.
View
8 src/core/Matchers.js
@@ -51,11 +51,9 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
} else {
var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); });
message = "Expected " + jasmine.pp(this.actual) + (this.isNot ? " not " : " ") + englishyPredicate;
- if (matcherArgs.length > 0) {
- for (var i = 0; i < matcherArgs.length; i++) {
- if (i > 0) message += ",";
- message += " " + jasmine.pp(matcherArgs[i]);
- }
+ for (var i = 0; i < matcherArgs.length; i++) {
+ if (i > 0) message += ",";
+ message += " " + jasmine.pp(matcherArgs[i]);
}
message += ".";
}
View
3  src/core/Spec.js
@@ -182,8 +182,9 @@ jasmine.Spec.prototype.execute = function(onComplete) {
jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
var runner = this.env.currentRunner();
var i;
+ var suite;
- for (var suite = this.suite; suite; suite = suite.parentSuite) {
+ for (suite = this.suite; suite; suite = suite.parentSuite) {
for (i = 0; i < suite.before_.length; i++) {
this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this));
}
View
15 src/core/base.js
@@ -79,16 +79,15 @@ jasmine.MessageResult = function(values) {
};
jasmine.MessageResult.prototype.toString = function() {
- var text = "";
+ var strings = [];
for (var i = 0; i < this.values.length; i++) {
- if (i > 0) text += " ";
if (jasmine.isString_(this.values[i])) {
- text += this.values[i];
+ strings.push(this.values[i]);
} else {
- text += jasmine.pp(this.values[i]);
+ strings.push(jasmine.pp(this.values[i]));
}
}
- return text;
+ return strings.join(" ");
};
jasmine.ExpectationResult = function(params) {
@@ -212,7 +211,7 @@ jasmine.objectContaining = function (sample) {
};
/**
- * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks.
+ * Jasmine Spies are test doubles that can act as stubs, spies, fakes, or when used in an expectation, mocks.
*
* Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine
* expectation syntax. Spies can be checked if they were called or not and what the calling params were.
@@ -234,8 +233,8 @@ jasmine.objectContaining = function (sample) {
*
* // actual foo.not will not be called, execution stops
* spyOn(foo, 'not');
-
- // foo.not spied upon, execution will continue to implementation
+ *
+ * // foo.not spied upon, execution will continue to implementation
* spyOn(foo, 'not').andCallThrough();
*
* // fake example
View
32 src/core/mock-timeout.js
@@ -53,24 +53,24 @@ jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMil
}
}
- if (funcsToRun.length > 0) {
- funcsToRun.sort(function(a, b) {
- return a.runAtMillis - b.runAtMillis;
- });
- for (var i = 0; i < funcsToRun.length; ++i) {
- try {
- var funcToRun = funcsToRun[i];
- this.nowMillis = funcToRun.runAtMillis;
- funcToRun.funcToCall();
- if (funcToRun.recurring) {
- this.scheduleFunction(funcToRun.timeoutKey,
- funcToRun.funcToCall,
- funcToRun.millis,
- true);
- }
- } catch(e) {
+ funcsToRun.sort(function(a, b) {
+ return a.runAtMillis - b.runAtMillis;
+ });
+ for (var i = 0; i < funcsToRun.length; ++i) {
+ try {
+ var funcToRun = funcsToRun[i];
+ this.nowMillis = funcToRun.runAtMillis;
+ funcToRun.funcToCall();
+ if (funcToRun.recurring) {
+ this.scheduleFunction(funcToRun.timeoutKey,
+ funcToRun.funcToCall,
+ funcToRun.millis,
+ true);
}
+ } catch(e) {
}
+ }
+ if (funcsToRun.length > 0) {
this.runFunctionsWithinRange(oldMillis, nowMillis);
}
};
View
20 src/core/util.js
@@ -4,7 +4,7 @@
jasmine.util = {};
/**
- * Declare that a child class inherit it's prototype from the parent class.
+ * Declare that a child class inherit its prototype from the parent class.
*
* @private
* @param {Function} childClass
@@ -21,22 +21,8 @@ jasmine.util.inherit = function(childClass, parentClass) {
};
jasmine.util.formatException = function(e) {
- var lineNumber;
- if (e.line) {
- lineNumber = e.line;
- }
- else if (e.lineNumber) {
- lineNumber = e.lineNumber;
- }
-
- var file;
-
- if (e.sourceURL) {
- file = e.sourceURL;
- }
- else if (e.fileName) {
- file = e.fileName;
- }
+ var lineNumber e.line || e.lineNumber;
+ var file = e.sourceURL || e.fileName;
var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString();
Something went wrong with that request. Please try again.