<commit_before>'use strict';

var stream = require('stream');

var expect = require('expect');

var stdout = require('../');

describe('mute', function() {

  var ogWrite = stream.Duplex.prototype.write;

  it('mutes the stream', function(done) {

    var writes = 0;

    stream.Duplex.prototype.write = function() {
      writes++;
    };

    stdout.mute();

    console.log('should not print');

    stdout.unmute();
    stream.Duplex.prototype.write = ogWrite;

    expect(writes).toEqual(0);

    done();
  });
});

describe('unmute', function() {

  var ogWrite = stream.Duplex.prototype.write;

  it('unmutes a muted stream', function(done) {

    var writes = 0;

    stream.Duplex.prototype.write = function() {
      writes++;
    };

    stdout.mute();

    console.log('should not print');

    stdout.unmute();

    console.log('should print');

    stream.Duplex.prototype.write = ogWrite;

    expect(writes).toEqual(1);

    done();
  });

  it('don\'t replace back when be not muted', function(done) {
    var ogWrite = process.stdout.write;
    var counter = 0;
    process.stdout.write = function() {
      counter++;
    };

    console.log('should count up!');

    stdout.unmute();

    console.log('should count up!');

    process.stdout.write = ogWrite;
    expect(counter).toEqual(2);
    done();
  });
});<commit_msg>Update: Use proper spies for testing (ref #6)<commit_after>'use strict';

var expect = require('expect');

// The spy needs to be set up before our module tracks the original method
var spy = expect.spyOn(process.stdout, 'write').andCallThrough();

var stdout = require('../');

describe('mute', function() {

  beforeEach(function(done) {
    spy.reset();

    done();
  });

  afterEach(function(done) {
    spy.reset();

    done();
  });

  it('mutes the stream', function(done) {

    stdout.mute();

    console.log('should not print');

    stdout.unmute();

    expect(spy).toNotHaveBeenCalled();

    done();
  });
});

describe('unmute', function() {

  beforeEach(function(done) {
    spy.reset();

    done();
  });

  afterEach(function(done) {
    spy.reset();

    done();
  });

  it('unmutes a muted stream', function(done) {

    stdout.mute();

    console.log('should not print');

    stdout.unmute();

    console.log('should print');

    expect(spy).toHaveBeenCalled();
    expect(spy.calls.length).toEqual(1);

    done();
  });

  it('skips unmute if never muted', function(done) {

    console.log('should count up!');

    stdout.unmute();

    console.log('should count up!');

    expect(spy).toHaveBeenCalled();
    expect(spy.calls.length).toEqual(2);
    done();
  });
});
{'fraction_non_alphanumeric': 0.17622641509433962, 'fraction_numerical': 0.0033962264150943396, 'mean_word_length': 3.0910493827160495, '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': '1401504', 'n_tokens_mistral': 918, 'n_tokens_neox': 862, 'n_words': 181}