Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/*.sw?
**/node_modules
15 changes: 15 additions & 0 deletions matthew_ringel/README.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions matthew_ringel/greetcl.js
Original file line number Diff line number Diff line change
@@ -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));
14 changes: 14 additions & 0 deletions matthew_ringel/lib/arg_parse.js
Original file line number Diff line number Diff line change
@@ -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
}
};
7 changes: 7 additions & 0 deletions matthew_ringel/lib/greet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

var Greeting = exports = module.exports = function() {
this.greet = function(name) {
return 'hello ' + name;
};
};
12 changes: 12 additions & 0 deletions matthew_ringel/test/greet_test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
17 changes: 17 additions & 0 deletions matthew_ringel/test/parse_test.js
Original file line number Diff line number Diff line change
@@ -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!')
});
});