Sha256: a020d8037cf98481e140bfb7b764230566d4cdd19ee9e5137ece3e65978adc67

Contents?: true

Size: 1.45 KB

Versions: 8

Compression:

Stored size: 1.45 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    describe Encoding do
      let(:encoding) { Encoding.new }

      it 'registers an offence when no encoding present', ruby: 1.9 do
        inspect_source(encoding, 'file.rb', ['def foo() end'])

        expect(encoding.offences.map(&:message)).to eq(
          ['Missing encoding comment.'])
      end

      it 'accepts encoding on first line', ruby: 1.9 do
        inspect_source(encoding, 'file.rb', ['# encoding: utf-8',
                                             'def foo() end'])

        expect(encoding.offences).to be_empty
      end

      it 'accepts encoding on second line when shebang present', ruby: 1.9 do
        inspect_source(encoding, 'file.rb', ['#!/usr/bin/env ruby',
                                             '# encoding: utf-8',
                                             'def foo() end'])

        expect(encoding.offences.map(&:message)).to be_empty
      end

      it 'books an offence when encoding is in the wrong place', ruby: 1.9 do
        inspect_source(encoding, 'file.rb', ['def foo() end',
                                             '# encoding: utf-8'])

        expect(encoding.offences.map(&:message)).to eq(
          ['Missing encoding comment.'])
      end

      it 'does not register an offence on Ruby 2.0', ruby: 2.0 do
        inspect_source(encoding, 'file.rb', ['def foo() end'])

        expect(encoding.offences).to be_empty
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rubocop-0.5.0 spec/rubocop/cops/encoding_spec.rb
rubocop-0.4.6 spec/rubocop/cops/encoding_spec.rb
rubocop-0.4.5 spec/rubocop/cops/encoding_spec.rb
rubocop-0.4.4 spec/rubocop/cops/encoding_spec.rb
rubocop-0.4.3 spec/rubocop/cops/encoding_spec.rb
rubocop-0.4.2 spec/rubocop/cops/encoding_spec.rb
rubocop-0.4.1 spec/rubocop/cops/encoding_spec.rb
rubocop-0.4.0 spec/rubocop/cops/encoding_spec.rb