<commit_before>require 'spec_helper'

describe Pubsubstub::Channel do
  let(:pubsub) { double(Pubsubstub::RedisPubSub, publish: true, subscribe: true, unsubscribe: true) }
  subject { Pubsubstub::Channel.new("test") }
  before { allow(subject).to receive(:pubsub) { pubsub } }

  context "#initialize" do
    it "does not subscribe immediately" do
      expect(pubsub).not_to receive(:subscribe)
      Pubsubstub::Channel.new('test')
    end
  end

  context "#subscribe" do
    let(:connection) { double('connection') }
    it "subscribes the client" do
      subject.subscribe(connection)
      expect(subject.subscribed?(connection)).to be_true
    end

    it "starts subscribing to the channel if it's the first client" do
      expect(pubsub).to receive(:subscribe)
      subject.subscribe(connection)
    end

    it "does not starts subscribing to the channel if it's not the first client" do
      subject.subscribe(connection)
      expect(pubsub).not_to receive(:subscribe)
      subject.subscribe(double('connection'))
    end

    it "sends the scrollback if a last_event_id is passed" do
      event = Pubsubstub::Event.new("event")
      expect(pubsub).to receive(:scrollback).with(1234).and_yield(event)
      expect(connection).to receive(:<<).with(event.to_message)
      subject.subscribe(connection, last_event_id: 1234)
    end
  end

  context "#unsubscribe" do
    let(:connection) { double('connection') }
    before { subject.subscribe(connection) }

    it "unsubscribes the client" do
      expect(subject.subscribed?(connection)).to be_true
      subject.unsubscribe(connection)
      expect(subject.subscribed?(connection)).to be_false
    end

    it "does not stop listening if it's not the last client" do
      subject.subscribe(double('connection'))
      expect(pubsub).not_to receive(:unsubscribe)
      subject.unsubscribe(connection)
    end

    it "stops listening if it's the last client" do
      expect(pubsub).to receive(:unsubscribe)
      subject.unsubscribe(connection)
    end<commit_msg>Fix RSpec deprecation warnings<commit_after>require 'spec_helper'

describe Pubsubstub::Channel do
  let(:pubsub) { double(Pubsubstub::RedisPubSub, publish: true, subscribe: true, unsubscribe: true) }
  subject { Pubsubstub::Channel.new("test") }
  before { allow(subject).to receive(:pubsub) { pubsub } }

  context "#initialize" do
    it "does not subscribe immediately" do
      expect(pubsub).not_to receive(:subscribe)
      Pubsubstub::Channel.new('test')
    end
  end

  context "#subscribe" do
    let(:connection) { double('connection') }
    it "subscribes the client" do
      subject.subscribe(connection)
      expect(subject.subscribed?(connection)).to be true
    end

    it "starts subscribing to the channel if it's the first client" do
      expect(pubsub).to receive(:subscribe)
      subject.subscribe(connection)
    end

    it "does not starts subscribing to the channel if it's not the first client" do
      subject.subscribe(connection)
      expect(pubsub).not_to receive(:subscribe)
      subject.subscribe(double('connection'))
    end

    it "sends the scrollback if a last_event_id is passed" do
      event = Pubsubstub::Event.new("event")
      expect(pubsub).to receive(:scrollback).with(1234).and_yield(event)
      expect(connection).to receive(:<<).with(event.to_message)
      subject.subscribe(connection, last_event_id: 1234)
    end
  end

  context "#unsubscribe" do
    let(:connection) { double('connection') }
    before { subject.subscribe(connection) }

    it "unsubscribes the client" do
      expect(subject.subscribed?(connection)).to be true
      subject.unsubscribe(connection)
      expect(subject.subscribed?(connection)).to be false
    end

    it "does not stop listening if it's not the last client" do
      subject.subscribe(double('connection'))
      expect(pubsub).not_to receive(:unsubscribe)
      subject.unsubscribe(connection)
    end

    it "stops listening if it's the last client" do
      expect(pubsub).to receive(:unsubscribe)
      subject.unsubscribe(connection)
    end
{'fraction_non_alphanumeric': 0.10760577158229397, 'fraction_numerical': 0.003912937148447053, 'mean_word_length': 3.7724620770128356, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3353251', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1160, 'n_words': 309}