<commit_before>require 'spec_helper'
include GitStatistics
include GitStatistics::Formatters

describe Console do
  let(:verbose) {false}
  let(:limit) {100}
  let(:fresh) {true}
  let(:pretty) {false}
  let(:collector) {Collector.new(verbose, limit, fresh, pretty)}

  let(:commits) {collector.commits}

  let(:fixture_file) {"multiple_authors.json"}
  let(:save_file) { File.join(collector.commits_path, "0.json") }
  let(:email) {false}
  let(:merge) {false}
  let(:sort) {:commits}
  let(:top_n) {0}

  let(:results) {
    setup_commits(commits, fixture_file, save_file, pretty)
    commits.calculate_statistics(email, merge)
    commits.author_top_n_type(sort)
    results = Console.new(commits)
  }

  let(:config) {
    results.prepare_result_summary(sort, email, top_n)
  }

  describe "#prepare_result_summary" do
    context "with email and sorting" do
      context "on first author" do
        let(:data) {config[:data]}
        author = "<NAME>"
        subject {data[author]}

        it {data.should have_key author}

        it {subject[:commits].should == 1}
        it {subject[:additions].should == 73}
        it {subject[:deletions].should == 0}
        it {subject[:create].should == 2}

        it {subject[:languages][:Ruby][:additions].should == 62}
        it {subject[:languages][:Ruby][:deletions].should == 0}
        it {subject[:languages][:Ruby][:create].should == 1}
        it {subject[:languages][:Markdown][:additions].should == 11}
        it {subject[:languages][:Markdown][:deletions].should == 0}
        it {subject[:languages][:Markdown][:create].should == 1}
      end

      context "on second author" do
        let(:data) {config[:data]}
        author = "<NAME>"
        subject {data[author]}

        it {data.has_key?(author).should be_true}
        it {subject[:commits].should == 1}
        it {subject[:additions].should == 64}
        it {subject[:deletions].should == 16}

        it {subject[:languages][:Ruby][:additions].should == 64}
        it {subject[:languages][:Ruby][:deletions].should == 16}
      end

      it {config[:sort].should == sort}
      it {config[:email].should == email}
      it {config[:top_n].should == top_n}
      it {config[:author_length].should == 17}
      it {config[:language_length].should == 8}
    end

    context "with negative top_n" do
      let(:top_n) {-1}

      context "on first author" do
        let(:data) {config[:data]}
        author = "<NAME>"
        subject {data[author]}

        it {data.has_key?(author).should be_true}

        it {subject[:commits].should == 1}
        it {subject[:additions].should == 73}
        it {subject[:deletions].should == 0}
        it {subject[:create].should == 2}

        it {subject[:languages][:Ruby][:additions].should == 62}
        it {subject[:languages][:Ruby][:deletions].should == 0}
        it {subject[:languages][:Ruby][:create].should == 1}
        it {subject[:languages][:Markdown][:additions].should == 11}
        it {subject[:languages][:Markdown][:deletions].should == 0}
        it {subject[:languages][:Markdown][:create].should == 1}
      end

      context "on second author" do
        let(:data) {config[:data]}
        author = "<NAME>"
        subject {data[author]}

        it {data.has_key?(author).should be_true}
        it {subject[:commits].should == 1}
        it {subject[:additions].should == 64}
        it {subject[:deletions].should == 16}

        it {subject[:languages][:Ruby][:additions].should == 64}
        it {subject[:languages][:Ruby][:deletions].should == 16}
      end

      it {config[:sort].should == sort}
      it {config[:email].should == email}
      it {config[:top_n].should == 0}
      it {config[:author_length].should == 17}
      it {config[:language_length].should == 8}
    end

    context "with top_n that filters to one author" do
      let(:top_n) {1}
      let(:data) {config[:data]}
      author = "<NAME>"
      subject {data[author]}

      it {data.has_key?(author).should be_true}

      it {subject[:commits].should == 1}
      it {subject[:additions].should == 73}
      it {subject[:deletions].should == 0}
      it {subject[:create].should == 2}

      it {subject[:languages][:Ruby][:additions].should == 62}
      it {subject[:languages][:Ruby][:deletions].should == 0}
      it {subject[:languages][:Ruby][:create].should == 1}
      it {subject[:languages][:Markdown][:additions].should == 11}
      it {subject[:languages][:Markdown][:deletions].should == 0}
      it {subject[:languages][:Markdown][:create].should == 1}

      it {config[:sort].should == sort}
      it {config[:email].should == email}
      it {config[:top_n].should == top_n}
      it {config[:author_length].should == 17}
      it {config[:language_length].should == 8}
    end
  end

  describe "#print_summary" do
    context "with valid data" do
      subject {results.print_summary(sort, email)}
      it {should == fixture("summary_output.txt").read.chomp}
    end
  end

  describe "#print_language_data" do
    context "with valid data" do
      subject {results.print_language_data(config[:data]["<NAME>"])}
      it {should == fixture("language_data_output.txt").read.split("\n")}
    end
  end

  describe "#print_header" do
    context "with valid data" do
      before { results.prepare_result_summary(sort, email, top_n) }
      subject { results.print_header.join("\n") }
      it {should == fixture("header_output.txt").read.chomp}
    end
  end
<commit_msg>always prepare summary before specs<commit_after>require 'spec_helper'
include GitStatistics
include GitStatistics::Formatters

