Sha256: f5b23f8e747a8647af3a7fece1e0dfdb532f5f81e9be019ada66ff45e73e794d

Contents?: true

Size: 1.45 KB

Versions: 3

Compression:

Stored size: 1.45 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

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

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

        it 'accepts encoding on first line', ruby: 1.9 do
          inspect_source(encoding, ['# 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, ['#!/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, ['def foo() end',
                                    '# encoding: utf-8'])

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

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

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

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
rubocop-0.9.1 spec/rubocop/cops/style/encoding_spec.rb
sabat-rubocop-0.9.0 spec/rubocop/cops/style/encoding_spec.rb
rubocop-0.9.0 spec/rubocop/cops/style/encoding_spec.rb