<commit_before>require 'rails_helper'

describe Hg::Queues::Queue do
  let(:queue_key) { 'somekey' }
  let(:queue_class) { Hg::Queues::Queue }
  let(:queue) { Hg::Queues::Queue.new(queue_key) }
  let(:some_message) { 'some_message' }
  let(:some_other_message) { 'a newer message' }

  describe '.initialize' do
    it 'assigns redis @key' do
      queue = Hg::Queues::Queue.new(queue_key)

      expect(queue.instance_variable_get(:@key)).to eq queue_key
    end
  end

  describe '.pop' do
    before(:each) do
      allow(queue_class).to receive(:initialize).and_return(queue)
    end

    context 'when there are messages on the queue' do
      it 'pops the oldest message off of the given queue' do
        queue.push(some_message)
        queue.push(some_other_message)

        result = queue.pop

        expect(result).to eq some_message
      end

      it 'then pops the next in queue' do
        result = queue.pop

        expect(result).to eq some_other_message
      end
    end

    context 'when there is no message on the queue' do
      let(:empty_queue_key) { 'empty_queue_key' }
      let(:empty_queue) { Hg::Queues::Queue.new(empty_queue_key) }

      it 'returns an empty hash' do
        result = empty_queue.pop

        expect(result).to be_empty
      end
    end
  end

  describe '.push' do
    it 'puts the message on the given queue' do
      allow(Hg::Redis).to receive(:execute).and_return('1')

      result = queue.push(some_message)

      expect(result).to_not eq 0
    end
  end
end<commit_msg>properly stub redis queue methods<commit_after>require 'rails_helper'

describe Hg::Queues::Queue do
  let(:queue_key) { 'somekey' }
  let(:queue_class) { Hg::Queues::Queue }
  let(:queue) { Hg::Queues::Queue.new(queue_key) }
  let(:some_message) { 'some_message' }
  let(:some_other_message) { 'a newer message' }
  let(:conn) { double('conn') }

  before(:example) do
    allow(queue_class).to receive(:initialize).and_return(queue)
    allow(Hg::Redis).to receive(:execute).and_yield(conn)
  end

  describe '.initialize' do
    it 'assigns redis @key' do
      queue = Hg::Queues::Queue.new(queue_key)

      expect(queue.instance_variable_get(:@key)).to eq queue_key
    end
  end

  describe '.pop' do
    context 'when there are messages on the queue' do
      it 'pops the oldest message off of the given queue' do
        allow(conn).to receive(:lpop).and_return(JSON.generate(some_message))

        result = queue.pop

        expect(result).to eq some_message
      end
    end

    context 'when there is no message on the queue' do
      let(:empty_queue_key) { 'empty_queue_key' }
      let(:empty_queue) { Hg::Queues::Queue.new(empty_queue_key) }

      it 'returns an empty hash' do
        allow(conn).to receive(:lpop).and_return(nil)

        result = empty_queue.pop

        expect(result).to be_empty
      end
    end
  end

  describe '.push' do
    it 'puts the message on the given queue' do
      allow(conn).to receive(:rpush).and_return(JSON.generate('1'))

      result = queue.push(some_message)

      expect(result).to_not eq 0
    end
  end
end
{'fraction_non_alphanumeric': 0.11411121825779492, 'fraction_numerical': 0.0012857602057216328, 'mean_word_length': 3.0573663624511083, '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': '5910693', 'n_tokens_mistral': 1040, 'n_tokens_neox': 991, 'n_words': 259}