Skip to content

Commit

Permalink
refactor "forbid pending" tests for DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Dec 7, 2017
1 parent 2dc09bc commit 2f8173a
Showing 1 changed file with 26 additions and 58 deletions.
84 changes: 26 additions & 58 deletions test/integration/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,63 +274,28 @@ describe('options', function () {
});
});

it('fails if there are tests marked skip', function (done) {
run('options/forbid-pending/skip.js', args, function (err, res) {
if (err) {
done(err);
return;
}
assert.equal(res.code, 1);
assert.equal(res.failures[0].err.message, pendingErrorMessage);
done();
});
});

it('fails if there are pending tests', function (done) {
run('options/forbid-pending/pending.js', args, function (err, res) {
if (err) {
done(err);
return;
}
assert.equal(res.code, 1);
assert.equal(res.failures[0].err.message, pendingErrorMessage);
done();
});
});

it('fails if tests call `skip()`', function (done) {
run('options/forbid-pending/this.skip.js', args, function (err, res) {
assert(!err);
assert.equal(res.code, 1);
assert.equal(res.failures[0].err.message, pendingErrorMessage);
done();
});
});

it('fails if beforeEach calls `skip()`', function (done) {
run('options/forbid-pending/beforeEach-this.skip.js', args, function (err, res) {
assert(!err);
assert.equal(res.code, 1);
assert.equal(res.failures[0].err.message, pendingErrorMessage);
done();
});
});

it('fails if before calls `skip()`', function (done) {
run('options/forbid-pending/before-this.skip.js', args, function (err, res) {
assert(!err);
assert.equal(res.code, 1);
assert.equal(res.failures[0].err.message, pendingErrorMessage);
done();
});
});
var forbidPendingFailureTests = {
'fails if there are tests marked skip': 'skip.js',
'fails if there are pending tests': 'pending.js',
'fails if tests call `skip()`': 'this.skip.js',
'fails if beforeEach calls `skip()`': 'beforeEach-this.skip.js',
'fails if before calls `skip()`': 'before-this.skip.js',
'fails if there are tests in suites marked skip': 'skip-suite.js'
};

it('fails if there are tests in suites marked skip', function (done) {
run('options/forbid-pending/skip-suite.js', args, function (err, res) {
assert(!err);
assert.equal(res.code, 1);
assert.equal(res.failures[0].err.message, pendingErrorMessage);
done();
Object.keys(forbidPendingFailureTests).forEach(function (title) {
it(title, function (done) {
run(path.join('options', 'forbid-pending', forbidPendingFailureTests[title]),
args,
function (err, res) {
if (err) {
done(err);
return;
}
assert.equal(res.code, 1);
assert.equal(res.failures[0].err.message, pendingErrorMessage);
done();
});
});
});
});
Expand All @@ -344,7 +309,8 @@ describe('options', function () {
/**
* Returns a test that executes Mocha in a subprocess with either
* `--exit`, `--no-exit`, or default behavior.
* @param {boolean} shouldExit - Expected result; `true` if Mocha should have force-killed the process.
* @param {boolean} shouldExit - Expected result; `true` if Mocha should
* have force-killed the process.
* @param {string} [behavior] - 'enabled' or 'disabled'
* @returns {Function}
*/
Expand Down Expand Up @@ -392,7 +358,9 @@ describe('options', function () {
describe('--help', function () {
it('works despite the presence of mocha.opts', function (done) {
directInvoke(['-h'], function (error, result) {
if (error) { return done(error); }
if (error) {
return done(error);
}
expect(result.output).to.contain('Usage:');
done();
}, path.join(__dirname, 'fixtures', 'options', 'help'));
Expand Down

0 comments on commit 2f8173a

Please sign in to comment.