Commit 939cee41 939cee41e064228da303669b42e46e197277d35f by Nicolas Perriault

refs #405 - renamed Casper#skip to #bypass

1 parent 653867b3
......@@ -243,6 +243,21 @@ Casper.prototype.base64encode = function base64encode(url, method, data) {
};
/**
* Bypasses `nb` steps.
*
* @param Integer nb Number of steps to bypass
*/
Casper.prototype.bypass = function bypass(nb) {
"use strict";
var step = this.step,
steps = this.steps,
last = steps.length;
this.checkStarted();
this.step = Math.min(step + nb, last);
return this;
};
/**
* Proxy method for WebPage#render. Adds a clipRect parameter for
* automatically set page clipRect setting values and sets it back once
* done. If the cliprect parameter is omitted, the full page viewport
......@@ -1608,72 +1623,50 @@ Casper.prototype.thenOpen = function thenOpen(location, settings, then) {
};
/**
* Skip `nb` steps.
* Adds a step which bypasses `nb` steps.
*
* @param Integer nb number of tests to skip
* @param String message message to display
* @param Integer nb Number of steps to bypass
*/
Casper.prototype.skip = function skip(nb, message) {
"use strict";
var step = this.step,
steps = this.steps,
last = steps.length;
this.checkStarted();
this.step = Math.min(step + nb, last);
return this;
};
/**
* Skip `nb` steps.
*
* @param Integer nb number of tests to skip
* @param String message message to display
*/
Casper.prototype.thenSkip = function (nb, message) {
return this.then(function () {
this.skip(nb, message);
Casper.prototype.thenBypass = function thenBypass(nb) {
return this.then(function _thenBypass() {
this.bypass(nb);
});
};
/**
* Skip `nb` steps if condition is true.
* Bypass `nb` steps if condition is true.
*
* @param Mixed condition number of tests to skip
* @param Integer nb number of tests to skip
* @param String message message to display
* @param Mixed condition Test condition
* @param Integer nb Number of steps to bypass
*/
Casper.prototype.thenSkipIf = function (condition, nb, message) {
return this.then(function () {
Casper.prototype.thenBypassIf = function thenBypassIf(condition, nb) {
return this.then(function _thenBypassIf() {
if (utils.isFunction(condition)) {
condition = condition();
condition = condition.call(this);
}
if (utils.isTruthy(condition)) {
this.skip(nb, message);
this.bypass(nb);
}
});
};
/**
* Skip `nb` steps if condition is true.
* Bypass `nb` steps if condition is true.
*
* @param Mixed condition number of tests to skip
* @param Integer nb number of tests to skip
* @param String message message to display
* @param Mixed condition Test condition
* @param Integer nb Number of tests to bypass
*/
Casper.prototype.thenSkipUnless = function (condition, nb, message) {
return this.then(function () {
Casper.prototype.thenBypassUnless = function thenBypassUnless(condition, nb) {
return this.then(function _thenBypassUnless() {
if (utils.isFunction(condition)) {
condition = condition();
condition = condition.call(this);
}
if (utils.isFalsy(condition)) {
this.skip(nb, message);
this.bypass(nb);
}
});
};
/**
* Adds a new navigation step for opening and evaluate an expression
* against the DOM retrieved from the provided location.
......
......@@ -236,14 +236,12 @@ Tester.prototype.abort = function abort(message) {
/**
* Skip `nb` tests.
*
* @param Integer nb number of tests to skip
* @param String message message to display
* @param Integer nb Number of tests to skip
* @param String message Message to display
*/
Tester.prototype.skip = function skip(nb, message) {
"use strict";
this.casper.skip(nb, message);
this.casper.bypass(nb);
return this.processAssertionResult({
success: null,
standard: f("Skipping %d tests", nb),
......
/*global casper*/
/*jshint strict:false*/
casper.test.begin('Casper.bypass() can bypass a step', 1, function(test) {
casper.start();
casper.then(function(){
test.fail("This test should not be executed.");
});
casper.bypass(1).run(function() {
test.pass("Step has been bypassed");
test.done();
});
});
casper.test.begin('Casper.bypass() can bypass multiple steps', 1, function(test) {
casper.start();
casper.then(function() {
test.pass("This test should be executed.");
});
casper.then(function() {
this.bypass(2);
});
casper.then(function() {
test.fail("This test should not be executed.");
});
casper.then(function() {
test.fail("Nor this one.");
});
casper.run(function() {
test.done();
});
});
casper.test.begin('Casper.thenBypass()', 1, function(test) {
casper.
thenBypass(1).
then(function() {
test.fail("This test should be bypassed.");
}).
then(function() {
test.pass("This test should be executed.");
});
casper.run(function() {
test.done();
});
});
casper.test.begin('Casper.thenBypassIf()', 3, function(test) {
casper.
thenBypassIf(true, 1, "Bypass if with function").
then(function() {
test.fail("This test should be bypassed.");
}).
then(function() {
test.pass("This test should be executed.");
}).
thenBypassIf(function() {
return true;
}, 1, "Bypass if with function").
then(function() {
test.fail("This test should be bypassed.");
}).
then(function() {
test.pass("This test should be executed.");
}).
thenBypassIf(function() {
return false;
}, 1, "Do not bypass if with function").
then(function() {
test.pass("This test should be executed.");
});
casper.run(function() {
test.done();
});
});
casper.test.begin('Casper.thenBypassUnless()', 3, function(test) {
casper.
thenBypassUnless(false, 1, "Bypass unless with function").
then(function() {
test.fail("This test should be bypassed.");
}).
then(function() {
test.pass("This test should be executed.");
}).
thenBypassUnless(function() {
return false;
}, 1, "Bypass unless with function").
then(function() {
test.fail("This test should be bypassed.");
}).
then(function() {
test.pass("This test should be executed.");
}).
thenBypassUnless(function() {
return true;
}, 1, "Do not bypass unless with function").
then(function() {
test.pass("This test should be executed.");
});
casper.run(function() {
test.done();
});
});
......@@ -40,99 +40,21 @@ casper.test.begin('Skip multiple', 1, function(test) {
});
casper.test.begin('Skip more than there is', 0, function(test) {
casper.
then(function () {
test.skip(2);
});
casper.run(function() {
test.done();
casper.then(function () {
test.skip(2);
});
});
casper.test.begin('Skip does not polluate next suite', 1, function(test) {
casper.
then(function () {
test.pass("This test should be executed.");
});
casper.run(function() {
test.done();
});
});
casper.test.begin('Casper.thenSkip', 1, function(test) {
casper.
thenSkip(1).
then(function () {
test.fail("This test should be skipped.");
}).
then(function () {
test.pass("This test should be executed.");
});
casper.run(function() {
test.done();
});
});
casper.test.begin('Casper.thenSkipIf', 3, function(test) {
casper.
thenSkipIf(true, 1, "Skip if with function").
then(function () {
test.fail("This test should be skipped.");
}).
then(function () {
test.pass("This test should be executed.");
}).
thenSkipIf(function () {
return true;
}, 1, "Skip if with function").
then(function () {
test.fail("This test should be skipped.");
}).
then(function () {
test.pass("This test should be executed.");
}).
thenSkipIf(function () {
return false;
}, 1, "Do not skip if with function").
then(function () {
test.pass("This test should be executed.");
});
casper.run(function() {
test.done();
casper.test.begin('Skip does not polluate next suite', 1, function(test) {
casper.then(function () {
test.pass("This test should be executed.");
});
});
casper.test.begin('Casper.thenSkipUnless', 3, function(test) {
casper.
thenSkipUnless(false, 1, "Skip unless with function").
then(function () {
test.fail("This test should be skipped.");
}).
then(function () {
test.pass("This test should be executed.");
}).
thenSkipUnless(function () {
return false;
}, 1, "Skip unless with function").
then(function () {
test.fail("This test should be skipped.");
}).
then(function () {
test.pass("This test should be executed.");
}).
thenSkipUnless(function () {
return true;
}, 1, "Do not skip unless with function").
then(function () {
test.pass("This test should be executed.");
});
casper.run(function() {
test.done();
});
});
......