<commit_before>require File.expand_path('../spec_helper', __FILE__)

module Danger
  describe Danger::DangerXcodeSummary do
    it 'should be a plugin' do
      expect(Danger::DangerXcodeSummary.new(nil)).to be_a Danger::Plugin
    end

    #
    # You should test your custom attributes and methods here
    #
    describe 'with Dangerfile' do
      before do
        @dangerfile = testing_dangerfile
        @xcode_summary = @dangerfile.xcode_summary
        @summary = @xcode_summary.read_summary('spec/fixtures/summary.json')
      end

      it 'fail if file don\'t exists' do
        result = @xcode_summary.read_summary('spec/fixtures/inexistent_file.json')
        # expected = [Danger::Violation.new('summary file not found', true)]
        expect(result).to be_a Array
        expect(result.count).to eq(1)
        violation = result.first
        expect(violation).to be_a Danger::Violation
        expect(violation.message).to eq('summary file not found')
        expect(violation.sticky).to be_truthy
      end

      it 'reads a json summary' do
        expect(@summary.count).to eq 10
      end
      
      it 'contains warnings' do
          diagnostic = @summary[:warnings]
          expect(diagnostic.count).to eq 0
      end

      it 'contains ld_warnings' do
        diagnostic = @summary[:ld_warnings]
        expect(diagnostic.count).to eq 0
      end

      it 'contains compile_warnings' do
        diagnostic = @summary[:compile_warnings]
        expect(diagnostic.count).to eq 1
      end

      it 'contains errors' do
        diagnostic = @summary[:errors]
        expect(diagnostic.count).to eq 0
      end

      it 'contains compile_errors' do
        diagnostic = @summary[:compile_errors]
        expect(diagnostic.count).to eq 0
      end

      it 'contains file_missing_errors' do
        diagnostic = @summary[:file_missing_errors]
        expect(diagnostic.count).to eq 0
      end

      it 'contains undefined_symbols_errors' do
        diagnostic = @summary[:undefined_symbols_errors]
        expect(diagnostic.count).to eq 0
      end

      it 'contains duplicate_symbols_errors' do
        diagnostic = @summary[:duplicate_symbols_errors]
        expect(diagnostic.count).to eq 0
      end

      it 'contains tests_failures' do
        diagnostic = @summary[:tests_failures]
        expect(diagnostic.count).to eq 0
      end

      it 'contains tests_summary_messages' do
        diagnostic = @summary[:tests_summary_messages]
        expect(diagnostic.count).to eq 1
        expect(diagnostic.first).to eq "\t Executed 4 tests, with 0 failures (0 unexpected) in 0.012 (0.017) seconds\n"
      end

      it 'format summary' do
        @xcode_summary.format_summary(@summary)<commit_msg>Added stubs<commit_after>require File.expand_path('../spec_helper', __FILE__)

module Danger
  describe Danger::DangerXcodeSummary do
    it 'should be a plugin' do
      expect(Danger::DangerXcodeSummary.new(nil)).to be_a Danger::Plugin
    end

    #
    # You should test your custom attributes and methods here
    #
    describe 'with Dangerfile' do
      before do
        @dangerfile = testing_dangerfile
        @xcode_summary = @dangerfile.xcode_summary
        @summary = @xcode_summary.read_summary('spec/fixtures/summary.json')
      end

      it 'fail if file don\'t exists' do
        result = @xcode_summary.read_summary('spec/fixtures/inexistent_file.json')
        # expected = [Danger::Violation.new('summary file not found', true)]
        expect(result).to be_a Array
        expect(result.count).to eq(1)
        violation = result.first
        expect(violation).to be_a Danger::Violation
        expect(violation.message).to eq('summary file not found')
        expect(violation.sticky).to be_truthy
      end

      it 'reads a json summary' do
        expect(@summary.count).to eq 10
      end
      
      it 'contains warnings' do
          diagnostic = @summary[:warnings]
          expect(diagnostic.count).to eq 0
      end

      it 'contains ld_warnings' do
        diagnostic = @summary[:ld_warnings]
        expect(diagnostic.count).to eq 0
      end

      it 'contains compile_warnings' do
        diagnostic = @summary[:compile_warnings]
        expect(diagnostic.count).to eq 1
      end

      it 'contains errors' do
        diagnostic = @summary[:errors]
        expect(diagnostic.count).to eq 0
      end

      it 'contains compile_errors' do
        diagnostic = @summary[:compile_errors]
        expect(diagnostic.count).to eq 0
      end

      it 'contains file_missing_errors' do
        diagnostic = @summary[:file_missing_errors]
        expect(diagnostic.count).to eq 0
      end

      it 'contains undefined_symbols_errors' do
        diagnostic = @summary[:undefined_symbols_errors]
        expect(diagnostic.count).to eq 0
      end

      it 'contains duplicate_symbols_errors' do
        diagnostic = @summary[:duplicate_symbols_errors]
        expect(diagnostic.count).to eq 0
      end

      it 'contains tests_failures' do
        diagnostic = @summary[:tests_failures]
        expect(diagnostic.count).to eq 0
      end

      it 'contains tests_summary_messages' do
        diagnostic = @summary[:tests_summary_messages]
        expect(diagnostic.count).to eq 1
        expect(diagnostic.first).to eq "\t Executed 4 tests, with 0 failures (0 unexpected) in 0.012 (0.017) seconds\n"
      end

      it 'format summary' do

        github = @dangerfile.github
        allow(github).to receive(:head_commit) { '129jef029jf029fj2039fj203f92' }
        request_source = @dangerfile.env.request_source
        allow(request_source).to receive(:pr_json) { { :head => { :repo => { :html_url => 'https://github.com/diogot/danger-xcode_summary' } } } }
        
        @xcode_summary.format_summary(@summary)
{'fraction_non_alphanumeric': 0.09156751163993793, 'fraction_numerical': 0.011381272633212623, 'mean_word_length': 2.5824583075972822, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 1, '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': '6314093', 'n_tokens_mistral': 1750, 'n_tokens_neox': 1674, 'n_words': 419}