/*global describe, beforeEach, it*/

var path = require('path');
var assert = require('assert');
var helpers = require('yeoman-generator').test;
var assert = require('yeoman-generator').assert;
var _ = require('underscore');

describe('Webapp generator', function () {
  // not testing the actual run of generators yet
  it('the generator can be required without throwing', function () {
    this.app = require('../app');
  });

  describe('run test', function () {

    var expectedContent = [
      ['bower.json', /"name": "tmp"/],
      ['package.json', /"name": "tmp"/]
    ];
    var expected = [
      '.editorconfig',
      '.gitignore',
      '.gitattributes',
      'package.json',
      'bower.json',
      'Gruntfile.js',
      'app/favicon.ico',
      'app/robots.txt',
      'app/index.ejs'
    ];

    var options = {
      'skip-install-message': true,
      'skip-install': true,
      'skip-welcome-message': true,
      'skip-message': true
    };

    var runGen;

    beforeEach(function () {
      runGen = helpers
        .run(path.join(__dirname, '../app'))
        .inDir(path.join(__dirname, '.tmp'))
        .withGenerators([[helpers.createDummyGenerator(), 'mocha:app']]);
    });

    it('creates expected files', function (done) {
      runGen.withOptions(options).on('end', function () {

        assert.file([].concat(
          expected,
          'app/styles/main.css',
          'app/scripts/main.js'
        ));
        assert.noFile([
          'app/styles/main.scss',
          'app/scripts/main.coffee'
        ]);

        assert.fileContent(expectedContent);
        assert.noFileContent([
          ['initConfig.js', /coffee/],
          ['initConfig.js', /modernizr/],
          ['app/index.ejs', /modernizr/],
          ['bower.json', /modernizr/],
          ['package.json', /modernizr/],
          ['initConfig.js', /bootstrap/],
          ['app/index.ejs', /bootstrap/],
          ['bower.json', /bootstrap/],
          ['initConfig.js', /sass/],
          ['app/index.ejs', /Sass/],
          ['.gitignore', /\.sass-cache/],
          ['package.json', /grunt-contrib-sass/],
          ['package.json', /grunt-sass/],
          ['initConfig.js', /bootstrap-sass-official/],
          ['app/index.ejs', /Sass is a mature/],
          ['bower.json', /bootstrap-sass-official/]
        ]);
        done();
      });
    });

    it('creates expected CoffeeScript files', function (done) {
      runGen.withOptions(
        _.extend(options, {coffee: true})
      ).on('end', function () {

        assert.file([].concat(
          expected,
          'app/scripts/main.coffee'
        ));
        assert.noFile('app/scripts/main.js');

        assert.fileContent([].concat(
          expectedContent,
          [['initConfig.js', /coffee/]]
        ));

        done();
      });
    });

    it('creates expected modernizr components', function (done) {
      runGen.withOptions(options).withPrompt({features: ['includeModernizr']})
      .on('end', function () {

        assert.fileContent([
          ['initConfig.js', /modernizr/],
          ['app/index.ejs', /modernizr/],
          ['bower.json', /modernizr/],
          ['package.json', /modernizr/],
        ]);

        done();
      });
    });

    it('creates expected bootstrap components', function (done) {
      runGen.withOptions(options).withPrompt({features: ['includeBootstrap']})
      .on('end', function () {

        assert.fileContent([
          ['initConfig.js', /bootstrap/],
          ['app/index.ejs', /bootstrap/],
          ['bower.json', /bootstrap/]
        ]);

        done();
      });
    });

    it('creates expected ruby SASS components', function (done) {
      runGen.withOptions(options).withPrompt({features: ['includeSass']})
      .on('end', function () {

        assert.fileContent([
          ['initConfig.js', /sass/],
          ['app/index.ejs', /Sass/],
          ['.gitignore', /\.sass-cache/],
          ['package.json', /grunt-contrib-sass/]
        ]);

        assert.noFileContent([
          ['package.json', /grunt-sass/],
          ['app/index.ejs', /Sass is a mature/]
        ]);

        done();
      });
    });

    it('creates expected node SASS files', function (done) {
      runGen.withOptions(options).withPrompt({
        features: ['includeSass'],
        libsass: true
      }).on('end', function () {

        assert.fileContent([
          ['package.json', /grunt-sass/]
        ]);

        assert.noFileContent([
          ['package.json', /grunt-contrib-sass/],
          ['initConfig.js', /bootstrap-sass-official/]
        ]);

        done();
      });
    });

    it('creates expected SASS and Bootstrap components', function (done) {
      runGen.withOptions(options).withPrompt({
        features: ['includeSass', 'includeBootstrap']
      }).on('end', function () {

        assert.fileContent([
          ['initConfig.js', /bootstrap-sass-official/],
          ['app/index.ejs', /Sass is a mature/],
          ['bower.json', /bootstrap-sass-official/]
        ]);

        done();
      });
    });
  });
});

@@ -1712,37 +1712,41 @@
           %5B'app/
-index
+ejs/_head
 .ejs', /moderniz
@@ -1880,37 +1880,41 @@
           %5B'app/
-index
+ejs/_head
 .ejs', /bootstra

Fix to app/index.ejs from app/ejs/_head.ejs