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) { ...@@ -243,6 +243,21 @@ Casper.prototype.base64encode = function base64encode(url, method, data) {
243 }; 243 };
244 244
245 /** 245 /**
246 * Bypasses `nb` steps.
247 *
248 * @param Integer nb Number of steps to bypass
249 */
250 Casper.prototype.bypass = function bypass(nb) {
251 "use strict";
252 var step = this.step,
253 steps = this.steps,
254 last = steps.length;
255 this.checkStarted();
256 this.step = Math.min(step + nb, last);
257 return this;
258 };
259
260 /**
246 * Proxy method for WebPage#render. Adds a clipRect parameter for 261 * Proxy method for WebPage#render. Adds a clipRect parameter for
247 * automatically set page clipRect setting values and sets it back once 262 * automatically set page clipRect setting values and sets it back once
248 * done. If the cliprect parameter is omitted, the full page viewport 263 * done. If the cliprect parameter is omitted, the full page viewport
...@@ -1608,72 +1623,50 @@ Casper.prototype.thenOpen = function thenOpen(location, settings, then) { ...@@ -1608,72 +1623,50 @@ Casper.prototype.thenOpen = function thenOpen(location, settings, then) {
1608 }; 1623 };
1609 1624
1610 /** 1625 /**
1611 * Skip `nb` steps. 1626 * Adds a step which bypasses `nb` steps.
1612 * 1627 *
1613 * @param Integer nb number of tests to skip 1628 * @param Integer nb Number of steps to bypass
1614 * @param String message message to display
1615 */ 1629 */
1616 Casper.prototype.skip = function skip(nb, message) { 1630 Casper.prototype.thenBypass = function thenBypass(nb) {
1617 "use strict"; 1631 return this.then(function _thenBypass() {
1618 var step = this.step, 1632 this.bypass(nb);
1619 steps = this.steps,
1620 last = steps.length;
1621
1622 this.checkStarted();
1623 this.step = Math.min(step + nb, last);
1624
1625 return this;
1626 };
1627
1628 /**
1629 * Skip `nb` steps.
1630 *
1631 * @param Integer nb number of tests to skip
1632 * @param String message message to display
1633 */
1634 Casper.prototype.thenSkip = function (nb, message) {
1635 return this.then(function () {
1636 this.skip(nb, message);
1637 }); 1633 });
1638 }; 1634 };
1639 1635
1640 /** 1636 /**
1641 * Skip `nb` steps if condition is true. 1637 * Bypass `nb` steps if condition is true.
1642 * 1638 *
1643 * @param Mixed condition number of tests to skip 1639 * @param Mixed condition Test condition
1644 * @param Integer nb number of tests to skip 1640 * @param Integer nb Number of steps to bypass
1645 * @param String message message to display
1646 */ 1641 */
1647 Casper.prototype.thenSkipIf = function (condition, nb, message) { 1642 Casper.prototype.thenBypassIf = function thenBypassIf(condition, nb) {
1648 return this.then(function () { 1643 return this.then(function _thenBypassIf() {
1649 if (utils.isFunction(condition)) { 1644 if (utils.isFunction(condition)) {
1650 condition = condition(); 1645 condition = condition.call(this);
1651 } 1646 }
1652 if (utils.isTruthy(condition)) { 1647 if (utils.isTruthy(condition)) {
1653 this.skip(nb, message); 1648 this.bypass(nb);
1654 } 1649 }
1655 }); 1650 });
1656 }; 1651 };
1657 1652
1658 /** 1653 /**
1659 * Skip `nb` steps if condition is true. 1654 * Bypass `nb` steps if condition is true.
1660 * 1655 *
1661 * @param Mixed condition number of tests to skip 1656 * @param Mixed condition Test condition
1662 * @param Integer nb number of tests to skip 1657 * @param Integer nb Number of tests to bypass
1663 * @param String message message to display
1664 */ 1658 */
1665 Casper.prototype.thenSkipUnless = function (condition, nb, message) { 1659 Casper.prototype.thenBypassUnless = function thenBypassUnless(condition, nb) {
1666 return this.then(function () { 1660 return this.then(function _thenBypassUnless() {
1667 if (utils.isFunction(condition)) { 1661 if (utils.isFunction(condition)) {
1668 condition = condition(); 1662 condition = condition.call(this);
1669 } 1663 }
1670 if (utils.isFalsy(condition)) { 1664 if (utils.isFalsy(condition)) {
1671 this.skip(nb, message); 1665 this.bypass(nb);
1672 } 1666 }
1673 }); 1667 });
1674 }; 1668 };
1675 1669
1676
1677 /** 1670 /**
1678 * Adds a new navigation step for opening and evaluate an expression 1671 * Adds a new navigation step for opening and evaluate an expression
1679 * against the DOM retrieved from the provided location. 1672 * against the DOM retrieved from the provided location.
......
...@@ -236,14 +236,12 @@ Tester.prototype.abort = function abort(message) { ...@@ -236,14 +236,12 @@ Tester.prototype.abort = function abort(message) {
236 /** 236 /**
237 * Skip `nb` tests. 237 * Skip `nb` tests.
238 * 238 *
239 * @param Integer nb number of tests to skip 239 * @param Integer nb Number of tests to skip
240 * @param String message message to display 240 * @param String message Message to display
241 */ 241 */
242 Tester.prototype.skip = function skip(nb, message) { 242 Tester.prototype.skip = function skip(nb, message) {
243 "use strict"; 243 "use strict";
244 244 this.casper.bypass(nb);
245 this.casper.skip(nb, message);
246
247 return this.processAssertionResult({ 245 return this.processAssertionResult({
248 success: null, 246 success: null,
249 standard: f("Skipping %d tests", nb), 247 standard: f("Skipping %d tests", nb),
......
1 /*global casper*/
2 /*jshint strict:false*/
3 casper.test.begin('Casper.bypass() can bypass a step', 1, function(test) {
4 casper.start();
5 casper.then(function(){
6 test.fail("This test should not be executed.");
7 });
8 casper.bypass(1).run(function() {
9 test.pass("Step has been bypassed");
10 test.done();
11 });
12 });
13
14 casper.test.begin('Casper.bypass() can bypass multiple steps', 1, function(test) {
15 casper.start();
16 casper.then(function() {
17 test.pass("This test should be executed.");
18 });
19 casper.then(function() {
20 this.bypass(2);
21 });
22 casper.then(function() {
23 test.fail("This test should not be executed.");
24 });
25 casper.then(function() {
26 test.fail("Nor this one.");
27 });
28 casper.run(function() {
29 test.done();
30 });
31 });
32
33 casper.test.begin('Casper.thenBypass()', 1, function(test) {
34 casper.
35 thenBypass(1).
36 then(function() {
37 test.fail("This test should be bypassed.");
38 }).
39 then(function() {
40 test.pass("This test should be executed.");
41 });
42
43 casper.run(function() {
44 test.done();
45 });
46 });
47
48 casper.test.begin('Casper.thenBypassIf()', 3, function(test) {
49 casper.
50 thenBypassIf(true, 1, "Bypass if with function").
51 then(function() {
52 test.fail("This test should be bypassed.");
53 }).
54 then(function() {
55 test.pass("This test should be executed.");
56 }).
57 thenBypassIf(function() {
58 return true;
59 }, 1, "Bypass if with function").
60 then(function() {
61 test.fail("This test should be bypassed.");
62 }).
63 then(function() {
64 test.pass("This test should be executed.");
65 }).
66 thenBypassIf(function() {
67 return false;
68 }, 1, "Do not bypass if with function").
69 then(function() {
70 test.pass("This test should be executed.");
71 });
72
73 casper.run(function() {
74 test.done();
75 });
76 });
77
78 casper.test.begin('Casper.thenBypassUnless()', 3, function(test) {
79 casper.
80 thenBypassUnless(false, 1, "Bypass unless with function").
81 then(function() {
82 test.fail("This test should be bypassed.");
83 }).
84 then(function() {
85 test.pass("This test should be executed.");
86 }).
87 thenBypassUnless(function() {
88 return false;
89 }, 1, "Bypass unless with function").
90 then(function() {
91 test.fail("This test should be bypassed.");
92 }).
93 then(function() {
94 test.pass("This test should be executed.");
95 }).
96 thenBypassUnless(function() {
97 return true;
98 }, 1, "Do not bypass unless with function").
99 then(function() {
100 test.pass("This test should be executed.");
101 });
102
103 casper.run(function() {
104 test.done();
105 });
106 });
107
...@@ -40,99 +40,21 @@ casper.test.begin('Skip multiple', 1, function(test) { ...@@ -40,99 +40,21 @@ casper.test.begin('Skip multiple', 1, function(test) {
40 }); 40 });
41 41
42 casper.test.begin('Skip more than there is', 0, function(test) { 42 casper.test.begin('Skip more than there is', 0, function(test) {
43 casper. 43 casper.then(function () {
44 then(function () { 44 test.skip(2);
45 test.skip(2);
46 });
47
48 casper.run(function() {
49 test.done();
50 }); 45 });
51 });
52
53 casper.test.begin('Skip does not polluate next suite', 1, function(test) {
54 casper.
55 then(function () {
56 test.pass("This test should be executed.");
57 });
58 46
59 casper.run(function() { 47 casper.run(function() {
60 test.done(); 48 test.done();
61 }); 49 });
62 }); 50 });
63 51
64 casper.test.begin('Casper.thenSkip', 1, function(test) { 52 casper.test.begin('Skip does not polluate next suite', 1, function(test) {
65 casper. 53 casper.then(function () {
66 thenSkip(1). 54 test.pass("This test should be executed.");
67 then(function () {
68 test.fail("This test should be skipped.");
69 }).
70 then(function () {
71 test.pass("This test should be executed.");
72 });
73
74 casper.run(function() {
75 test.done();
76 });
77 });
78
79 casper.test.begin('Casper.thenSkipIf', 3, function(test) {
80 casper.
81 thenSkipIf(true, 1, "Skip if with function").
82 then(function () {
83 test.fail("This test should be skipped.");
84 }).
85 then(function () {
86 test.pass("This test should be executed.");
87 }).
88 thenSkipIf(function () {
89 return true;
90 }, 1, "Skip if with function").
91 then(function () {
92 test.fail("This test should be skipped.");
93 }).
94 then(function () {
95 test.pass("This test should be executed.");
96 }).
97 thenSkipIf(function () {
98 return false;
99 }, 1, "Do not skip if with function").
100 then(function () {
101 test.pass("This test should be executed.");
102 });
103
104 casper.run(function() {
105 test.done();
106 }); 55 });
107 });
108
109 casper.test.begin('Casper.thenSkipUnless', 3, function(test) {
110 casper.
111 thenSkipUnless(false, 1, "Skip unless with function").
112 then(function () {
113 test.fail("This test should be skipped.");
114 }).
115 then(function () {
116 test.pass("This test should be executed.");
117 }).
118 thenSkipUnless(function () {
119 return false;
120 }, 1, "Skip unless with function").
121 then(function () {
122 test.fail("This test should be skipped.");
123 }).
124 then(function () {
125 test.pass("This test should be executed.");
126 }).
127 thenSkipUnless(function () {
128 return true;
129 }, 1, "Do not skip unless with function").
130 then(function () {
131 test.pass("This test should be executed.");
132 });
133 56
134 casper.run(function() { 57 casper.run(function() {
135 test.done(); 58 test.done();
136 }); 59 });
137 }); 60 });
138
......