// matter.js
//

'use strict';

var pkg = require('../package.json');
var tempDir = require('./lib/TempDir');

var os = require('os');
var path = require('path');

var expect = require('chai').expect;
var nock = require('nock');
var uuid = require('node-uuid');

nock.disableNetConnect();

// Set a unique temporary location.
tempDir.tmpLocation = path.join(os.tmpdir(), 'collider-cli-tests', uuid.v4());

// TESTS
//

before('prepare', function () {
  tempDir.prepare();
});

describe('collider', function () {

  it('should show a usage format when passed no args.', function () {
    var result = tempDir.collider();

    // TO DO:
    // Look into why exit code (1) is being
    // routed to STDOUT rather than STDERR.
    var text = result.stdout.toString();

    expect(text).to.contain('usage:');
    expect(text).to.not.contain('options:');
  });

  it('should show current version when passed "--version"', function () {
    var result = tempDir.collider(['--version']);
    var text   = result.stdout.toString();

    expect(text).to.contain(pkg.version);
  });

  it('should show help information when passed "--help"', function () {
    var result = tempDir.collider(['--help']);
    var text   = result.stdout.toString();

    expect(text).to.contain('options:');
    expect(text).to.contain('commands:');
  });

  it('should exit with an error when passed an undefined command', function () {
    var result = tempDir.collider(['undefined']);
    var text   = result.stderr.toString();

    expect(result.status).to.not.equal(0);
    expect(text).to.contain('Error:');
  });

  // `new` command
  //

  describe('new', function () {

    it('should create a new project', function () {

      // Intercept following HTTP request with a mocked
      // response and expected successful file payload.
      nock('http://getcollider.com')
        .get('/latest.tar.gz')
        .replyWithFile(200, 'assets/latest.tar.gz');

      tempDir.runCmd('new', ['test-project'], function () {
        var project = tempDir.readJson('test-project/project/.collider');

        expect(project.name).to.equal('test-project');
        expect(project.author).to.equal('unknown');
      });
    });

    it('should create a new project with an attributed author', function () {

      // Intercept following HTTP request with a mocked
      // response and expected successful file payload.
      nock('http://getcollider.com')
        .get('/latest.tar.gz')
        .replyWithFile(200, 'assets/latest.tar.gz');

      tempDir.runCmd('new', ['--author', 'Test Author', 'test-project-author'], function () {
        var project = tempDir.readJson('test-project-author/project/.collider');

        expect(project.name).to.equal('test-project-author');
        expect(project.author).to.equal('Test Author');
      });
    });
  });
});

afterEach(function () {
  nock.cleanAll();
});

after('clean', function () {
  tempDir.clean();
});

@@ -256,16 +256,91 @@
 uid');%0A%0A
+// Throw %22NetConnectNotAllowedError%22 on any requests to 'un-Nocked' hosts.%0A
 nock.dis
@@ -701,12 +701,12 @@
 // T
-O DO
+o do
 :%0A  
@@ -1777,542 +1777,227 @@
     
-  // Intercept following HTTP request with a mocked%0A      // response and expected successful file payload.%0A      nock('http://getcollider.com')%0A        .get('/latest.tar.gz')%0A        .replyWithFile(200, 'assets/latest.tar.gz');%0A%0A      tempDir.runCmd('new', %5B'test-project'%5D, function () %7B%0A        var project = tempDir.readJson('test-project/project/.collider');%0A%0A        expect(project.name).to.equal('test-project');%0A        expect(project.author).to.equal('unknown');%0A      %7D);%0A    %7D);%0A%0A    it('should create a new project
+%7D);%0A%0A    // Collider-file reference.%0A    // %7B%22name%22:%22%22,%22createdTime%22:0,%22author%22:%22%22,%22matterLibs%22:%5B%5D%7D%0A%0A    it('should populate the Collider-file', function () %7B%0A%0A    %7D);%0A%0A    it('should populate the Collider-file
  with 
-an
+the
  att
@@ -2036,316 +2036,131 @@
     
-  // Intercept following HTTP request with a mocked%0A      // response and expected successful file payload.%0A      nock('http://getcollider.com')%0A        .get('/latest.tar.gz')%0A        .replyWithFile(200, 'assets/latest.tar.gz');%0A%0A      tempDir.runCmd('new', %5B'--author', 'Test Author', 'test-project-autho
+%7D);%0A  %7D);%0A%0A  // %60run%60 command%0A  //%0A%0A  describe('run', function () %7B%0A%0A  %7D);%0A%0A  // %60matter%60 command%0A  //%0A%0A  describe('matte
 r'
-%5D
 , fu
@@ -2175,225 +2175,150 @@
 ) %7B%0A
+%0A
   
-      var project = tempDir.readJson('test-project-author/project/.collider');%0A%0A        expect(project.name).to.equal('test-project-author'
+%7D);%0A%0A  // %60generate%60 command%0A  //%0A%0A  describe('generate', function () %7B%0A%0A  %7D
 );%0A
+%0A
   
-      expect(project.author).to.equal('Test Author');%0A      %7D);%0A    %7D);
+// %60help%60 command%0A  //%0A%0A  describe('help', function () %7B%0A
 %0A  %7D

Prepare test/collider.js for following tests