<commit_before>'use strict'
const Promise = require('bluebird')
const fs = Promise.promisifyAll(require('fs'))
const input = require('input')
const init = require('src/init')

describe('init', () => {
  beforeEach(() => {
    sinon.stub(input, 'text', () => Promise.resolve('foo'))
    sinon.stub(fs, 'writeFileAsync', () => Promise.resolve())
  })
  afterEach(() => {
    input.text.restore()
    fs.writeFileAsync.restore()
  })
  it('rejects if input cannot be read', () => {
    input.text.restore()
    sinon.stub(input, 'text', () => Promise.reject(new Error('foo')))
    return init()
      .catch((err) => {
        expect(err.message).to.equal('Could not read input')
      })
  })
  it('rejects if config file cannot be written', () => {
    fs.writeFileAsync.restore()
    sinon.stub(fs, 'writeFileAsync', () => Promise.reject(new Error('foo')))
    return init()
      .catch((err) => {
        expect(err.message).to.equal('Unable to write config file')
      })
  })
  it('accepts image prompt input and writes config file from template and resolves', () => {
    return init()
      .then((res) => {
        expect(res).to.equal('Config file created')
      })
  })
})<commit_msg>test(init): use sandbox for stubs<commit_after>'use strict'
const Promise = require('bluebird')
const fs = Promise.promisifyAll(require('fs'))
const input = require('input')
const init = require('src/init')
const sandbox = require('test/sandbox')

describe('init', () => {
  beforeEach(() => {
    sandbox.stub(input, 'text', () => Promise.resolve('foo'))
    sandbox.stub(fs, 'writeFileAsync', () => Promise.resolve())
  })
  it('rejects if input cannot be read', () => {
    input.text.restore()
    sandbox.stub(input, 'text', () => Promise.reject(new Error('foo')))
    return init()
      .catch((err) => {
        expect(err.message).to.equal('Could not read input')
      })
  })
  it('rejects if config file cannot be written', () => {
    fs.writeFileAsync.restore()
    sandbox.stub(fs, 'writeFileAsync', () => Promise.reject(new Error('foo')))
    return init()
      .catch((err) => {
        expect(err.message).to.equal('Unable to write config file')
      })
  })
  it('accepts image prompt input and writes config file from template and resolves', () => {
    return init()
      .then((res) => {
        expect(res).to.equal('Config file created')
      })
  })
})
{'fraction_non_alphanumeric': 0.19065656565656566, 'fraction_numerical': 0.0, 'mean_word_length': 3.385608856088561, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '772715', 'n_tokens_mistral': 741, 'n_tokens_neox': 745, 'n_words': 170}