/*jshint -W030 */
var gremlin = require('../');

describe('.execute()', function() {
  it('should return a result and a response', function(done) {
    var client = gremlin.createClient();

    client.execute('g.V()', function(err, result) {
      (err === null).should.be.true;
      result.length.should.equal(6);
      done();
    });
  });

  it('should queue command before the client is connected', function(done) {
    var client = gremlin.createClient();

    client.execute('g.V()', function() { });
    client.queue.length.should.equal(1);
    done();
  });

  it('should send commands after the client is connected', function(done) {
    var client = gremlin.createClient();

    client.on('connect', function() {
      client.execute('g.V()', function(err, result) {
        (err === null).should.be.true;
        result.length.should.equal(6);
        done();
      });
    });
  });

  it('should handle optional args', function(done) {
    var client = gremlin.createClient();

    client.execute('g.v(1)', null, { args: { language: 'nashorn' }}, function(err, result) {
      (err === null).should.be.true;
      result.length.should.equal(1);
      done();
    });
  });

  it('should handle bindings and optional args', function(done) {
    var client = gremlin.createClient();

    client.execute('g.v(x)', { x: 1 }, { args: { language: 'nashorn' }}, function(err, result) {
      (err === null).should.be.true;
      result.length.should.equal(1);
      done();
    });
  });
});
@@ -78,16 +78,101 @@
 ion() %7B%0A
+  var client;%0A%0A  beforeEach(function() %7B%0A    client = gremlin.createClient();%0A  %7D);%0A%0A
   it('sh
@@ -230,50 +230,8 @@
 ) %7B%0A
-    var client = gremlin.createClient();%0A%0A
     
@@ -462,50 +462,8 @@
 ) %7B%0A
-    var client = gremlin.createClient();%0A%0A
     
@@ -643,50 +643,8 @@
 ) %7B%0A
-    var client = gremlin.createClient();%0A%0A
     
@@ -907,50 +907,8 @@
 ) %7B%0A
-    var client = gremlin.createClient();%0A%0A
     
@@ -1169,50 +1169,8 @@
 ) %7B%0A
-    var client = gremlin.createClient();%0A%0A
     
@@ -1363,12 +1363,250 @@
 );%0A  %7D);
+%0A%0A  it('should handle errors', function(done) %7B%0A    // pass a buggy script (missing parenthese)%0A    var script = 'g.V(';%0A%0A    client.execute(script, function(err, result) %7B%0A      (err === null).should.be.false;%0A      done();%0A    %7D);%0A  %7D);
 %0A%7D);

Add a test checking for errors in execute() mode