var fs = require('fs'),
    path = require('path'),
    assert = require('assert');

describe('new', function () {

    beforeEach(function (done) {
        var scenario = this;
        process.chdir(scenario.workDir);
        done();
    });
    afterEach(function (done) {
        var scenario = this;
        process.chdir(scenario.here);
        done();
    });

    it('Create a new project.', function (done) {
        var scenario = this,
            commands = scenario.commands,
            workDir = scenario.workDir;
        commands.new('TheWorld', {}, function (err) {
            assert.ifError(err);
            var projectDir = path.resolve(workDir, 'TheWorld');
            scenario.projectDir = projectDir;
            fs.exists(projectDir, function (exists) {
                assert.ok(exists);
                var apemanfile = path.resolve(projectDir, 'Apemanfile.js');
                fs.exists(apemanfile, function (exists) {
                    assert.ok(exists);
                    done();
                });
            });
        });
    });

    it('Try to create duplicate project.', function (done) {
        var _log = console.log;
        console.log = function () {

        };
        var scenario = this,
            commands = scenario.commands;
        commands.new('TheWorld', {}, function (err) {
            assert.ok(err);
            console.log = _log;
            done();
        });
    });

    it('Try to create duplicate project with force option.', function (done) {
        var scenario = this,
            commands = scenario.commands;
        commands.new('TheWorld', {force: true}, function (err) {
            assert.ifError(err);
            done();
        });
    });


});