Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
test: remove redundant tests
Browse files Browse the repository at this point in the history
They test something already tested and they should actually test the
interplay between 'prompt' and 'applyAnswers' than the 'applyAnswers'
alone. This should be handled by integration tests in the future.
  • Loading branch information
honzajavorek committed Aug 13, 2018
1 parent 5b0510d commit 44fc8a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 124 deletions.
121 changes: 9 additions & 112 deletions test/unit/cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const sinon = require('sinon');
const { assert } = require('chai');

const configUtilsStub = require('../../src/config-utils');
const interactiveConfigStub = require('../../src/interactive-config');
const loggerStub = require('../../src/logger');
const options = require('../../src/options');
const packageData = require('../../package.json');
Expand All @@ -32,11 +31,16 @@ const DreddStub = proxyquire('../../src/dredd', {
'./logger': loggerStub
});

const initStub = sinon.stub().callsFake((config, save, callback) => {
save(config);
callback();
});

const CLIStub = proxyquire('../../src/cli', {
'./dredd': DreddStub,
console: loggerStub,
'./logger': loggerStub,
'./interactive-config': interactiveConfigStub,
'./init': initStub,
'./config-utils': configUtilsStub,
fs: fsStub,
'cross-spawn': crossSpawnStub
Expand Down Expand Up @@ -271,123 +275,17 @@ describe('CLI class', () => {
it('prints out version', () => assert.include(stdout, `${packageData.name} v${packageData.version}`));
});

describe('"init" (nodejs)', () => {
before((done) => {
sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'nodejs' }));
sinon.stub(configUtilsStub, 'save');
execCommand({ argv: ['init'] }, () => done());
});

after(() => {
interactiveConfigStub.run.restore();
configUtilsStub.save.restore();
});

it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called));

it('should save configuration', () => assert.isTrue(configUtilsStub.save.called));
});

describe('"init" (python)', () => {
before((done) => {
sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'python' }));
sinon.stub(configUtilsStub, 'save');
execCommand({ argv: ['init'] }, () => done());
});

after(() => {
interactiveConfigStub.run.restore();
configUtilsStub.save.restore();
});

it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called));

it('should save configuration', () => assert.isTrue(configUtilsStub.save.called));
});


describe('"init" (php)', () => {
before((done) => {
sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'php' }));
sinon.stub(configUtilsStub, 'save');
execCommand({ argv: ['init'] }, () => done());
});

after(() => {
interactiveConfigStub.run.restore();
configUtilsStub.save.restore();
});

it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called));

it('should save configuration', () => assert.isTrue(configUtilsStub.save.called));
});

describe('"init" (ruby)', () => {
describe('init', () => {
before((done) => {
sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'ruby' }));
sinon.stub(configUtilsStub, 'save');
execCommand({ argv: ['init'] }, () => done());
});

after(() => {
interactiveConfigStub.run.restore();
configUtilsStub.save.restore();
});

it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called));

it('should save configuration', () => assert.isTrue(configUtilsStub.save.called));
});

describe('"init" (perl)', () => {
before((done) => {
sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'perl' }));
sinon.stub(configUtilsStub, 'save');
execCommand({ argv: ['init'] }, () => done());
});

after(() => {
interactiveConfigStub.run.restore();
configUtilsStub.save.restore();
});

it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called));

it('should save configuration', () => assert.isTrue(configUtilsStub.save.called));
});

describe('"init" (go)', () => {
before((done) => {
sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'go' }));
sinon.stub(configUtilsStub, 'save');
execCommand({ argv: ['init'] }, () => done());
});

after(() => {
interactiveConfigStub.run.restore();
configUtilsStub.save.restore();
});

it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called));

it('should save configuration', () => assert.isTrue(configUtilsStub.save.called));
});

describe('"init" (rust)', () => {
before((done) => {
sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'rust' }));
sinon.stub(configUtilsStub, 'save');
execCommand({ argv: ['init'] }, () => done());
});

after(() => {
interactiveConfigStub.run.restore();
configUtilsStub.save.restore();
});

it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called));

it('should run interactive config', () => assert.isTrue(initStub.called));
it('should save configuration', () => assert.isTrue(configUtilsStub.save.called));
});

Expand Down Expand Up @@ -418,7 +316,7 @@ describe('CLI class', () => {
cb(null, stats);
});

sinon.stub(interactiveConfigStub, 'run').callsFake((config, cb) => cb());
initStub.callsFake((config, cb) => cb());

sinon.stub(fsStub, 'existsSync').callsFake(() => true);

Expand Down Expand Up @@ -457,7 +355,6 @@ describe('CLI class', () => {
after(() => {
DreddStub.prototype.run.restore();
DreddStub.prototype.init.restore();
interactiveConfigStub.run.restore();
configUtilsStub.load.restore();
fsStub.existsSync.restore();
});
Expand Down
12 changes: 0 additions & 12 deletions test/unit/init/applyAnswers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,10 @@ describe('init._applyAnswers()', () => {
const config = applyAnswers(createConfig(), { apiaryApiKey: '1234' });
assert.equal(config.custom.apiaryApiKey, '1234');
});
it('keeps the Apiary API key if already present in the config', () => {
const config = applyAnswers(Object(createConfig()), {
custom: { apiaryApiKey: '1234' }
});
assert.equal(config.custom.apiaryApiKey, '1234');
});
it('sets the Apiary API name if provided', () => {
const config = applyAnswers(createConfig(), { apiaryApiName: 'myproject' });
assert.equal(config.custom.apiaryApiName, 'myproject');
});
it('keeps the Apiary API name if already present in the config', () => {
const config = applyAnswers(Object(createConfig()), {
custom: { apiaryApiName: 'myproject' }
});
assert.equal(config.custom.apiaryApiName, 'myproject');
});
it('creates selected CI configuration if asked', () => {
applyAnswers(createConfig(), { createCI: 'wercker' }, { ci });
assert.isTrue(ci.wercker.calledOnce);
Expand Down

0 comments on commit 44fc8a8

Please sign in to comment.