<commit_before><commit_msg>Add spec for out ports<commit_after>chai = require 'chai' unless chai
if typeof process isnt 'undefined' and process.execPath and process.execPath.indexOf('node') isnt -1
  outport = require '../src/lib/OutPort'
  socket = require '../src/lib/InternalSocket'
else
  outport = require 'noflo/src/lib/OutPort.js'
  socket = require 'noflo/src/lib/InternalSocket.js'

describe 'Outport Port', ->
  describe 'with addressable ports', ->
    s1 = s2 = s3 = null
    beforeEach ->
      s1 = new socket
      s2 = new socket
      s3 = new socket

    it 'should be able to send to a specific port', ->
      p = new outport
        addressable: true
      p.attach s1
      p.attach s2
      p.attach s3
      cb1 = jasmine.createSpy()
      cb2 = jasmine.createSpy()
      cb3 = jasmine.createSpy()
      s1.on 'data', cb1
      s2.on 'data', cb2
      s3.on 'data', cb3
      p.send 'some-data', 2
      cb1.not.toHaveBeenCalled()
      cb2.toHaveBeenCalled()
      cb3.not.toHaveBeenCalled()

    it 'should send to all with no specific port', ->
      p = new outport
        addressable: true
      p.attach s1
      p.attach s2
      p.attach s3
      cb1 = jasmine.createSpy()
      cb2 = jasmine.createSpy()
      cb3 = jasmine.createSpy()
      s1.on 'data', cb1
      s2.on 'data', cb2
      s3.on 'data', cb3
      p.send 'some-data'
      cb1.toHaveBeenCalled()
      cb2.toHaveBeenCalled()
      cb3.toHaveBeenCalled()

    it 'should throw an error when a specific port is requested with non-addressable port', ->
      p = new outport
      p.attach s1
      p.attach s2
      p.attach s3
      send ->
        p.send 'some-data'
      expect(send).toHaveThrown()
{'fraction_non_alphanumeric': 0.10882352941176471, 'fraction_numerical': 0.02411764705882353, 'mean_word_length': 2.173507462686567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '7206467', 'n_tokens_mistral': 590, 'n_tokens_neox': 584, 'n_words': 163}