describe Console do
  let(:verbose) {false}
  let(:limit) {100}
  let(:fresh) {true}
  let(:pretty) {false}
  let(:collector) {Collector.new(verbose, limit, fresh, pretty)}

  let(:commits) {collector.commits}

  let(:fixture_file) {"multiple_authors.json"}
  let(:save_file) { File.join(collector.commits_path, "0.json") }
  let(:email) {false}
  let(:merge) {false}
  let(:sort) {:commits}
  let(:top_n) {0}

  let(:results) {
    setup_commits(commits, fixture_file, save_file, pretty)
    commits.calculate_statistics(email, merge)
    commits.author_top_n_type(sort)
    results = Console.new(commits)
  }

  let(:config) {
    results.prepare_result_summary(sort, email, top_n)
  }

  before { config }

  describe "#prepare_result_summary" do
    context "with email and sorting" do
      context "on first author" do
        let(:data) {config[:data]}
        author = "<NAME>"
        subject {data[author]}

        it {data.should have_key author}

        it {subject[:commits].should == 1}
        it {subject[:additions].should == 73}
        it {subject[:deletions].should == 0}
        it {subject[:create].should == 2}

        it {subject[:languages][:Ruby][:additions].should == 62}
        it {subject[:languages][:Ruby][:deletions].should == 0}
        it {subject[:languages][:Ruby][:create].should == 1}
        it {subject[:languages][:Markdown][:additions].should == 11}
        it {subject[:languages][:Markdown][:deletions].should == 0}
        it {subject[:languages][:Markdown][:create].should == 1}
      end

      context "on second author" do
        let(:data) {config[:data]}
        author = "<NAME>"
        subject {data[author]}

        it {data.has_key?(author).should be_true}
        it {subject[:commits].should == 1}
        it {subject[:additions].should == 64}
        it {subject[:deletions].should == 16}

        it {subject[:languages][:Ruby][:additions].should == 64}
        it {subject[:languages][:Ruby][:deletions].should == 16}
      end

      it {config[:sort].should == sort}
      it {config[:email].should == email}
      it {config[:top_n].should == top_n}
      it {config[:author_length].should == 17}
      it {config[:language_length].should == 8}
    end

    context "with negative top_n" do
      let(:top_n) {-1}

      context "on first author" do
        let(:data) {config[:data]}
        author = "<NAME>"
        subject {data[author]}

        it {data.has_key?(author).should be_true}

        it {subject[:commits].should == 1}
        it {subject[:additions].should == 73}
        it {subject[:deletions].should == 0}
        it {subject[:create].should == 2}

        it {subject[:languages][:Ruby][:additions].should == 62}
        it {subject[:languages][:Ruby][:deletions].should == 0}
        it {subject[:languages][:Ruby][:create].should == 1}
        it {subject[:languages][:Markdown][:additions].should == 11}
        it {subject[:languages][:Markdown][:deletions].should == 0}
        it {subject[:languages][:Markdown][:create].should == 1}
      end

      context "on second author" do
        let(:data) {config[:data]}
        author = "<NAME>"
        subject {data[author]}

        it {data.has_key?(author).should be_true}
        it {subject[:commits].should == 1}
        it {subject[:additions].should == 64}
        it {subject[:deletions].should == 16}

        it {subject[:languages][:Ruby][:additions].should == 64}
        it {subject[:languages][:Ruby][:deletions].should == 16}
      end

      it {config[:sort].should == sort}
      it {config[:email].should == email}
      it {config[:top_n].should == 0}
      it {config[:author_length].should == 17}
      it {config[:language_length].should == 8}
    end

    context "with top_n that filters to one author" do
      let(:top_n) {1}
      let(:data) {config[:data]}
      author = "<NAME>"
      subject {data[author]}

      it {data.has_key?(author).should be_true}

      it {subject[:commits].should == 1}
      it {subject[:additions].should == 73}
      it {subject[:deletions].should == 0}
      it {subject[:create].should == 2}

      it {subject[:languages][:Ruby][:additions].should == 62}
      it {subject[:languages][:Ruby][:deletions].should == 0}
      it {subject[:languages][:Ruby][:create].should == 1}
      it {subject[:languages][:Markdown][:additions].should == 11}
      it {subject[:languages][:Markdown][:deletions].should == 0}
      it {subject[:languages][:Markdown][:create].should == 1}

      it {config[:sort].should == sort}
      it {config[:email].should == email}
      it {config[:top_n].should == top_n}
      it {config[:author_length].should == 17}
      it {config[:language_length].should == 8}
    end
  end

  describe "#print_summary" do
    context "with valid data" do
      subject {results.print_summary(sort, email)}
      it {should == fixture("summary_output.txt").read.chomp}
    end
  end

  describe "#print_language_data" do
    context "with valid data" do
      subject {results.print_language_data(config[:data]["<NAME>"])}
      it {should == fixture("language_data_output.txt").read.split("\n")}
    end
  end

  describe "#print_header" do
    context "with valid data" do
      subject { results.print_header.join("\n") }
      it {should == fixture("header_output.txt").read.chomp}
    end
  end

{'fraction_non_alphanumeric': 0.1681140872108968, 'fraction_numerical': 0.013529573087119481, 'mean_word_length': 3.1392357169882708, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '904469', 'n_tokens_mistral': 3690, 'n_tokens_neox': 3433, 'n_words': 736}