From 83b11e8f20968af44421028427c75fa5b448b4c2 Mon Sep 17 00:00:00 2001 From: Paul Jensen Date: Tue, 26 May 2015 22:04:36 +0100 Subject: [PATCH] fix(tests): Added some tests for the cli, ported from ss-generator --- package.json | 4 +++- test/unit/cli/index.test.js | 42 +++++++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 3113a55c..b45392be 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "devDependencies": { "connect-livereload": "0.5.2", "coveralls": "2.11.2", + "gently": "^0.9.2", "grunt": "0.4.5", "grunt-cli": "0.1.13", "grunt-concurrent": "1.0.0", @@ -82,7 +83,8 @@ "test-debug": "node_modules/.bin/mocha --debug-brk test/unit/**/* --reporter spec --require should --require sinon" }, "pre-commit": [ - "lint", "quick-test" + "lint", + "quick-test" ], "directories": { "lib": "./lib", diff --git a/test/unit/cli/index.test.js b/test/unit/cli/index.test.js index 35650cc8..28e2d099 100644 --- a/test/unit/cli/index.test.js +++ b/test/unit/cli/index.test.js @@ -4,11 +4,15 @@ // Dependencies // -// var Gently = require('gently'); +var assert = require('assert'); +var Gently = require('gently'); +var generator = require('../../../lib/cli/generate.js'); +var index = require('../../../lib/cli/index.js'); +var gently = new Gently(); -describe('lib/cli/index.js', function () { +describe('/index.js', function () { @@ -18,9 +22,14 @@ describe('lib/cli/index.js', function () { describe('when the 1st argument is n', function () { - it('should call the generator with the program arguments'); - // For this, we stub the generator using Gently, and assert - // that it receives the expected arguments from the CLI module + it('should call the generator with the program arguments', function (done) { + var program = {args: ['n', 'testapp']}; + gently.expect(generator, 'generate', function (receivedProgram) { + assert.deepEqual(program,receivedProgram); + done(); + }); + index.process(program); + }); }); @@ -28,9 +37,14 @@ describe('lib/cli/index.js', function () { describe('when the 1st argument is new', function () { - it('should call the generator with the program arguments'); - // For this, we stub the generator using Gently, and assert - // that it receives the expected arguments from the CLI module + it('should call the generator with the program arguments', function (done) { + var program = {args: ['new', 'testapp']}; + gently.expect(generator, 'generate', function (receivedProgram) { + assert.deepEqual(program,receivedProgram); + done(); + }); + index.process(program); + }); }); @@ -38,8 +52,14 @@ describe('lib/cli/index.js', function () { describe('when the 1st argument is neither "n" or "new"', function () { - it('should inform the user on how to use the application'); - // NOTE - how do we capture this use case? + it('should inform the user on how to use the application', function (done) { + var program = {args: ['create', 'testapp']}; + gently.expect(console, 'log', function (string) { + assert.deepEqual('Type "socketstream new " to create a new application',string); + done(); + }); + index.process(program); + }); }); @@ -49,4 +69,4 @@ describe('lib/cli/index.js', function () { -}); \ No newline at end of file +});