<commit_before>/*global describe, before, beforeEach, it */
'use strict';
var fs = require('fs');
var path = require('path');
var util = require('util');
var events = require('events');
var assert = require('assert');
var sinon = require('sinon');
var proxyquire = require('proxyquire');
var generators = require('..');
var fetch = require('../lib/actions/fetch');

var noop = function () { return this; };

describe('generators.Base fetch utilities', function () {
  // increase timeout to 15s for this suite (slow connections like mine needs that)
  this.timeout(50000);

  before(generators.test.setUpTestDirectory(path.join(__dirname, 'temp')));

  beforeEach(function () {
    function Dummy() {
      generators.Base.apply(this, arguments);
    }
    util.inherits(Dummy, generators.Base);

    Dummy.prototype.test = function () {
      this.shouldRun = true;
    };

    this.env = generators();
    this.dummy = new Dummy({
      env: this.env,
      resolved: 'test:fetch'
    });
    this.Dummy = Dummy;
  });

  describe('#bowerInstall()', function () {
    it('fetch remote from Bower', function (done) {
      this.dummy.bowerInstall('backbone', function () {
        fs.stat('bower_components/backbone', done);
      });
    });
  });

  describe('#tarball()', function () {
    beforeEach(function () {
      this.events = new events.EventEmitter();
      this.download = sinon.stub().returns(this.events);
      this.fetch = proxyquire('../lib/actions/fetch', { download: this.download });
      this.fetch.log = {
        write: noop,
        info: noop,
        ok: noop
      };
    });

    it('download and untar via the NPM download package', function (done) {
      var called = false;
      var from = 'https://github.com/yeoman/generator/archive/master.tar.gz';
      var dest = './yeoman-generator/';
      var cb = function () {
        called = true;
        done();
      };
      this.fetch.tarball(from, dest, cb);

      var downloadCall = this.download.args[0];
      assert.equal(downloadCall[0], from);
      assert.equal(downloadCall[1], dest);
      assert.ok(!called);
      this.events.emit('close');
    });

    it('aliases #extract()', function () {
      assert.equal(fetch.tarball, fetch.extract);
    });
  });

  describe('#fetch()', function () {
    it('should allow the fething of a single file', function (done) {
      this.dummy.fetch('https://raw.github.com/yeoman/generator/master/readme.md', './some/path/README.md', function (err) {
        if (err) {
          return done(err);
        }
        fs.stat('./some/path/README.md', done);
      });
    });
  });

  describe('#remote()', function () {
    it('should remotely fetch a package on github', function (done) {
      this.dummy.remote('yeoman', 'generators', done);
    });

    it('should have the result cached internally into a `_cache` folder', function (done) {
      fs.stat(path.join(this.dummy.cacheRoot(), 'yeoman/generators/master'), done);
    });

    it('should invoke `cb` with a remote object to interract with the downloaded package', function (done) {
      this.dummy.remote('yeoman', 'generators', function (err, remote) {
        if (err) {
          return done(err);<commit_msg>Fix remote tests<commit_after>/*global describe, before, beforeEach, it */
'use strict';
var fs = require('fs');
var path = require('path');
var util = require('util');
var events = require('events');
var assert = require('assert');
var sinon = require('sinon');
var proxyquire = require('proxyquire');
var generators = require('..');
var fetch = require('../lib/actions/fetch');

var noop = function () { return this; };

describe('generators.Base fetch utilities', function () {
  // increase timeout to 15s for this suite (slow connections like mine needs that)
  this.timeout(50000);

  before(generators.test.setUpTestDirectory(path.join(__dirname, 'temp')));

  beforeEach(function () {
    function Dummy() {
      generators.Base.apply(this, arguments);
    }
    util.inherits(Dummy, generators.Base);

    Dummy.prototype.test = function () {
      this.shouldRun = true;
    };

    this.env = generators();
    this.dummy = new Dummy({
      env: this.env,
      resolved: 'test:fetch'
    });
    this.Dummy = Dummy;
  });

  describe('#bowerInstall()', function () {
    it('fetch remote from Bower', function (done) {
      this.dummy.bowerInstall('backbone', function () {
        fs.stat('bower_components/backbone', done);
      });
    });
  });

  describe('#tarball()', function () {
    beforeEach(function () {
      this.events = new events.EventEmitter();
      this.download = sinon.stub().returns(this.events);
      this.fetch = proxyquire('../lib/actions/fetch', { download: this.download });
      this.fetch.log = {
        write: noop,
        info: noop,
        ok: noop
      };
    });

    it('download and untar via the NPM download package', function (done) {
      var called = false;
      var from = 'https://github.com/yeoman/generator/archive/master.tar.gz';
      var dest = './yeoman-generator/';
      var cb = function () {
        called = true;
        done();
      };
      this.fetch.tarball(from, dest, cb);

      var downloadCall = this.download.args[0];
      assert.equal(downloadCall[0], from);
      assert.equal(downloadCall[1], dest);
      assert.ok(!called);
      this.events.emit('close');
    });

    it('aliases #extract()', function () {
      assert.equal(fetch.tarball, fetch.extract);
    });
  });

  describe('#fetch()', function () {
    it('should allow the fething of a single file', function (done) {
      this.dummy.fetch('https://raw.github.com/yeoman/generator/master/readme.md', './some/path/README.md', function (err) {
        if (err) {
          return done(err);
        }
        fs.stat('./some/path/README.md', done);
      });
    });
  });

  describe('#remote()', function () {
    it('should remotely fetch a package on github', function (done) {
      this.dummy.remote('yeoman', 'generator', done);
    });

    it('should have the result cached internally into a `_cache` folder', function (done) {
      fs.stat(path.join(this.dummy.cacheRoot(), 'yeoman/generator/master'), done);
    });

    it('should invoke `cb` with a remote object to interract with the downloaded package', function (done) {
      this.dummy.remote('yeoman', 'generator', function (err, remote) {
        if (err) {
          return done(err);
{'fraction_non_alphanumeric': 0.16692570718060304, 'fraction_numerical': 0.003108486167236556, 'mean_word_length': 2.9213893967093236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6908017', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1905, 'n_words': 459}