#!/usr/bin/env node
var assert = require('assert');

var express = require('express');
var request = require('request');
var sugar = require('object-sugar');

var rest = require('../lib/rest-sugar');
var models = require('./models');


main();

function main() {
    var host = 'http://localhost';
    var port = 3000;
    var prefix = '/api/';
    var resource = host + ':' + port + prefix + 'authors';
    var app = express();

    app.configure(function() {
        app.use(express.methodOverride()); // handles PUT
        app.use(express.bodyParser()); // handles POST
        app.use(app.router);
    });

    rest.init(app, prefix, {
        authors: models.Author
    }, sugar); // TODO: add auth and success cbs

    console.log('Running tests!');
    app.listen(port, function(err) {
        if(err) return console.error(err);

        request.get(resource, function(err, d) {
            if(err) return console.error(err);

            var name = 'Joe';

            assert.equal(JSON.parse(d.body).length, 0);

            request.post({url: resource, json: {name: name}}, function(err, r, body) {
                if(err) return console.error(err);

                assert.equal(body.name, name);

                finish();
            });
       });
    });
}

function finish() {
    console.log('Tests finished!');
    process.exit();
}

@@ -723,36 +723,14 @@
     
-console.log('Running tests!'
+start(
 );%0A 
@@ -1245,16 +1245,73 @@
  %7D);%0A%7D%0A%0A
+function start() %7B%0A    console.log('Running tests!');%0A%7D%0A%0A
 function

Tidy up