<commit_before>'use strict';

var path          = require('path');
var assert        = require('../../helpers/assert');
var MockUI        = require('../../helpers/mock-ui');
var MockAnalytics = require('../../helpers/mock-analytics');
var rewire        = require('rewire');
var stubPath      = require('../../helpers/stub').stubPath;
var Promise       = require('../../../lib/ext/promise');
var Project       = require('../../../lib/models/project');
var Task          = require('../../../lib/models/task');

describe('init command', function() {
  var InitCommand;
  var ui;
  var analytics;
  var project;
  var tasks;

  beforeEach(function() {
    ui = new MockUI();
    analytics = new MockAnalytics();
    tasks = {
      InstallBlueprint: Task.extend({}),
      NpmInstall: Task.extend({}),
      BowerInstall: Task.extend({})
    };

    project = new Project(process.cwd(), { name: 'some-random-name'});
    InitCommand = rewire('../../../lib/commands/init');
    InitCommand.__set__('path', stubPath('test'));
  });

  it('doesn\'t allow to create an application named `test`', function() {
    new InitCommand({
      ui: ui,
      analytics: analytics,
      project: new Project(process.cwd(), { name: 'test'}),
      tasks: tasks
    }).validateAndRun([]).then(function() {
      assert.ok(false, 'should have rejected with an application name of test');
    })
    .catch(function() {
      assert.equal(ui.output, 'Due to an issue with `compileES6` an application name of `test` cannot be used.');
    });
  });

  it('Uses the name of the closest project to when calling installBlueprint', function() {
    tasks.InstallBlueprint = Task.extend({
      run: function(blueprintOpts) {
        assert.equal(blueprintOpts.rawName, 'some-random-name');
        return Promise.reject('Called run');
      }
    });

    var command = new InitCommand({
      ui: ui,
      analytics: analytics,
      project: project,
      tasks: tasks
    });

    return command.validateAndRun([])
      .catch(function(reason) {
        assert.equal(reason, 'Called run');
      });
  });

  it('Uses process.cwd if no package is found when calling installBlueprint', function() {
    tasks.InstallBlueprint = Task.extend({
      run: function(blueprintOpts) {
        assert.equal(blueprintOpts.rawName, path.basename(process.cwd()));
        return Promise.reject('Called run');
      }
    });
    var command = new InitCommand({
      ui: ui,
      analytics: analytics,
      project: new Project(process.cwd(), { name: path.basename(process.cwd()) }),
      tasks: tasks
    });

    return command.validateAndRun([])
      .catch(function(reason) {
        assert.equal(reason, 'Called run');
      });
  });
});<commit_msg>add test to prevent regression<commit_after>'use strict';

var path          = require('path');
var assert        = require('../../helpers/assert');
var MockUI        = require('../../helpers/mock-ui');
var MockAnalytics = require('../../helpers/mock-analytics');
var rewire        = require('rewire');
var stubPath      = require('../../helpers/stub').stubPath;
var Promise       = require('../../../lib/ext/promise');
var Project       = require('../../../lib/models/project');
var Task          = require('../../../lib/models/task');

describe('init command', function() {
  var InitCommand;
  var ui;
  var analytics;
  var project;
  var tasks;

  beforeEach(function() {
    ui = new MockUI();
    analytics = new MockAnalytics();
    tasks = {
      InstallBlueprint: Task.extend({}),
      NpmInstall: Task.extend({}),
      BowerInstall: Task.extend({})
    };

    project = new Project(process.cwd(), { name: 'some-random-name'});
    InitCommand = rewire('../../../lib/commands/init');
    InitCommand.__set__('path', stubPath('test'));
  });

  it('doesn\'t allow to create an application named `test`', function() {
    new InitCommand({
      ui: ui,
      analytics: analytics,
      project: new Project(process.cwd(), { name: 'test'}),
      tasks: tasks
    }).validateAndRun([]).then(function() {
      assert.ok(false, 'should have rejected with an application name of test');
    })
    .catch(function() {
      assert.equal(ui.output, 'Due to an issue with `compileES6` an application name of `test` cannot be used.');
    });
  });

  it('Uses the name of the closest project to when calling installBlueprint', function() {
    tasks.InstallBlueprint = Task.extend({
      run: function(blueprintOpts) {
        assert.equal(blueprintOpts.rawName, 'some-random-name');
        return Promise.reject('Called run');
      }
    });

    var command = new InitCommand({
      ui: ui,
      analytics: analytics,
      project: project,
      tasks: tasks
    });

    return command.validateAndRun([])
      .catch(function(reason) {
        assert.equal(reason, 'Called run');
      });
  });

  it('Uses the provided app name over the closest found project', function() {
    tasks.InstallBlueprint = Task.extend({
      run: function(blueprintOpts) {
        assert.equal(blueprintOpts.rawName, 'provided-name');
        return Promise.reject('Called run');
      }
    });

    var command = new InitCommand({
      ui: ui,
      analytics: analytics,
      project: new Project(process.cwd(), { name: 'some-random-name'}),
      tasks: tasks
    });

    return command.validateAndRun(['provided-name'])
      .catch(function(reason) {
        assert.equal(reason, 'Called run');
      });
  });


  it('Uses process.cwd if no package is found when calling installBlueprint', function() {
    tasks.InstallBlueprint = Task.extend({
      run: function(blueprintOpts) {
        assert.equal(blueprintOpts.rawName, path.basename(process.cwd()));
        return Promise.reject('Called run');
      }
    });
    var command = new InitCommand({
      ui: ui,
      analytics: analytics,
      project: new Project(process.cwd(), { name: path.basename(process.cwd()) }),
      tasks: tasks
    });

    return command.validateAndRun([])
      .catch(function(reason) {
        assert.equal(reason, 'Called run');
      });
  });
});
{'fraction_non_alphanumeric': 0.1652145323031399, 'fraction_numerical': 0.0003287851389117212, 'mean_word_length': 2.705237515225335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1535294', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1766, 'n_words': 435}