Sha256: 4ac8cb88f986c7f3bb425a3d7f856fc6c31fb5948dc25aa4e7adebf8d05d56a4

Contents?: true

Size: 1.45 KB

Versions: 3

Compression:

Stored size: 1.45 KB

Contents

# encoding: utf-8

require 'spec_helper'
require 'stringio'
require 'tempfile'

module Rubocop
  module Formatter
    describe OffenceCountFormatter do
      subject(:formatter) { Formatter::OffenceCountFormatter.new(output) }
      let(:output) { StringIO.new }

      let(:files) do
        %w(lib/rubocop.rb spec/spec_helper.rb bin/rubocop).map do |path|
          File.expand_path(path)
        end
      end

      describe '#file_finished' do
        before { formatter.started(files) }

        let(:finish) { formatter.file_finished(files.first, offences) }

        context 'when no offences are detected' do
          let(:offences) { [] }
          it 'shouldn\'t add to offence_counts' do
            expect { finish }.to_not change { formatter.offence_counts }
          end
        end

        context 'when any offences are detected' do
          let(:offences) { [double('offence', cop_name: 'OffendedCop')] }
          it 'should increment the count for the cop in offence_counts' do
            expect { finish }.to change { formatter.offence_counts }
          end
        end
      end

      describe '#report_summary' do
        context 'when a offence detected' do
          let(:cop_counts) { { 'OffendedCop' => 1 } }
          it 'shows the cop and the offence count' do
            formatter.report_summary(1, cop_counts)
            expect(output.string).to include(
              "\n1  OffendedCop")
          end
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.13.1 spec/rubocop/formatter/offence_count_formatter_spec.rb
rubocop-0.13.0 spec/rubocop/formatter/offence_count_formatter_spec.rb
rubocop-0.12.0 spec/rubocop/formatter/offence_count_formatter_spec.rb