Skip to content

Commit

Permalink
text fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
gravitezero committed Aug 27, 2012
1 parent 4d1c6d7 commit a18e357
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/main.js
Expand Up @@ -27,7 +27,7 @@ module.exports = function(scope, name){
};

this._cb_final = function() {
this._needs_done = true;
//this._needs_done = true;
if(this._callback) {
this._callback.apply(this._scope, this.result);
this._done = true;
Expand Down Expand Up @@ -109,7 +109,7 @@ module.exports = function(scope, name){

this.then = function(cb) {
this._callback = cb || function(){};
if(this._needs_done)
if (this._counter === 0)//if(this._needs_done)
this._cb_final();
return this;
};
Expand Down
69 changes: 56 additions & 13 deletions test/main.js
Expand Up @@ -17,6 +17,29 @@ describe('Sozu', function() {
});
});

it('should be executed after one synchrone needs', function(done) {
var proof = false;
var test = new sozu(this).

needs(function(){
proof = true
}).

then(function(results){
proof.should.equal(true);
done();
});
});

it('should`nt need needs', function(done) {
var proof = false;
var test = new sozu(this).

then(function(){
done();
});
});

it('should be executed after one synchrone needs', function(done) {
var proof = false;
var fn = function(callback, msg){
Expand Down Expand Up @@ -78,15 +101,12 @@ describe('Sozu', function() {
then(function(){
for(var index in arguments){
for(var arg in args) {
//cb index, results
if(arguments[index] [1] === args[arg])
//cb index, results
if(arguments[index].results === args[arg])
proof += 1;
}
}

// TODO this :
//arguments.should.include()

proof.should.equal(3);
done();
});
Expand All @@ -109,8 +129,8 @@ describe('Sozu', function() {
then(function(){
for(var index in arguments){
for(var arg in args) {
//cb index, args, first argument
if(arguments[index] [0] [0] === args[arg])
//cb index, arguments,first argument
if(arguments[index].arguments[0] === args[arg])
proof += 1;
}
}
Expand All @@ -134,11 +154,10 @@ describe('Sozu', function() {
}, 10, args[4], args[5]).

then(function(){
//console.log(arguments);
for(var index in arguments){
for(var arg_index in arguments[index]) {
for(var arg_index in arguments[index].arguments) {
for(var arg in args) {
if(arguments[index][0][arg_index] === args[arg])
if(arguments[index].arguments[arg_index] === args[arg])
proof += 1;
}
}
Expand All @@ -163,7 +182,7 @@ describe('Sozu', function() {
then(function(){
for(var index in arguments){
for(var arg in args) {
if(arguments[index][0][0] === args[arg])
if(arguments[index].arguments[0] === args[arg])
proof += 1;
}
}
Expand All @@ -185,7 +204,7 @@ describe('Sozu', function() {
then(function(){
for(var index in arguments){
for(var arg in args) {
if(arguments[index][0][0] === args[arg]) {
if(arguments[index].arguments[0] === args[arg]) {
proof += 1;
}
}
Expand All @@ -203,7 +222,7 @@ describe('Sozu', function() {
then(function(){
for(var index in arguments){
for(var arg in args) {
if(arguments[index][0][0] === args[arg]) {
if(arguments[index].arguments[0] === args[arg]) {
proof += 1;
}

Expand All @@ -213,4 +232,28 @@ describe('Sozu', function() {
done();
});
});

it('should be able to iterate a needs over an array', function(done) {
var proof = 0;
var args = ['tartiflette', 'raclette', 'flammenküche', 'panini', 'kebab', 'tacos'];
var test = new sozu(this).

needsEach(args,setTimeout,function(arg){
var fn = function(){
return arg;
};
return [fn, 10];
}).

then(function(){
for(var index in arguments){
for(var arg in args) {
if(arguments[index].results === args[arg])
proof += 1;
}
}
proof.should.equal(6);
done();
});
});
});

0 comments on commit a18e357

Please sign in to comment.