<commit_before>﻿var Install = require('../lib/install'),
    sinon = require('sinon'),
    Q = require('q'),
    _ = require('underscore'),
    injections = {
        _: _,
        Q: Q,
        prefix: require('../lib/prefix')
    },
    RequireHelper = require('../lib/helper/require');

describe('install', function() {
    describe('interface', function() {
        var install;
        beforeEach(function() {
            install = new Install();
        });
        it('should respond to install', function() {
            install.should.respondTo('install');
            install.should.respondTo('installGenerators');
            install.should.respondTo('installTemplates');
        });
        it('should respond to uninstall', function() {
            install.should.respondTo('uninstall');
            install.should.respondTo('uninstallGenerators');
            install.should.respondTo('uninstallTemplates');
        });
    });
    
    describe('#install', function() {
        var installSpy = sinon.spy(),
            install;
        beforeEach(function() {
            install = new Install(_.extend(injections, {
                npm: {
                    install: installSpy
                }
            }));
        });
        it('should call npm.install', function() {
            install.install('module');
            installSpy.should.have.been.calledWith('module');
        });
    });

    describe('#installGenerators', function () {
        var install,
            installStub = createSinonStubPromise(),
            configStub = createSinonStubPromise();

        beforeEach(function () {
            install = new Install(_.extend(injections, {
                npm: {
                    install: installStub
                },
                requireHelper: new RequireHelper(injections),
                heinzelConfig: {
                    saveLocal: configStub
                }
            }));
        });
        it('should call npm.install with the generator prefix', function () {
            install.installGenerators('module');
            installStub.should.have.been.calledWith(['heinzelmannchen-gen-module']);
        });

        it('should call npm.install with the generator prefix for multiple generators', function () {
            install.installGenerators(['module1', 'module2', 'module3']);
            installStub.should.have.been.calledWith(['heinzelmannchen-gen-module1', 'heinzelmannchen-gen-module2', 'heinzelmannchen-gen-module3']);
        });

        it('shouldn\'t call heinzel config if no save flag is used', function () {
            return install.installGenerators('module').then(function () {
                return configStub.should.not.have.been.called;
            });
        });

        it('should call heinzel config with the generator string', function () {
            return install.installGenerators('module', true).then(function () {
                return configStub.should.have.been.calledWith('generators.heinzelmannchen-gen-module');
            });
        });
    });

    describe('#installTemplates', function () {
        var install,
            installStub = createSinonStubPromise(),
            configStub = createSinonStubPromise();

        beforeEach(function () {
            install = new Install(_.extend(injections, {
                npm: {
                    install: installStub
                },
                requireHelper: new RequireHelper(injections),
                heinzelConfig: {
                    saveLocal: configStub
                }
            }));
        });
        it('should call npm.install with the template prefix', function () {
            install.installTemplates('module');
            installStub.should.have.been.calledWith(['heinzelmannchen-tpl-module']);
        });

        it('should call npm.install with the template prefix for multiple templates', function () {
            install.installTemplates(['module1', 'module2', 'module3']);
            installStub.should.have.been.calledWith(['heinzelmannchen-tpl-module1', 'heinzelmannchen-tpl-module2', 'heinzelmannchen-tpl-module3']);
        });

        it('shouldn\'t call heinzel config if no save-flag is used', function () {
            return install.installTemplates('module').then(function () {
                return configStub.should.not.have.been.called;
            });
        });

        it('should call heinzel config with the template string', function () {
            return install.installTemplates(['module'], true).then(function () {
                return configStub.should.have.been.calledWith('templates.heinzelmannchen-tpl-module');
            });
        });

        it('should call npm.install without a prefix if it\'s an url', function () {
            var urls = ['http://github.com/heinzelmannchen/module1.git',
                        'https://github.com/heinzelmannchen/module2.git',
                        'http://github.com/heinzelmannchen/module3',
                        'https://github.com/heinzelmannchen/module4',
                        'git://github.com/heinzelmannchen/module5'];
            install.installTemplates(urls);
            installStub.should.have.been.calledWith(urls);
        });

        it('should call heinzel config with the repository name if it\'s an url or packagename', function () {
            var packages = ['http://github.com/heinzelmannchen/module1.git',
                            'https://github.com/heinzelmannchen/module2',
                            'module3',
                            'git://github.com/heinzelmannchen/module4',
                            'http://github.com/heinzelmannchen/heinzel-tpl-foo.git#0.1.1/myfoo.tpl'];
            return install.installTemplates(packages, true).then(function () {
                return configStub.should.have.been.calledWith('templates.module1', 'http://github.com/heinzelmannchen/module1.git') &&
                       configStub.should.have.been.calledWith('templates.module2', 'https://github.com/heinzelmannchen/module2') &&
                       configStub.should.have.been.calledWith('templates.heinzelmannchen-tpl-module3', 'heinzelmannchen-tpl-module3') &&
                       configStub.should.have.been.calledWith('templates.module4', 'git://github.com/heinzelmannchen/module4');
            });
        });
    });
    
    describe('uninstall', function() {
        var install,
            uninstallStub = createSinonStubPromise(),
            configStub = createSinonStubPromise();

        beforeEach(function() {
            install = new Install(_.extend(injections, {
                npm: {
                    uninstall: uninstallStub
                },
                requireHelper: new RequireHelper(injections),
                heinzelConfig: {
                    removeLocal: configStub
                }
            }));
        });
        it('should call npm.uninstall', function() {
            install.uninstall('module');<commit_msg>renamed injection<commit_after>﻿var Install = require('../lib/install'),
    sinon = require('sinon'),
    Q = require('q'),
    _ = require('underscore'),
    injections = {
        _: _,
        Q: Q,
        prefix: require('../lib/prefix')
    },
    RequireHelper = require('../lib/helper/require');

describe('install', function() {
    describe('interface', function() {
        var install;
        beforeEach(function() {
            install = new Install();
        });
        it('should respond to install', function() {
            install.should.respondTo('install');
            install.should.respondTo('installGenerators');
            install.should.respondTo('installTemplates');
        });
        it('should respond to uninstall', function() {
            install.should.respondTo('uninstall');
            install.should.respondTo('uninstallGenerators');
            install.should.respondTo('uninstallTemplates');
        });
    });
    
    describe('#install', function() {
        var installSpy = sinon.spy(),
            install;
        beforeEach(function() {
            install = new Install(_.extend(injections, {
                npm: {
                    install: installSpy
                }
            }));
        });
        it('should call npm.install', function() {
            install.install('module');
            installSpy.should.have.been.calledWith('module');
        });
    });

    describe('#installGenerators', function () {
        var install,
            installStub = createSinonStubPromise(),
            configStub = createSinonStubPromise();

        beforeEach(function () {
            install = new Install(_.extend(injections, {
                npm: {
                    install: installStub
                },
                requireHelper: new RequireHelper(injections),
                config: {
                    saveLocal: configStub
                }
            }));
        });
        it('should call npm.install with the generator prefix', function () {
            install.installGenerators('module');
            installStub.should.have.been.calledWith(['heinzelmannchen-gen-module']);
        });

        it('should call npm.install with the generator prefix for multiple generators', function () {
            install.installGenerators(['module1', 'module2', 'module3']);
            installStub.should.have.been.calledWith(['heinzelmannchen-gen-module1', 'heinzelmannchen-gen-module2', 'heinzelmannchen-gen-module3']);
        });

        it('shouldn\'t call heinzel config if no save flag is used', function () {
            return install.installGenerators('module').then(function () {
                return configStub.should.not.have.been.called;
            });
        });

        it('should call heinzel config with the generator string', function () {
            return install.installGenerators('module', true).then(function () {
                return configStub.should.have.been.calledWith('generators.heinzelmannchen-gen-module');
            });
        });
    });

    describe('#installTemplates', function () {
        var install,
            installStub = createSinonStubPromise(),
            configStub = createSinonStubPromise();

        beforeEach(function () {
            install = new Install(_.extend(injections, {
                npm: {
                    install: installStub
                },
                requireHelper: new RequireHelper(injections),
                config: {
                    saveLocal: configStub
                }
            }));
        });
        it('should call npm.install with the template prefix', function () {
            install.installTemplates('module');
            installStub.should.have.been.calledWith(['heinzelmannchen-tpl-module']);
        });

        it('should call npm.install with the template prefix for multiple templates', function () {
            install.installTemplates(['module1', 'module2', 'module3']);
            installStub.should.have.been.calledWith(['heinzelmannchen-tpl-module1', 'heinzelmannchen-tpl-module2', 'heinzelmannchen-tpl-module3']);
        });

        it('shouldn\'t call heinzel config if no save-flag is used', function () {
            return install.installTemplates('module').then(function () {
                return configStub.should.not.have.been.called;
            });
        });

        it('should call heinzel config with the template string', function () {
            return install.installTemplates(['module'], true).then(function () {
                return configStub.should.have.been.calledWith('templates.heinzelmannchen-tpl-module');
            });
        });

        it('should call npm.install without a prefix if it\'s an url', function () {
            var urls = ['http://github.com/heinzelmannchen/module1.git',
                        'https://github.com/heinzelmannchen/module2.git',
                        'http://github.com/heinzelmannchen/module3',
                        'https://github.com/heinzelmannchen/module4',
                        'git://github.com/heinzelmannchen/module5'];
            install.installTemplates(urls);
            installStub.should.have.been.calledWith(urls);
        });

        it('should call heinzel config with the repository name if it\'s an url or packagename', function () {
            var packages = ['http://github.com/heinzelmannchen/module1.git',
                            'https://github.com/heinzelmannchen/module2',
                            'module3',
                            'git://github.com/heinzelmannchen/module4',
                            'http://github.com/heinzelmannchen/heinzel-tpl-foo.git#0.1.1/myfoo.tpl'];
            return install.installTemplates(packages, true).then(function () {
                return configStub.should.have.been.calledWith('templates.module1', 'http://github.com/heinzelmannchen/module1.git') &&
                       configStub.should.have.been.calledWith('templates.module2', 'https://github.com/heinzelmannchen/module2') &&
                       configStub.should.have.been.calledWith('templates.heinzelmannchen-tpl-module3', 'heinzelmannchen-tpl-module3') &&
                       configStub.should.have.been.calledWith('templates.module4', 'git://github.com/heinzelmannchen/module4');
            });
        });
    });
    
    describe('uninstall', function() {
        var install,
            uninstallStub = createSinonStubPromise(),
            configStub = createSinonStubPromise();

        beforeEach(function() {
            install = new Install(_.extend(injections, {
                npm: {
                    uninstall: uninstallStub
                },
                requireHelper: new RequireHelper(injections),
                config: {
                    removeLocal: configStub
                }
            }));
        });
        it('should call npm.uninstall', function() {
            install.uninstall('module');
{'fraction_non_alphanumeric': 0.1279393896076049, 'fraction_numerical': 0.004574369237366879, 'mean_word_length': 1.8980944490472245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, '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': '180090', 'n_tokens_mistral': 3626, 'n_tokens_neox': 3543, 'n_words': 586}