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/.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 new file mode 100644 index 0000000..30ab0db --- /dev/null +++ b/matthew_ringel/README.md @@ -0,0 +1,29 @@ +#Adding a Gulpfile/package.json# +##Matthew Ringel## +##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 + +```node greetcl.js [name]``` + +where [name] is a string. + + +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/greetcl.js b/matthew_ringel/greetcl.js new file mode 100644 index 0000000..5a10142 --- /dev/null +++ b/matthew_ringel/greetcl.js @@ -0,0 +1,9 @@ +'use strict'; + +var Greet = require('./lib/greet'); +var greet = new Greet(); + +var arg_parse = require('./lib/arg_parse.js'); +var nameString = arg_parse.parse(process.argv[2]); + +console.log(greet.greet(nameString)); diff --git a/matthew_ringel/gulpfile.js b/matthew_ringel/gulpfile.js new file mode 100644 index 0000000..5eba4fd --- /dev/null +++ b/matthew_ringel/gulpfile.js @@ -0,0 +1,20 @@ +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']; + +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() { + return gulp.src('./test/greet_test.js', {read: false}) + .pipe(mocha({reporter: 'spec'})); +}); diff --git a/matthew_ringel/lib/arg_parse.js b/matthew_ringel/lib/arg_parse.js new file mode 100644 index 0000000..2438c41 --- /dev/null +++ b/matthew_ringel/lib/arg_parse.js @@ -0,0 +1,14 @@ +'use strict'; + +exports = module.exports = {}; + +exports.parse = function(arg) { + if (typeof arg != 'string') { + // throw "argument is not a string!"; + throw new TypeError('string!'); + // return arg.toString(); + } + else { + return arg; + } +}; diff --git a/matthew_ringel/lib/greet.js b/matthew_ringel/lib/greet.js new file mode 100644 index 0000000..68afe65 --- /dev/null +++ b/matthew_ringel/lib/greet.js @@ -0,0 +1,7 @@ +'use strict'; + +var Greeting = module.exports = exports = function() { + this.greet = function(name) { + return 'hello ' + name; + }; +}; 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" +} 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'); + }); +}); diff --git a/matthew_ringel/test/parse_test.js b/matthew_ringel/test/parse_test.js new file mode 100644 index 0000000..9ef177c --- /dev/null +++ b/matthew_ringel/test/parse_test.js @@ -0,0 +1,17 @@ +'use strict'; + +var chai = require('chai'); +var expect = chai.expect; +var assert = chai.assert; + +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); + assert.throws(arg_parse.parse(0), TypeError, 'string!') + }); +});