<commit_before>/**
 * Inquirer public API test
 */

var expect = require("chai").expect;
var sinon = require("sinon");
var _ = require("lodash");
var ReadlineStub = require("../helpers/readline");
var inquirer = require("../../lib/inquirer");


describe("inquirer.prompt", function() {

  beforeEach(function() {
    inquirer.rl = new ReadlineStub();
  });

  it("should resume and close readline", function( done ) {
    var rl = inquirer.rl;

    inquirer.prompt({
      type: "confirm",
      name: "q1",
      message: "message"
    }, function( answers ) {
      expect(rl.resume.called).to.be.true;
      expect(rl.close.called).to.be.true;
      expect(inquirer.rl).to.be.null;

      rl = inquirer.rl = new ReadlineStub();
      inquirer.prompt({
        type: "confirm",
        name: "q1",
        message: "message"
      }, function( answers ) {
        expect(rl.resume.called).to.be.true;
        expect(rl.close.called).to.be.true;
        expect(inquirer.rl).to.be.null;
        done();
      });

      inquirer.rl.emit("line");
    });

    rl.emit("line");

  });

  it("should take a prompts array and return answers", function( done ) {
    var prompts = [{
      type: "confirm",
      name: "q1",
      message: "message"
    }, {
      type: "confirm",
      name: "q2",
      message: "message",
      default: false
    }];

    inquirer.prompt( prompts, function( answers ) {
      expect(answers.q1).to.be.true;
      expect(answers.q2).to.be.false;<commit_msg>Better test for the inquirer nested bug - test what is expected not how it is done<commit_after>/**
 * Inquirer public API test
 */

var expect = require("chai").expect;
var sinon = require("sinon");
var _ = require("lodash");
var ReadlineStub = require("../helpers/readline");
var proxyquire = require("proxyquire");
var inquirer = proxyquire("../../lib/inquirer", {
  "./utils/readline": {
    createInterface: function() {
      return new ReadlineStub();
    }
  }
});


describe("inquirer.prompt", function() {

  it("should close and create a new readline instances each time it's called", function( done ) {
    var rl1;

    inquirer.prompt({
      type: "confirm",
      name: "q1",
      message: "message"
    }, function( answers ) {
      var rl2;

      expect(rl1.close.called).to.be.true;
      expect(inquirer.rl).to.not.exist;

      inquirer.prompt({
        type: "confirm",
        name: "q1",
        message: "message"
      }, function( answers ) {
        expect(rl2.close.called).to.be.true;
        expect(inquirer.rl).to.not.exist;

        expect( rl1 ).to.not.equal( rl2 );
        done();
      });

      rl2 = inquirer.rl;
      inquirer.rl.emit("line");
    });

    rl1 = inquirer.rl;
    inquirer.rl.emit("line");

  });

  it("should take a prompts array and return answers", function( done ) {
    var prompts = [{
      type: "confirm",
      name: "q1",
      message: "message"
    }, {
      type: "confirm",
      name: "q2",
      message: "message",
      default: false
    }];

    inquirer.prompt( prompts, function( answers ) {
      expect(answers.q1).to.be.true;
      expect(answers.q2).to.be.false;
{'fraction_non_alphanumeric': 0.16528662420382165, 'fraction_numerical': 0.006369426751592357, 'mean_word_length': 2.4440789473684212, 'pattern_counts': {'":': 1, '<': 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': '1514000', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1034, 'n_words': 225}