<commit_before>require 'spec_helper'

describe KittyEvents do
  it 'has a version number' do
    expect(described_class::VERSION).not_to be nil
  end

  after(:each) do
    # Don't leak settings across tests
    described_class.class_variable_set :@@handlers, {}
  end

  let(:some_handler) { class_double(ActiveJob::Base) }
  let(:another_handler) { class_double(ActiveJob::Base) }
  let(:some_object) { double('Some::Object') }

  describe '.register' do
    it 'adds event to list of events' do
      described_class.register(:vote)
      expect(described_class.registered).to include(:vote)
    end

    it 'handles event names passed as a string' do
      described_class.register('event')
      expect(described_class.registered).to include(:event)
    end

    it 'handles multiple events' do
      described_class.register(:vote, :post, :subscribe)

      expect(described_class.registered).to include(:vote)
      expect(described_class.registered).to include(:post)
      expect(described_class.registered).to include(:subscribe)
    end

    it 'does not add duplicates' do
      described_class.register(:vote)
      described_class.register(:vote)

      expect(described_class.registered.length).to eq 1
    end
  end

  describe '.subscribe' do
    before do
      described_class.register(:vote)
    end

    it 'subscribes to an event' do
      described_class.subscribe(:vote, some_handler)

      expect(described_class.handlers[:vote]).to eq [some_handler]
    end

    it 'subscribes to an event (using string)' do
      described_class.subscribe('vote', some_handler)

      expect(described_class.handlers[:vote]).to eq [some_handler]<commit_msg>Register can be called multiple times<commit_after>require 'spec_helper'

describe KittyEvents do
  it 'has a version number' do
    expect(described_class::VERSION).not_to be nil
  end

  after(:each) do
    # Don't leak settings across tests
    described_class.class_variable_set :@@handlers, {}
  end

  let(:some_handler) { class_double(ActiveJob::Base) }
  let(:another_handler) { class_double(ActiveJob::Base) }
  let(:some_object) { double('Some::Object') }

  describe '.register' do
    it 'adds event to list of events' do
      described_class.register(:vote)
      expect(described_class.registered).to include(:vote)
    end

    it 'handles event names passed as a string' do
      described_class.register('vote')
      expect(described_class.registered).to include(:vote)
    end

    it 'handles multiple events' do
      described_class.register(:vote)
      described_class.register(:post, :subscribe)

      expect(described_class.registered.sort).to eq %i(vote post subscribe).sort
    end

    it 'does not add duplicates' do
      described_class.register(:vote)
      described_class.register(:vote)

      expect(described_class.registered).to eq %i(vote)
    end
  end

  describe '.subscribe' do
    before do
      described_class.register(:vote)
    end

    it 'subscribes to an event' do
      described_class.subscribe(:vote, some_handler)

      expect(described_class.handlers[:vote]).to eq [some_handler]
    end

    it 'subscribes to an event (using string)' do
      described_class.subscribe('vote', some_handler)

      expect(described_class.handlers[:vote]).to eq [some_handler]
{'fraction_non_alphanumeric': 0.10151975683890578, 'fraction_numerical': 0.00030395136778115504, 'mean_word_length': 3.735251798561151, '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': '3276338', 'n_tokens_mistral': 1007, 'n_tokens_neox': 940, 'n_words': 241}