<commit_before>should = require 'should'
path = require 'path'
fs = require 'fs'
test_path = path.join(__dirname, 'fixtures/new')
rimraf = require 'rimraf'
mkdirp = require 'mkdirp'
require('./helpers')(should)

Roots = require '../lib'

describe 'new', ->

  it 'should throw if not given a path', ->
    (-> Roots.new()).should.throw

  it 'should create a project with the base tpl, emit all events, and return a roots instance from the callback', (done) ->
    p = path.join(test_path, 'testing')

    events = 0
    increment = -> ++events

    finish = (err) ->
      if err then return done(err)
      events.should.be.above(2)
      rimraf.sync(p)
      Roots.template.remove('base').done((-> done()), done)

    Roots.new(
      path: p
      options: { name: 'foo', description: 'bar' }
      done: (inst) -> inst.should.be.an.instanceof(Roots)
    ).on('done', -> finish())
     .on('error', finish)
     .on('template:base_added', increment)
     .on('template:created', increment)
     .on('deps:installing', increment)
     .on('deps:finished', increment)

  it 'should create a project with another template if provided'
    # this needs to add the template, create, then remove it
    # depends on the roots template commands<commit_msg>add a test for alternate template<commit_after>should = require 'should'
path = require 'path'
fs = require 'fs'
test_path = path.join(__dirname, 'fixtures/new')
rimraf = require 'rimraf'
mkdirp = require 'mkdirp'
require('./helpers')(should)
test_tpl_path = 'https://github.com/jenius/sprout-test-template.git'

Roots = require '../lib'

describe 'new', ->

  it 'should throw if not given a path', ->
    (-> Roots.new()).should.throw

  it 'should create a project with the base tpl, emit all events, and return a roots instance from the callback', (done) ->
    p = path.join(test_path, 'testing')

    events = 0
    increment = -> ++events

    finish = (err) ->
      if err then return done(err)
      events.should.be.above(2)
      rimraf.sync(p)
      Roots.template.remove('base').done((-> done()), done)

    Roots.new(
      path: p
      options: { name: 'foo', description: 'bar' }
      done: (inst) -> inst.should.be.an.instanceof(Roots)
    ).on('done', -> finish())
     .on('error', finish)
     .on('template:base_added', increment)
     .on('template:created', increment)
     .on('deps:installing', increment)
     .on('deps:finished', increment)

  it 'should create a project with another template if provided', (done) ->
    p = path.join(test_path, 'testing')

    Roots.template.add(name: 'foobar', url: test_tpl_path)
      .catch(done)
      .then ->
        Roots.new(path: p, options: { foo: 'bar' }, template: 'foobar').on 'done', ->
          fs.existsSync(path.join(p, 'index.html')).should.be.ok
          rimraf.sync(p)
          Roots.template.remove('foobar').then(-> done())
{'fraction_non_alphanumeric': 0.1600418410041841, 'fraction_numerical': 0.001394700139470014, 'mean_word_length': 3.1103151862464182, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 1, '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': '2445412', 'n_tokens_mistral': 934, 'n_tokens_neox': 914, 'n_words': 257}