Permalink
Browse files

Unit tests taking shape!

  • Loading branch information...
arthurakay committed Apr 26, 2013
1 parent 471c083 commit f3025af68cafa449ab99a6e2f8fb24da3954337f
Showing with 157 additions and 8 deletions.
  1. +2 −1 .gitignore
  2. +1 −1 docs/output/LintRoller.js
  3. +1 −1 docs/source/LintRoller.html
  4. +8 −1 hooks/pre-commit
  5. +145 −4 tests/specs/LintRoller.js
View
@@ -1,4 +1,5 @@
/.idea
*.log
.DS_Store
-node_modules/
+node_modules/
+hooks/test_errors.txt

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -41,7 +41,7 @@
</span> * @class LintRoller
* @author Arthur Kay (http://www.akawebdesign.com)
* @singleton
- * @version 2.2.5
+ * @version 2.3
*
* GitHub Project: http://arthurakay.github.com/LintRoller/
*/
View
@@ -4,7 +4,12 @@ clear
### Check for errors; abandon the process if error exist
function checkError {
+ COLOR='\033[01;31m' # bold red
+ RESET='\033[00;00m' # normal white
+
if [[ $1 != 0 ]] ; then
+ echo "${COLOR}An error has been encountered. Please check the error logs.${RESET}"
+
#prevent commit with error code
exit 99
fi
@@ -15,8 +20,10 @@ node hooks/check-lint.js
checkError $?
echo "*** Running Jasmine Tests... ***"
-node tests/specs.js
+node tests/specs.js > hooks/test_errors.txt
checkError $?
+rm hooks/test_errors.txt
+
### Exit successfully
exit 0
View
@@ -1,11 +1,152 @@
-/*global describe : false, it : false, expect : false */
+/*global describe, it, expect, beforeEach, afterEach, spyOn */
"use strict";
-var LintRoller = require('../../src/LintRoller');
-describe('LintRoller', function() {
+describe('LintRoller', function () {
+ var LintRoller;
- it('should pass this sanity test', function() {
+ //SETUP / TEARDOWN
+
+ beforeEach(function () {
+ LintRoller = require('../../src/LintRoller');
+ });
+
+ afterEach(function () {
+ LintRoller = null;
+ });
+
+ //SPECS
+
+ it('should pass this sanity test', function () {
expect(LintRoller).toNotEqual(undefined);
});
+ describe('init()', function () {
+ //TODO: can a useful test be written?
+ });
+
+ describe('initConfigs()', function () {
+
+ afterEach(function () {
+ LintRoller.verbose = true;
+ LintRoller.linters = [];
+ LintRoller.logFile = {
+ name : 'error_log.txt',
+ type : 'text'
+ };
+ });
+
+ it('should assign generic configs to LintRoller', function () {
+ expect(LintRoller.verbose).toEqual(true);
+
+ LintRoller.initConfigs({ verbose : false });
+ expect(LintRoller.verbose).toEqual(false);
+ });
+
+ it('should call setLinters() for the "linters" config', function () {
+ expect(LintRoller.linters).toEqual([]);
+
+ spyOn(LintRoller, 'setLinters');
+ var spy = LintRoller.setLinters;
+
+ var linters = [ { type : 'esprima' } ];
+ LintRoller.initConfigs({ linters : linters });
+
+ expect(spy).toHaveBeenCalled();
+ });
+
+ it('should only assign "name" and "type" properties to the "logFile" config', function () {
+ expect(typeof LintRoller.logFile).toEqual('object');
+
+ LintRoller.initConfigs({
+ logFile : {
+ name : 'test.txt',
+ type : 'json',
+ foo : 'bar'
+ }
+ });
+
+ expect(LintRoller.logFile.name).toEqual('test.txt');
+ expect(LintRoller.logFile.type).toEqual('json');
+ expect(LintRoller.logFile.foo).toEqual(undefined);
+ });
+
+ });
+
+ describe('setLinters()', function () {
+ it('should apply the appropriate linters to LintRoller', function () {
+ expect(LintRoller.linters).toEqual([]);
+
+ var linters = [ { type : 'esprima' } ];
+ LintRoller.setLinters(linters);
+
+ expect(LintRoller.linters.length).toEqual(1);
+ expect(LintRoller.linters[0].name).toEqual('esprima');
+ });
+ });
+
+ describe('announceErrors()', function () {
+ //TODO: can a useful test be written?
+ });
+
+ describe('announceSuccess()', function () {
+ //TODO: can a useful test be written?
+ });
+
+ describe('getFiles()', function () {
+ //This method just returns the result of fs.readdirSync() and logs output to the terminal
+ //I probably don't need to test this
+ });
+
+ describe('parseTree()', function () {
+
+ });
+
+ describe('lintFiles()', function () {
+ //TODO: can a useful test be written? Or do we simply test the ACTUAL linters?
+ });
+
+ describe('logToFile()', function () {
+ //TODO: can a useful test be written?
+ });
+
+ describe('formatTextOutput()', function () {
+
+ });
+
+ describe('clearLogFile()', function () {
+ //TODO: can a useful test be written?
+ });
+
+ describe('log()', function () {
+
+ it('should default to VERBOSE being true', function () {
+ expect(LintRoller.verbose).toEqual(true);
+ });
+
+ it('should only log to console when VERBOSE is true or OVERRIDE is true', function () {
+ spyOn(console, 'log');
+ var spy = console.log;
+ expect(spy.callCount).toEqual(0);
+
+ //true, false (YES)
+ LintRoller.log('test', false);
+ expect(spy.callCount).toEqual(1);
+
+ //true, true (YES)
+ LintRoller.log('test', true);
+ expect(spy.callCount).toEqual(2);
+
+ LintRoller.verbose = false;
+
+ //false, false (NO)
+ LintRoller.log('test', false);
+ expect(spy.callCount).toEqual(2);
+
+ //false, true (YES)
+ LintRoller.log('test', true);
+ expect(spy.callCount).toEqual(3);
+ });
+
+ });
+
});

0 comments on commit f3025af

Please sign in to comment.