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
36 changes: 36 additions & 0 deletions lab-ron-dunphy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
![CF](assets/shield-32x32.png) Lab 01: Modular Patterns and Testing
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rubiksron no need to include this README in your PR

===

##To Submit this Assignment
* fork this repository
* write all of your code in a directory named `lab-` + `<your name>` **e.g.** `lab-duncan`
* push to your repository
* submit a pull request to this repository
* submit a link to your PR in canvas
* write a question and observation on canvas

## Resources
* [Node assert docs](https://nodejs.org/dist/latest-v4.x/docs/api/assert.html)
* [Mocha docs](http://mochajs.org/#getting-started)

##Description:
This assignment will have you create a simple Javascript object that will be exported using the Node modular pattern we went over in class.

Your object should have a function named 'greet' that takes a name as a parameter and returns the string 'hello ' + name

You should have at least one test that verifies the output of the function.

Your code should pass the **.eslintrc** included in this repository.

Your submission should be a link to your pull request.

##Bonus:
For an extra point, create a command line utility that will be run using node greet.js 'some name' and will pass the input contained in that argument to the greet function and output the result to the screen.

For a second bonus point, write a test that makes sure that the arguments are being processed.

##Rubric:
* Proper Styling: 2pts
* Proper Submission: 2pts
* mocha/assert Test: 3pts
* Use of Modular Pattern/design of greet object/function: 3pts
12 changes: 12 additions & 0 deletions lab-ron-dunphy/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const greet = require('../lib/greet.js');
const assert = require('assert');


describe('testing greet module', function(){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rubiksron best practice is to include an additional describe block, inside of this one, that includes the method name - your outer describe block should reference the module that you are testing.

For example:

describe('ModuleName', function() {
  describe('#methodName', function() {
    it('should do stuff', function() {
      // assertion testing goes here
    });
  });
});

it('should return Ron', function(){
var result = greet('Ron');
assert.equal(result, 'hello Ron', 'expected "hello Ron"');
});
});
23 changes: 23 additions & 0 deletions lab-ron-dunphy/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const gulp = require('gulp');
const eslint = require('gulp-eslint');
const mocha = require('gulp-mocha');

gulp.task('test', function(){
gulp.src('./test/*-test.js', {read: false})
.pipe(mocha({reporter: 'nyan'}));
});

gulp.task('lint', function(){
return gulp.src(['**/*.js','!node_modules/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('dev', function(){
gulp.watch(['**/*.js','!node_modules/**'], ['lint', 'test']);
});

gulp.task('default', ['dev']);
6 changes: 6 additions & 0 deletions lab-ron-dunphy/lib/greet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = function(name) {
if (!name) throw new Error('expected name');
return `hello ${name}`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rubiksron great use of string interpolation here!

};
21 changes: 21 additions & 0 deletions lab-ron-dunphy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "lab-ron-dunphy",
"version": "1.0.0",
"description": "![CF](assets/shield-32x32.png) Lab 01: Modular Patterns and Testing ===",
"main": "app.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
"gulp-mocha": "^3.0.1",
"mocha": "^3.0.2"
}
}
17 changes: 17 additions & 0 deletions lab-ron-dunphy/test/greet-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const greet = require('../lib/greet');
const assert = require('assert');

describe('testing module greet', function(){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rubiksron Same goes here, with regards to your single describe block. Feel free to reference my comment above for additional info.

it('should return hello Ron', function(){
let result = greet('Ron');
assert.ok(result === 'hello Ron', 'was not hello Ron');
});

it('should throw a missing a name error', function(){
assert.throws(function(){
greet();
}, 'should have thrown that err');
});
});