<commit_before>require_relative 'integration_helper'

describe "Gitlactica" do
  include EventMachineHelper
  include GitHubApiHelper
  include JSONHelper

  it "given a list of repos to subscribe to, fetches them from GitHub then sends back all recent unique committers" do
    EM.run {
      Gitlactica::Application.run

      mock_github_api('localhost', 3333)

      websocket = EM::WebSocketClient.connect("ws://localhost:8080")

      websocket.callback do
        websocket.send_msg(
          to_json(
            event: "subscribe",
            data: {
              repos: ["garybernhardt/raptor"]
            }
          )
        )
      end

      websocket.stream do |json|
        EM.stop_event_loop

        from_json(json).should == {
          event: "committers",
          data: {
            repo: "garybernhardt/raptor",
            committers: [
              { login: "garybernhardt", last_commit: "2012-09-23T17:50:51Z" },
              { login: "tmiller", last_commit: "2012-09-20T04:27:46Z" },
              { login: "tcrayford", last_commit: "2012-06-09T12:57:38Z" },
              { login: "dpick", last_commit: "2012-03-18T22:02:36Z" },
              { login: "andrewhr", last_commit: "2012-03-17T00:47:32Z" }
            ]
          }
        }
      end

      fail_after(0.3, "No message received")
    }
  end
end<commit_msg>Close the WebSocket connection when a spec fails<commit_after>require_relative 'integration_helper'

describe "Gitlactica" do
  include EventMachineHelper
  include GitHubApiHelper
  include JSONHelper

  it "given a list of repos to subscribe to, fetches them from GitHub then sends back all recent unique committers" do
    EM.run {
      Gitlactica::Application.run

      mock_github_api('localhost', 3333)

      websocket = EM::WebSocketClient.connect("ws://localhost:8080")

      websocket.callback do
        websocket.send_msg(
          to_json(
            event: "subscribe",
            data: {
              repos: ["garybernhardt/raptor"]
            }
          )
        )
      end

      websocket.stream do |json|
        EM.stop_event_loop

        from_json(json).should == {
          event: "committers",
          data: {
            repo: "garybernhardt/raptor",
            committers: [
              { login: "garybernhardt", last_commit: "2012-09-23T17:50:51Z" },
              { login: "tmiller", last_commit: "2012-09-20T04:27:46Z" },
              { login: "tcrayford", last_commit: "2012-06-09T12:57:38Z" },
              { login: "dpick", last_commit: "2012-03-18T22:02:36Z" },
              { login: "andrewhr", last_commit: "2012-03-17T00:47:32Z" }
            ]
          }
        }
      end

      fail_after(0.3, "No message received") do
        websocket.close_connection
      end
    }
  end
end
{'fraction_non_alphanumeric': 0.10960371295965726, 'fraction_numerical': 0.057122456265619424, 'mean_word_length': 2.0129032258064514, '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': '7311614', 'n_tokens_mistral': 997, 'n_tokens_neox': 860, 'n_words': 181}