<commit_before>require "spec_helper"

describe PusherFake::Server::Application, ".call" do
  let(:data)         { mock }
  let(:event)        { mock }
  let(:channel)      { stub(emit: nil) }
  let(:response)     { mock }
  let(:environment)  { mock }
  let(:channel_name) { mock }

  subject { PusherFake::Server::Application }

  before do
    subject.stubs(channel: channel_name, data: data, event: event)
    PusherFake::Channel.stubs(factory: channel)
    response.stubs(finish: response)
    Rack::Response.stubs(new: response)
  end

  it "assigns the environment" do
    subject.call(environment)
    subject.environment.should == environment
  end

  it "creates the channel by name" do
    subject.call(environment)
    PusherFake::Channel.should have_received(:factory).with(channel_name)
  end

  it "emits the event to the channel" do
    subject.call(environment)
    channel.should have_received(:emit).with(event, data)
  end

  it "creates a Rack response" do
    subject.call(environment)
    Rack::Response.should have_received(:new).with("{}")
  end

  it "finishes the response" do
    subject.call(environment)
    response.should have_received(:finish).with()
  end

  it "returns the response" do
    subject.call(environment).should == response
  end
end

describe PusherFake::Server::Application, ".channel" do
  let(:path)    { "/apps/PUSHER_APP_ID/channels/#{channel}/events" }
  let(:channel) { "channel-name" }

  subject { PusherFake::Server::Application }
<commit_msg>Improve test description for server creating a Rack response.<commit_after>require "spec_helper"

describe PusherFake::Server::Application, ".call" do
  let(:data)         { mock }
  let(:event)        { mock }
  let(:channel)      { stub(emit: nil) }
  let(:response)     { mock }
  let(:environment)  { mock }
  let(:channel_name) { mock }

  subject { PusherFake::Server::Application }

  before do
    subject.stubs(channel: channel_name, data: data, event: event)
    PusherFake::Channel.stubs(factory: channel)
    response.stubs(finish: response)
    Rack::Response.stubs(new: response)
  end

  it "assigns the environment" do
    subject.call(environment)
    subject.environment.should == environment
  end

  it "creates the channel by name" do
    subject.call(environment)
    PusherFake::Channel.should have_received(:factory).with(channel_name)
  end

  it "emits the event to the channel" do
    subject.call(environment)
    channel.should have_received(:emit).with(event, data)
  end

  it "creates a Rack response with an empty JSON object" do
    subject.call(environment)
    Rack::Response.should have_received(:new).with("{}")
  end

  it "finishes the response" do
    subject.call(environment)
    response.should have_received(:finish).with()
  end

  it "returns the response" do
    subject.call(environment).should == response
  end
end

describe PusherFake::Server::Application, ".channel" do
  let(:path)    { "/apps/PUSHER_APP_ID/channels/#{channel}/events" }
  let(:channel) { "channel-name" }

  subject { PusherFake::Server::Application }

{'fraction_non_alphanumeric': 0.12199089134677944, 'fraction_numerical': 0.0, 'mean_word_length': 3.92, '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': '6431799', 'n_tokens_mistral': 963, 'n_tokens_neox': 943, 'n_words': 227}