From a18540f397ff598e623c507e517493373efb2b6a Mon Sep 17 00:00:00 2001 From: Matthew Ringel Date: Tue, 27 Oct 2015 09:58:52 -0700 Subject: [PATCH 1/8] command line util done --- .gitignore | 1 + matthew_ringel/greetcl.js | 6 ++++++ matthew_ringel/lib/greet.js | 7 +++++++ matthew_ringel/test/greet_test.js | 12 ++++++++++++ 4 files changed, 26 insertions(+) create mode 100644 matthew_ringel/greetcl.js create mode 100644 matthew_ringel/lib/greet.js create mode 100644 matthew_ringel/test/greet_test.js diff --git a/.gitignore b/.gitignore index ab646e2..7ddf381 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ **/*.sw? +**/node_modules diff --git a/matthew_ringel/greetcl.js b/matthew_ringel/greetcl.js new file mode 100644 index 0000000..aa4147a --- /dev/null +++ b/matthew_ringel/greetcl.js @@ -0,0 +1,6 @@ +'use strict'; + +var Greet = require('./lib/greet'); +var greet = new Greet(); + +console.log(greet.greet(process.argv[2])); diff --git a/matthew_ringel/lib/greet.js b/matthew_ringel/lib/greet.js new file mode 100644 index 0000000..c40cc36 --- /dev/null +++ b/matthew_ringel/lib/greet.js @@ -0,0 +1,7 @@ +'use strict'; + +var Greeting = exports = module.exports = function() { + this.greet = function(name) { + return 'hello ' + name; + }; +}; diff --git a/matthew_ringel/test/greet_test.js b/matthew_ringel/test/greet_test.js new file mode 100644 index 0000000..81c711e --- /dev/null +++ b/matthew_ringel/test/greet_test.js @@ -0,0 +1,12 @@ +'use strict'; + +var expect = require('chai').expect; + +var greetConstructor = require(__dirname + '/../lib/greet'); +var greetModule = new greetConstructor(); + +describe('the greet function', function testGreet() { + it('should return hello NAME', function greetExpect() { + expect(greetModule.greet('NAME')).to.eql('hello NAME'); + }); +}); From c8b538f85d1fa45c94d4511e4849b7b2df1d90a2 Mon Sep 17 00:00:00 2001 From: Matthew Ringel Date: Tue, 27 Oct 2015 11:38:01 -0700 Subject: [PATCH 2/8] added readme and partially complete bonus test --- matthew_ringel/README.md | 15 +++++++++++++++ matthew_ringel/lib/arg_parse.js | 12 ++++++++++++ matthew_ringel/test/parse_test.js | 14 ++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 matthew_ringel/README.md create mode 100644 matthew_ringel/lib/arg_parse.js create mode 100644 matthew_ringel/test/parse_test.js diff --git a/matthew_ringel/README.md b/matthew_ringel/README.md new file mode 100644 index 0000000..54db70b --- /dev/null +++ b/matthew_ringel/README.md @@ -0,0 +1,15 @@ +#Simple Test and Modular Pattern Homework Submission# +##Matthew Ringel## +##27 October 2015## + +greet.js is a module that returns an object with a method called greet which takes one argument, expected as a string. Calling the method will output 'hello NAME' where NAME is the string passed as an argument. + +greetcl.js is the command line utility. Usage is + +'''node greetcl.js [name]''' + +where [name] is a string. + + +The test for the part bonus isn't working. The argument parser is set up to throw a TypeError is the given argument is not a string. I tried to set up a test to test for the error using expect(fn).to.throw(TypeError) +but it didn't work. diff --git a/matthew_ringel/lib/arg_parse.js b/matthew_ringel/lib/arg_parse.js new file mode 100644 index 0000000..d41e044 --- /dev/null +++ b/matthew_ringel/lib/arg_parse.js @@ -0,0 +1,12 @@ +'use strict'; + +exports = module.exports = {}; + +exports.parse = function(arg) { + if (typeof arg != 'string') { + throw new TypeError('argument is not a string!'); + } + else { + return arg + } +}; diff --git a/matthew_ringel/test/parse_test.js b/matthew_ringel/test/parse_test.js new file mode 100644 index 0000000..08d5a20 --- /dev/null +++ b/matthew_ringel/test/parse_test.js @@ -0,0 +1,14 @@ +'use strict'; + +var expect = require('chai').expect; + +var arg_parse = require('../lib/arg_parse.js'); + +describe('the parse function', function testParse() { + it('should return a string', function stringExpect() { + expect(arg_parse.parse('NAME')).to.eql('NAME'); + }); + it('should throw an error', function errorExpect() { + expect(arg_parse.parse(0)).to.throw(TypeError); + }); +}); From d8b8eddb8145900778dd8bb7bad2e1d986682fce Mon Sep 17 00:00:00 2001 From: Matthew Ringel Date: Tue, 27 Oct 2015 11:38:32 -0700 Subject: [PATCH 3/8] fixed greetcl.js --- matthew_ringel/greetcl.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/matthew_ringel/greetcl.js b/matthew_ringel/greetcl.js index aa4147a..5a10142 100644 --- a/matthew_ringel/greetcl.js +++ b/matthew_ringel/greetcl.js @@ -3,4 +3,7 @@ var Greet = require('./lib/greet'); var greet = new Greet(); -console.log(greet.greet(process.argv[2])); +var arg_parse = require('./lib/arg_parse.js'); +var nameString = arg_parse.parse(process.argv[2]); + +console.log(greet.greet(nameString)); From 5d3f6678737113138896fbc45b4d90df872a5e9e Mon Sep 17 00:00:00 2001 From: Matthew Ringel Date: Thu, 29 Oct 2015 09:30:50 -0700 Subject: [PATCH 4/8] bonus 2 in progress --- matthew_ringel/lib/arg_parse.js | 4 +++- matthew_ringel/test/parse_test.js | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/matthew_ringel/lib/arg_parse.js b/matthew_ringel/lib/arg_parse.js index d41e044..c2f46ea 100644 --- a/matthew_ringel/lib/arg_parse.js +++ b/matthew_ringel/lib/arg_parse.js @@ -4,7 +4,9 @@ exports = module.exports = {}; exports.parse = function(arg) { if (typeof arg != 'string') { - throw new TypeError('argument is not a string!'); + // throw "argument is not a string!"; + throw new TypeError('string!'); + // return arg.toString(); } else { return arg diff --git a/matthew_ringel/test/parse_test.js b/matthew_ringel/test/parse_test.js index 08d5a20..9ef177c 100644 --- a/matthew_ringel/test/parse_test.js +++ b/matthew_ringel/test/parse_test.js @@ -1,6 +1,8 @@ 'use strict'; -var expect = require('chai').expect; +var chai = require('chai'); +var expect = chai.expect; +var assert = chai.assert; var arg_parse = require('../lib/arg_parse.js'); @@ -9,6 +11,7 @@ describe('the parse function', function testParse() { expect(arg_parse.parse('NAME')).to.eql('NAME'); }); it('should throw an error', function errorExpect() { - expect(arg_parse.parse(0)).to.throw(TypeError); + // expect(arg_parse.parse(0)).to.throw(TypeError); + assert.throws(arg_parse.parse(0), TypeError, 'string!') }); }); From 3d145db1e5c0973ae961e77d8c9832e190029365 Mon Sep 17 00:00:00 2001 From: Matthew Ringel Date: Thu, 29 Oct 2015 09:56:22 -0700 Subject: [PATCH 5/8] first commit, gulp-jshint running --- matthew_ringel/gulpfile.js | 10 ++++++++++ matthew_ringel/lib/arg_parse.js | 2 +- matthew_ringel/package.json | 29 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 matthew_ringel/gulpfile.js create mode 100644 matthew_ringel/package.json diff --git a/matthew_ringel/gulpfile.js b/matthew_ringel/gulpfile.js new file mode 100644 index 0000000..254f231 --- /dev/null +++ b/matthew_ringel/gulpfile.js @@ -0,0 +1,10 @@ +var gulp = require('gulp'); +var jshint = require('gulp-jshint'); +var appFiles = ['index.js', 'lib/**/*.js', 'bin/**/*.js']; +var testFiles = ['./test/**/*.js']; + +gulp.task('jshint', function() { + return gulp.src('./lib/*.js') + .pipe(jshint()) + .pipe(jshint.reporter('default')); +}); diff --git a/matthew_ringel/lib/arg_parse.js b/matthew_ringel/lib/arg_parse.js index c2f46ea..2438c41 100644 --- a/matthew_ringel/lib/arg_parse.js +++ b/matthew_ringel/lib/arg_parse.js @@ -9,6 +9,6 @@ exports.parse = function(arg) { // return arg.toString(); } else { - return arg + return arg; } }; diff --git a/matthew_ringel/package.json b/matthew_ringel/package.json new file mode 100644 index 0000000..57f4d04 --- /dev/null +++ b/matthew_ringel/package.json @@ -0,0 +1,29 @@ +{ + "name": "matthew_ringel_wk1", + "version": "0.1.0", + "description": "greeting module for week one of sea-d45-javascript", + "main": "index.js", + "directories": { + "test": "test" + }, + "dependencies": { + "chai": "^3.4.0" + }, + "devDependencies": { + "gulp-jshint": "^1.11.2", + "gulp-mocha": "^2.1.3" + }, + "scripts": { + "test": "./node_modules/mocha/bin/mocha test" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/mringel/simple-test-and-modular-patterns.git" + }, + "author": "Matthew Ringel", + "license": "MIT", + "bugs": { + "url": "https://github.com/mringel/simple-test-and-modular-patterns/issues" + }, + "homepage": "https://github.com/mringel/simple-test-and-modular-patterns#readme" +} From 3f1221de764cd676027499be7b56b0c9abcd9fba Mon Sep 17 00:00:00 2001 From: Matthew Ringel Date: Thu, 29 Oct 2015 10:33:18 -0700 Subject: [PATCH 6/8] basic jshint and mocha test working through gulp --- matthew_ringel/.jshintrc | 8 ++++++++ matthew_ringel/README.md | 4 ++-- matthew_ringel/gulpfile.js | 6 ++++++ matthew_ringel/lib/greet.js | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 matthew_ringel/.jshintrc diff --git a/matthew_ringel/.jshintrc b/matthew_ringel/.jshintrc new file mode 100644 index 0000000..85864d7 --- /dev/null +++ b/matthew_ringel/.jshintrc @@ -0,0 +1,8 @@ +{ + "node": true, + "globals": { + "exports": true, + "module": true + + } +} diff --git a/matthew_ringel/README.md b/matthew_ringel/README.md index 54db70b..3bceb1a 100644 --- a/matthew_ringel/README.md +++ b/matthew_ringel/README.md @@ -6,10 +6,10 @@ greet.js is a module that returns an object with a method called greet which tak greetcl.js is the command line utility. Usage is -'''node greetcl.js [name]''' +```node greetcl.js [name]``` where [name] is a string. -The test for the part bonus isn't working. The argument parser is set up to throw a TypeError is the given argument is not a string. I tried to set up a test to test for the error using expect(fn).to.throw(TypeError) +The test for the 2nd part bonus isn't working. The argument parser is set up to throw a TypeError if the given argument is not a string. I tried to set up a test to test for the error using expect(fn).to.throw(TypeError) but it didn't work. diff --git a/matthew_ringel/gulpfile.js b/matthew_ringel/gulpfile.js index 254f231..e145327 100644 --- a/matthew_ringel/gulpfile.js +++ b/matthew_ringel/gulpfile.js @@ -1,5 +1,6 @@ var gulp = require('gulp'); var jshint = require('gulp-jshint'); +var mocha = require('gulp-mocha'); var appFiles = ['index.js', 'lib/**/*.js', 'bin/**/*.js']; var testFiles = ['./test/**/*.js']; @@ -8,3 +9,8 @@ gulp.task('jshint', function() { .pipe(jshint()) .pipe(jshint.reporter('default')); }); + +gulp.task('mocha', function() { + return gulp.src('./test/greet_test.js', {read: false}) + .pipe(mocha({reporter: 'spec'})); +}); diff --git a/matthew_ringel/lib/greet.js b/matthew_ringel/lib/greet.js index c40cc36..68afe65 100644 --- a/matthew_ringel/lib/greet.js +++ b/matthew_ringel/lib/greet.js @@ -1,6 +1,6 @@ 'use strict'; -var Greeting = exports = module.exports = function() { +var Greeting = module.exports = exports = function() { this.greet = function(name) { return 'hello ' + name; }; From 6fdf7bba2e33cbccffd4acfdfc31221894f3d453 Mon Sep 17 00:00:00 2001 From: Matthew Ringel Date: Thu, 29 Oct 2015 10:50:33 -0700 Subject: [PATCH 7/8] updated readme and fixed jshint task to run on test code also --- matthew_ringel/README.md | 16 +++++++++++++++- matthew_ringel/gulpfile.js | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/matthew_ringel/README.md b/matthew_ringel/README.md index 3bceb1a..6c2f6ff 100644 --- a/matthew_ringel/README.md +++ b/matthew_ringel/README.md @@ -1,7 +1,21 @@ #Simple Test and Modular Pattern Homework Submission# ##Matthew Ringel## -##27 October 2015## +##28 October 2015## +Added package.json and gulp file. + +The gulpfile contains two tasks: + +gulp jshint will run jshint on all code in the /lib and /test folders. + +gulp mocha will run the tests in the greet_test.js file. I chose not to include the the other test file as that only applied to last assignment's bonus point. + +For this weeks bonus point, I put the jshint options into a .jshintrc file at the root level that can me transfered between projects. + + + + +###27 October 2015### greet.js is a module that returns an object with a method called greet which takes one argument, expected as a string. Calling the method will output 'hello NAME' where NAME is the string passed as an argument. greetcl.js is the command line utility. Usage is diff --git a/matthew_ringel/gulpfile.js b/matthew_ringel/gulpfile.js index e145327..5eba4fd 100644 --- a/matthew_ringel/gulpfile.js +++ b/matthew_ringel/gulpfile.js @@ -8,6 +8,10 @@ gulp.task('jshint', function() { return gulp.src('./lib/*.js') .pipe(jshint()) .pipe(jshint.reporter('default')); + return gulp.src('./test/*.js') + .pipe(jshint()) + .pipe(jshint.reporter('default')); + }); gulp.task('mocha', function() { From 30b44d1ba0ab6d695b064074505ce3dbc66dce74 Mon Sep 17 00:00:00 2001 From: Matthew Ringel Date: Thu, 29 Oct 2015 10:55:39 -0700 Subject: [PATCH 8/8] changed README.md --- matthew_ringel/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matthew_ringel/README.md b/matthew_ringel/README.md index 6c2f6ff..30ab0db 100644 --- a/matthew_ringel/README.md +++ b/matthew_ringel/README.md @@ -1,4 +1,4 @@ -#Simple Test and Modular Pattern Homework Submission# +#Adding a Gulpfile/package.json# ##Matthew Ringel## ##28 October 2015##