forked from stonegao/inspec
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored to meet serverJs Securable Module specificationy
- Loading branch information
Showing
63 changed files
with
1,553 additions
and
22,965 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env narwhal | ||
|
||
var File = system.fs; | ||
var currentPath = File.cwd(); | ||
var specPath = File.join(currentPath, 'spec'); | ||
|
||
Inspec = require('inspec'); | ||
|
||
function getAllSpecFiles(baseDir) { | ||
if(File.exists(baseDir) && File.isDirectory(baseDir)){ | ||
var all = File.list(baseDir); | ||
var dirs = []; | ||
var specFiles = []; | ||
|
||
// stash all the dirs and find all spec files | ||
for(var i=0; i< all.length; i++){ | ||
var loc = File.join(baseDir, all[i]); | ||
if(File.isDirectory(loc)){ | ||
dirs.push(loc); | ||
} else if(/Spec[.]js$/.test(all[i])){ | ||
specFiles.push(loc); | ||
} | ||
} | ||
|
||
// go through each dirs and concat all spec files | ||
for(var i=0; i< dirs.length; i++){ | ||
specFiles = specFiles.concat(getAllSpecFiles(dirs[i])); | ||
} | ||
|
||
return specFiles; | ||
} | ||
} | ||
|
||
var files = getAllSpecFiles(specPath); | ||
|
||
|
||
|
||
Inspec | ||
.load(files) | ||
.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
(function(){var mod=function(require, exports){var Inspec = exports; | ||
Inspec.dsl = require("./inspec/dsl").dsl; | ||
Inspec.util = require("./inspec/util").util; | ||
Inspec.Matchers = require("./inspec/matchers").matchers; | ||
Inspec.exceptions = require("./inspec/exceptions").exceptions; | ||
|
||
Inspec.Environment = require("./inspec/environment").Environment; | ||
Inspec.RhinoEnvironment = require("./inspec/environments/rhinoEnvironment").RhinoEnvironment; | ||
|
||
Inspec.Reporter = require("./inspec/reporter").Reporter; | ||
Inspec.ConsoleReporter = require("./inspec/reporters/consoleReporter").ConsoleReporter; | ||
|
||
Inspec.Class = require("./inspec/class").Class; | ||
Inspec.TreeNode = require("./inspec/treeNode").TreeNode; | ||
Inspec.Behavior = require("./inspec/behavior").Behavior; | ||
Inspec.Example = require("./inspec/example").Example; | ||
Inspec.ExampleGroup = require("./inspec/exampleGroup").ExampleGroup; | ||
Inspec.ExampleGroupManager = require("./inspec/exampleGroupManager").ExampleGroupManager; | ||
Inspec.Runner = require("./inspec/runner").Runner; | ||
Inspec.Expectation = require("./inspec/expectation").Expectation; | ||
|
||
|
||
Inspec.defaultOptions = require("./inspec/defaultOptions").defaultOptions; | ||
|
||
Inspec.load = function(){ | ||
var files = []; | ||
while(arguments.length){ | ||
var temp = Array.prototype.shift.call(arguments); | ||
if(temp.length && temp.length > 0){ | ||
files = files.concat(temp); | ||
} else if(typeof temp == "string"){ | ||
files.push(temp); | ||
} | ||
} | ||
var env = Inspec.Environment.getInstance(); | ||
for(var i=0; i< files.length; i++){ | ||
env.load(files[i]); | ||
} | ||
return this; | ||
}; | ||
|
||
Inspec.run = function(){ | ||
var env = Inspec.Environment.getInstance(); | ||
env.run(); | ||
} | ||
};require.install ? require.install('Inspec',mod) : mod(require, exports);})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(function(){var mod=function(require, exports){ | ||
|
||
var TreeNode = require('./treeNode').TreeNode; | ||
var Environment = require('./environment').Environment; | ||
|
||
var Behavior = TreeNode.extend({ | ||
init : function(description){ | ||
this._super(description, []); | ||
}, | ||
|
||
getExampleGroup : function(index){ | ||
return this.getExampleGroups()[index]; | ||
}, | ||
|
||
addExampleGroup : function(exampleGroup){ | ||
exampleGroup.setBehavior(this); | ||
return this.getExampleGroups().push(exampleGroup); | ||
} | ||
}); | ||
|
||
Behavior.prototype.getExampleGroups = Behavior.prototype.getContent; | ||
Behavior.prototype.getDescription = Behavior.prototype.getName; | ||
|
||
Behavior.current = function(){ | ||
return Environment.getInstance().getExampleGroupManager().currentBehavior; | ||
}; | ||
|
||
exports.Behavior = Behavior; | ||
|
||
};require.install ? require.install('Inspec',mod) : mod(require, exports);})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
(function(){var mod=function(require, exports){ | ||
|
||
/** | ||
* @class Base class to emulate classical class-based OOP | ||
*/ | ||
var Class = function() {}; | ||
var _initializing = false; | ||
var _fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; | ||
|
||
/** | ||
* @param {object} base Base class to be extended | ||
* @return {Class} Extended class instance | ||
*/ | ||
Class.extend = function(base) { | ||
// Inspired by http://ejohn.org/blog/simple-javascript-inheritance/ | ||
var _super = this.prototype; | ||
|
||
_initializing = true; | ||
var prototype = new this(); | ||
_initializing = false; | ||
|
||
for(var name in base) { | ||
prototype[name] = typeof base[name] == 'function' && | ||
typeof _super[name] == 'function' && _fnTest.test(base[name]) ? | ||
(function(name, fn){ | ||
return function() { | ||
var tmp = this._super; | ||
this._super = _super[name]; | ||
var ret = fn.apply(this, arguments); | ||
this._super = tmp; | ||
return ret; | ||
}; | ||
})(name, base[name]) : | ||
base[name]; | ||
} | ||
|
||
function Class() { | ||
if (!_initializing && this.init) | ||
this.init.apply(this, arguments); | ||
} | ||
|
||
Class.prototype = prototype; | ||
Class.constructor = Class; | ||
Class.extend = arguments.callee; | ||
|
||
return Class; | ||
}; | ||
|
||
exports.Class = Class; | ||
|
||
};require.install ? require.install('Inspec',mod) : mod(require, exports);})(); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(function(){var mod=function(require, exports){ | ||
var dsl = {}; | ||
dsl.BDD = require('./dsl/bdd').BDD; | ||
|
||
exports.dsl = dsl; | ||
};require.install ? require.install('Inspec.dsl',mod) : mod(require, exports);})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(function(){var mod=function(require, exports){ | ||
|
||
var ExampleGroup = require('../exampleGroup').ExampleGroup; | ||
var Example = require('../example').Example; | ||
var BDD = {}; | ||
|
||
BDD.describe = function(description, implementation){ | ||
ExampleGroup.createExampleGroup(description, implementation); | ||
}; | ||
|
||
BDD.shareExamplesFor = function(description, implementation){ | ||
ExampleGroup.createExampleGroup(description, implementation, {shared : true}); | ||
}; | ||
|
||
BDD.it = function(description, implementation){ | ||
Example.createExample(description, implementation); | ||
}; | ||
|
||
BDD.beforeEach = function(implementation){ | ||
ExampleGroup.addBeforeEach(implementation); | ||
}; | ||
|
||
BDD.afterEach = function(implementation){ | ||
ExampleGroup.addAfterEach(implementation); | ||
}; | ||
|
||
BDD.beforeAll = function(implementation){ | ||
ExampleGroup.addBeforeAll(implementation); | ||
}; | ||
|
||
BDD.afterAll = function(implementation){ | ||
ExampleGroup.addAfterAll(implementation); | ||
}; | ||
|
||
// alias | ||
BDD.context = BDD.describe; | ||
BDD.sharedExamplesFor = BDD.shareExamplesFor; | ||
|
||
exports.BDD = BDD; | ||
};require.install ? require.install('Inspec.dsl.BDD',mod) : mod(require, exports);})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
(function(){var mod=function(require, exports){ | ||
|
||
var Class = require('./class').Class; | ||
var Messenger = require('./util/messenger').Messenger; | ||
var ExampleGroupManager = require('./exampleGroupManager').ExampleGroupManager; | ||
var Runner = require('./runner').Runner; | ||
var createImplementation = require('./util/misc').createImplementation; | ||
var NotImplemented = require('./exceptions').exceptions.NotImplemented; | ||
var UnkownEnvironment = require('./exceptions').exceptions.UnkownEnvironment; | ||
|
||
var Environment = Class.extend({ | ||
init : function(){ | ||
this.initFacility(); | ||
}, | ||
|
||
initFacility : function(){ | ||
this.messenger = new Messenger(); | ||
this.exampleGroupManager = new ExampleGroupManager(); | ||
var reporter = this.reporterClass(); | ||
this.reporter = new reporter(this.messenger); | ||
this.runner = new Runner(this.exampleGroupManager.behaviorRoot, this.exampleGroupManager.exampleGroupRoot, this.messenger); | ||
}, | ||
|
||
getExampleGroupManager : function(){ | ||
return this.exampleGroupManager; | ||
}, | ||
|
||
getMessenger : function(){ | ||
return this.messenger; | ||
}, | ||
|
||
getReporter : function(){ | ||
return this.reporter; | ||
}, | ||
|
||
getRunner : function(){ | ||
return this.runner; | ||
}, | ||
|
||
run : function(){ | ||
this.runner.execute(); | ||
}, | ||
|
||
load : function(location){ | ||
var fn = createImplementation(this.loadFile(location)); | ||
var matchers = require('./matchers').matchers; | ||
var bdd = require('./dsl/bdd').BDD; | ||
|
||
fn.call({}, bdd, matchers); | ||
}, | ||
|
||
reporterClass : function(){ | ||
throw new NotImplemented(); | ||
}, | ||
|
||
loadFile : function(location){ | ||
throw new NotImplemented(); | ||
}, | ||
|
||
log : function(msg){ | ||
throw new NotImplemented(); | ||
} | ||
}); | ||
|
||
var _instance = null; | ||
|
||
Environment.getInstance = function(){ | ||
if(typeof _instance === "undefined" || _instance === null){ | ||
var env; | ||
|
||
if( typeof navigator !== "undefined" && navigator !== null ) | ||
env = require('./environments/browserEnvironment').BrowserEnvironment; | ||
else if(typeof load !== "undefined" && load !== null ) | ||
env = require('./environments/rhinoEnvironment').RhinoEnvironment; | ||
else if(typeof WScript !== "undefined" && WScript !== null) | ||
env = require('./environments/wscriptEnvironment').WScriptEnvironment; | ||
else | ||
throw new UnkownEnvironment(); | ||
|
||
_instance = new env(); | ||
|
||
} | ||
return _instance; | ||
}; | ||
|
||
exports.Environment = Environment; | ||
|
||
};require.install ? require.install('Inspec',mod) : mod(require, exports);})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(function(){var mod=function(require, exports){ | ||
|
||
var Environment = require('../environment').Environment; | ||
var ConsoleReporter = require('../reporters/consoleReporter').ConsoleReporter; | ||
|
||
var RhinoEnvironment = Environment.extend({ | ||
reporterClass : function(){ | ||
return ConsoleReporter; | ||
}, | ||
|
||
loadFile : function(location){ | ||
return readFile(location); | ||
}, | ||
|
||
log : function(msg){ | ||
print(msg); | ||
} | ||
}); | ||
|
||
exports.RhinoEnvironment = RhinoEnvironment; | ||
|
||
};require.install ? require.install('Inspec',mod) : mod(require, exports);})(); |
Oops, something went wrong.