<commit_before>require 'spec_helper'

describe Zack::Notifier do
  class Handler
    def initialize(backchannel)
      @backchannel = backchannel
    end
    def pids
      @backchannel.put Process.pid
    end
  end

  let(:backchannel) { Cod.pipe }
  let(:notifier) {
    Zack::Notifier.new(
      'football', 
      server: 'localhost:11300', 
      with_answer: [:bar])
  }

  # Starts two server processes that are notified of events. 
  before(:each) { 
    @pids = 2.times.map { 
      backchannel_dup = backchannel.dup
      fork do
        listener = Zack::Listener.new(
          'football', 
          factory: lambda { Handler.new(backchannel_dup) },
          server: 'localhost:11300')
        
        backchannel_dup.put :ready
        listener.run
      end
    }
    @pids.size.times { backchannel.get }
  }
  # Makes sure the server processes are killed. 
  after(:each) { 
    @pids.each do |pid|
      Process.kill('TERM', pid)
    end
    Process.waitall
  }

  it "returns all return values from all listeners" do
    notifier.pids
    
    resulting_pids = @pids.size.times.map { backchannel.get(timeout: 0.5) }
    
    resulting_pids.should =~ @pids<commit_msg>. corrects wording of a spec<commit_after>require 'spec_helper'

describe Zack::Notifier do
  class Handler
    def initialize(backchannel)
      @backchannel = backchannel
    end
    def pids
      @backchannel.put Process.pid
    end
  end

  let(:backchannel) { Cod.pipe }
  let(:notifier) {
    Zack::Notifier.new(
      'football', 
      server: 'localhost:11300', 
      with_answer: [:bar])
  }

  # Starts two server processes that are notified of events. 
  before(:each) { 
    @pids = 2.times.map { 
      backchannel_dup = backchannel.dup
      fork do
        listener = Zack::Listener.new(
          'football', 
          factory: lambda { Handler.new(backchannel_dup) },
          server: 'localhost:11300')
        
        backchannel_dup.put :ready
        listener.run
      end
    }
    @pids.size.times { backchannel.get }
  }
  # Makes sure the server processes are killed. 
  after(:each) { 
    @pids.each do |pid|
      Process.kill('TERM', pid)
    end
    Process.waitall
  }

  it "executes all registered listeners" do
    notifier.pids
    
    resulting_pids = @pids.size.times.map { backchannel.get(timeout: 0.5) }
    
    resulting_pids.should =~ @pids
{'fraction_non_alphanumeric': 0.10395622895622895, 'fraction_numerical': 0.010942760942760943, 'mean_word_length': 2.319832402234637, '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': '6254534', 'n_tokens_mistral': 807, 'n_tokens_neox': 755, 'n_words': 177}