Sha256: a78a1e87d46ba33af4d1b6e7ae826ff199a4a229a59fa6e35e5f2148aa37cf8a

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    module Style
      describe CommentAnnotation do
        let(:cop) { CommentAnnotation.new }

        it 'registers an offence for a missing colon' do
          inspect_source(cop, ['# TODO make better'])
          expect(cop.offences).to have(1).item
        end

        context 'when used with the clang formatter' do
          let(:formatter) { Formatter::ClangStyleFormatter.new(output) }
          let(:output) { StringIO.new }

          it 'marks the annotation keyword' do
            inspect_source(cop, ['# TODO:make better'])
            formatter.report_file('t', cop.offences)
            expect(output.string).to eq(["t:1:3: C: #{CommentAnnotation::MSG}",
                                         '# TODO:make better',
                                         '  ^^^^^',
                                         ''].join("\n"))
          end
        end

        it 'registers an offence for lower case' do
          inspect_source(cop, ['# fixme: does not work'])
          expect(cop.offences).to have(1).item
        end

        it 'registers an offence for capitalized annotation keyword' do
          inspect_source(cop, ['# Optimize: does not work'])
          expect(cop.offences).to have(1).item
        end

        it 'registers an offence for upper case with colon but no note' do
          inspect_source(cop, ['# HACK:'])
          expect(cop.offences).to have(1).item
        end

        it 'accepts upper case keyword with colon, space and note' do
          inspect_source(cop, ['# REVIEW: not sure about this'])
          expect(cop.offences).to be_empty
        end

        it 'accepts upper case keyword alone' do
          inspect_source(cop, ['# OPTIMIZE'])
          expect(cop.offences).to be_empty
        end

        it 'accepts a comment that is obviously a code example' do
          inspect_source(cop, ['# Todo.destroy(1)'])
          expect(cop.offences).to be_empty
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.10.0 spec/rubocop/cops/style/comment_annotation_spec.rb