Skip to content

Commit

Permalink
Refactored to meet serverJs Securable Module specificationy
Browse files Browse the repository at this point in the history
  • Loading branch information
aq1018 committed May 26, 2009
1 parent bbfba56 commit 99ac3a5
Show file tree
Hide file tree
Showing 63 changed files with 1,553 additions and 22,965 deletions.
40 changes: 40 additions & 0 deletions bin/inspec
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();
43 changes: 0 additions & 43 deletions jake.yml

This file was deleted.

46 changes: 46 additions & 0 deletions lib/inspec.js
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);})();
30 changes: 30 additions & 0 deletions lib/inspec/behavior.js
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);})();
51 changes: 51 additions & 0 deletions lib/inspec/class.js
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 added lib/inspec/defaultOptions.js
Empty file.
6 changes: 6 additions & 0 deletions lib/inspec/dsl.js
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);})();
40 changes: 40 additions & 0 deletions lib/inspec/dsl/bdd.js
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);})();
88 changes: 88 additions & 0 deletions lib/inspec/environment.js
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);})();
22 changes: 22 additions & 0 deletions lib/inspec/environments/rhinoEnvironment.js
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);})();
Loading

0 comments on commit 99ac3a5

Please sign in to comment.