<commit_before>require 'spec_helper'

describe EventHub::MessageProcessor do

  let(:message_processor) {
    processor = double(:processor)
    allow(processor).to receive(:name).and_return('a.processor', 'b.processor')
    allow(processor).to receive(:now_stamp).and_return('a.stamp', 'b.stamp')
    allow(processor).to receive(:handle_message) do |metadata, message|
      message
    end
    EventHub::MessageProcessor.new(processor)
  }


  it 'forwards the message to the processor' do
    message_processor.process(Object.new, '{}')
    expect(message_processor.processor).to have_received(:handle_message)
  end

  it 'adds execution path to header' do
    response = message_processor.process(Object.new, '{}')
    message = response[0]
    expect(message.header.get('execution_path').size).to eq(1)
    expect(message.header.get('execution_path')[0]).to eq({'processor' => 'a.processor', 'timestamp' => 'a.stamp'})
  end

  it 'appends execution path to header' do
    response = message_processor.process(Object.new, '{}')
    message = response[0]

    response = message_processor.process(Object.new, message.to_json)
    message = response[0]

    expect(message.header.get('execution_path').size).to eq(2)
    expect(message.header.get('execution_path')[0]).to eq({'processor' => 'a.processor', 'timestamp' => 'a.stamp'})
    expect(message.header.get('execution_path')[1]).to eq({'processor' => 'b.processor', 'timestamp' => 'b.stamp'})
  end
<commit_msg>fixed broken spec<commit_after>require 'spec_helper'

describe EventHub::MessageProcessor do

  let(:message_processor) {
    processor = double(:processor)
    allow(processor).to receive(:name).and_return('a.processor', 'b.processor')
    allow(processor).to receive(:now_stamp).and_return('a.stamp', 'b.stamp')
    allow(processor).to receive(:handle_message) do |metadata, message|
      message
    end
    EventHub::MessageProcessor.new(processor)
  }


  it 'forwards the message to the processor' do
    message_processor.process(Object.new, '{}')
    expect(message_processor.processor).to have_received(:handle_message)
  end

  it 'adds execution history to header' do
    response = message_processor.process(Object.new, '{}')
    message = response[0]
    expect(message.header.get('execution_history').size).to eq(1)
    expect(message.header.get('execution_history')[0]).to eq({'processor' => 'a.processor', 'timestamp' => 'a.stamp'})
  end

  it 'appends execution history to header' do
    response = message_processor.process(Object.new, '{}')
    message = response[0]

    response = message_processor.process(Object.new, message.to_json)
    message = response[0]

    expect(message.header.get('execution_history').size).to eq(2)
    expect(message.header.get('execution_history')[0]).to eq({'processor' => 'a.processor', 'timestamp' => 'a.stamp'})
    expect(message.header.get('execution_history')[1]).to eq({'processor' => 'b.processor', 'timestamp' => 'b.stamp'})
  end

{'fraction_non_alphanumeric': 0.1577350859453994, 'fraction_numerical': 0.005392652510953826, 'mean_word_length': 4.900596421471173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5371388', 'n_tokens_mistral': 939, 'n_tokens_neox': 910, 'n_words': 166}