<commit_before>require 'spec_helper'
require 'evented-spec'

describe Philotic do
  include EventedSpec::EMSpec
  include EventedSpec::SpecHelper

  default_timeout 10

  describe '.initialize_named_queue!' do

    after(:all) do
      test_queues.each_pair do |queue_name, config|
        Philotic.delete_queue(queue_name, config)
      end
    end

    let(:test_queues) do
      {
          app_live_feed: {
              exchange: 'philotic.headers.test_app.feed.live',
              options: {
                  arguments: {
                      :'x-dead-letter-exchange' => 'philotic.headers.test_app.feed.delayed',
                      :'x-message-ttl' => 600000 # ms
                  } },
              bindings:
                  [
                      {
                          philotic_product: 'test_app',
                          philotic_component: 'app_component',
                          :'x-match:' => 'all'
                      },
                  ],
          }
      }
    end
    it "should throw an error when ENV['INITIALIZE_NAMED_QUEUE'] is not set to 'true'" do
      ENV['INITIALIZE_NAMED_QUEUE'] = nil
      queue_name = test_queues.keys.first
      config = test_queues[queue_name]
      done do
        expect { Philotic.initialize_named_queue! queue_name, config }.to raise_error("ENV['INITIALIZE_NAMED_QUEUE'] must equal 'true' to run Philotic.initialize_named_queue!")
      end
    end

    it 'should set up the queue with the right parameters' do
      ENV['INITIALIZE_NAMED_QUEUE'] = 'true'


      test_queues.each_pair do |queue_name, config|
        config[:bindings].each do |arguments|
          expect_any_instance_of(AMQP::Queue).to receive(:bind).with(instance_of(AMQP::Exchange), { arguments: arguments })
          Philotic.initialize_named_queue! queue_name, config
        end

        done((test_queues.keys.length + 1) * 0.1) do

        end
      end
    end
  end
end<commit_msg>testing updates<commit_after>require 'spec_helper'
require 'evented-spec'

describe Philotic do
  include EventedSpec::EMSpec
  include EventedSpec::SpecHelper

  default_timeout 10

  describe '.initialize_named_queue!' do

    let(:test_queues) do
      {
          app_live_feed: {
              exchange: 'philotic.headers.test_app.feed.live',
              options: {
                  arguments: {
                      :'x-dead-letter-exchange' => 'philotic.headers.test_app.feed.delayed',
                      :'x-message-ttl' => 600000 # ms
                  } },
              bindings:
                  [
                      {
                          philotic_product: 'test_app',
                          philotic_component: 'app_component',
                          :'x-match:' => 'all'
                      },
                  ],
          }
      }
    end
    it "should throw an error when ENV['INITIALIZE_NAMED_QUEUE'] is not set to 'true'" do
      ENV['INITIALIZE_NAMED_QUEUE'] = nil
      queue_name = test_queues.keys.first
      config = test_queues[queue_name]
      done do
        expect { Philotic.initialize_named_queue! queue_name, config }.to raise_error("ENV['INITIALIZE_NAMED_QUEUE'] must equal 'true' to run Philotic.initialize_named_queue!")
      end
    end

it 'should set up the queue with the right parameters' do
  ENV['INITIALIZE_NAMED_QUEUE'] = 'true'

  test_queues.each_pair do |queue_name, config|

    queue_options = Philotic::DEFAULT_NAMED_QUEUE_OPTIONS.dup
    queue_options.merge!(config[:options] || {})

    channel_double = double(AMQP::Channel)
    queue_double = double(AMQP::Queue)
    exchange_double = double(AMQP::Exchange)

    expect(Philotic).to receive(:connect!).and_yield.exactly(2).times
    expect(AMQP).to receive(:channel).and_return(channel_double).exactly(2).times
    expect(channel_double).to receive(:queue).with(queue_name, queue_options).and_yield(queue_double).exactly(2).times
    expect(queue_double).to receive(:delete).and_yield
    expect(Philotic::Connection).to receive(:close).and_yield
    expect(channel_double).to receive(:headers).with(config[:exchange], durable: true) { exchange_double }
    expect(AMQP).to receive(:channel) { channel_double }
    expect(queue_double).to receive(:name) { queue_name }

    config[:bindings].each do |arguments|
      expect(queue_double).to receive(:bind).with(exchange_double, { arguments: arguments })
      Philotic.initialize_named_queue! queue_name, config
    end

    done((test_queues.keys.length + 1) * 0.1) do

    end
  end
end
  end
end
{'fraction_non_alphanumeric': 0.10406539991162174, 'fraction_numerical': 0.00552364118426867, 'mean_word_length': 2.3092105263157894, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2810575', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1324, 'n_words': 257}