<commit_before>{Reader}       = require('../src/device/reader')
{Communicator} = require('../src/communicator')

describe 'Reader', ->
  beforeEach ->
    @communicator = sinon.createStubInstance(Communicator)
    @device       = {number: 0}
    @dataType     = 'test'
    @pluginMethod = 'Foo'
    @reader       = new Reader(@communicator, @device, @dataType, @pluginMethod)

  describe '#perform', ->
    it 'throws an error is the plugin is busy', ->
      @communicator.busy.returns true
      expect(=> @reader.perform()).to.throw Error

    it 'returns a promise', ->
      subject = @reader.perform()
      expect(subject? and _(subject).isObject() and subject.isFulfilled?).to.equal true

    it 'invokes the method on the communicator', ->
      @reader.perform()
      expect(@communicator.invoke.calledWith('StartReadFoo', 0, 'test')).to.equal true<commit_msg>Fix Reader specs.<commit_after>{Reader}       = require('../src/device/reader')
{Communicator} = require('../src/communicator')

describe 'Reader', ->
  beforeEach ->
    @communicator             = Communicator.get()
    @device                   = {number: 0}
    @dataType                 = 'test'
    @pluginMethod             = 'Foo'
    @reader                   = new Reader(@device, @dataType, @pluginMethod)
    @communicator.pluginProxy = {StartReadFoo: -> true}
    @invokeSpy                = sinon.spy(@communicator, 'invoke')

  afterEach ->
    Communicator.destroy()
    @invokeSpy.restore()

  describe '#perform', ->
    it 'throws an error is the plugin is busy', ->
      sinon.stub(Communicator.get(), 'busy').returns true
      expect(=> @reader.perform()).to.throw Error

    it 'returns a promise', ->
      subject = @reader.perform()
      expect(subject? and _(subject).isObject() and subject.isFulfilled?).to.equal true

    it 'invokes the method on the communicator', ->
      @reader.perform()
      expect(@communicator.invoke.calledWith('StartReadFoo', 0, 'test')).to.equal true
{'fraction_non_alphanumeric': 0.14934409687184663, 'fraction_numerical': 0.0020181634712411706, 'mean_word_length': 2.7699619771863118, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7213445', 'n_tokens_mistral': 604, 'n_tokens_neox': 566, 'n_words': 134}