From f084871a4440cf00d448d41a5f8b1e2c6a5767e2 Mon Sep 17 00:00:00 2001 From: Honza Javorek Date: Fri, 10 Aug 2018 18:26:56 +0200 Subject: [PATCH] test: update integration tests --- test/unit/cli-test.js | 121 ++++-------------------------------------- 1 file changed, 9 insertions(+), 112 deletions(-) diff --git a/test/unit/cli-test.js b/test/unit/cli-test.js index 59cf87988..aee78c011 100644 --- a/test/unit/cli-test.js +++ b/test/unit/cli-test.js @@ -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'); @@ -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 @@ -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)); }); @@ -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); @@ -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(); });