// test/stubbatti.js

/* global describe, it, afterEach, beforeEach */

'use strict';

var exec = require('child_process').exec;
var expect = require('chai').expect;

var Stubbatti = require('../src/stubbatti.js');

describe('Stubbatti', function () {

    var stubbatti;

    beforeEach(function () {

        stubbatti = new Stubbatti();
        stubbatti.setConsole({log: function () {}});

    });

    afterEach(function (done) {

        stubbatti.stop(function () {

            done();

        });

    });

    describe('register', function () {

        it('registers a response for a path', function (done) {

            stubbatti.register('get', '/hello', 'Hello, world!');

            stubbatti.start(function () {

                exec('curl 0.0.0.0:28987/hello', function (err, stdout, stderr) {

                    expect(stdout).to.equal('Hello, world!');

                    done();

                });

            });
        });
    });

});

@@ -209,16 +209,250 @@
 .js');%0A%0A
+var DEFAULT_HOST = '0.0.0.0:28987';%0A%0A%0A// test utility for get request the server%0Avar get = function (path, cb) %7B%0A%0A    exec('curl ' + DEFAULT_HOST + path, function (error, stdout, stderr) %7B%0A        cb(stdout.toString());%0A    %7D);%0A%0A%7D;%0A%0A%0A
 describe
@@ -979,70 +979,530 @@
     
-exec('curl 0.0.0.0:28987/hello', function (err, stdout, stderr
+get('/hello', function (responseText) %7B%0A%0A                    expect(responseText).to.equal('Hello, world!');%0A%0A                    done();%0A%0A                %7D);%0A%0A            %7D);%0A        %7D);%0A%0A        it('registers a delayed response for a path if delay option is specified', function (done) %7B%0A%0A            stubbatti.register('get', '/delay', 'delayed response', %7Bdelay: 1000%7D);%0A%0A            var startTime = new Date().getTime();%0A%0A            stubbatti.start(function () %7B%0A%0A                get('/delay', function (responseText
 ) %7B%0A
@@ -1529,21 +1529,27 @@
  expect(
-stdou
+responseTex
 t).to.eq
@@ -1549,38 +1549,222 @@
 ).to.equal('
-Hello, world!'
+delayed response');%0A%0A                    var endTime = new Date().getTime();%0A%0A                    var error = Math.abs(startTime + 1000 - endTime);%0A%0A                    expect(error).to.be.below(100
 );%0A%0A        
@@ -1813,32 +1813,33 @@
             %7D);%0A
+%0A
         %7D);%0A    

Add test of delay option