Sha256: bd745b7dd033aaf3b0c5048c3e919651db5cf18c9f5bad2d6195f18ae882a05b

Contents?: true

Size: 957 Bytes

Versions: 6

Compression:

Stored size: 957 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Style::AsciiIdentifiers do
  subject(:cop) { described_class.new }

  it 'registers an offense for a variable name with non-ascii chars' do
    inspect_source(cop,
                   ['# encoding: utf-8',
                    'älg = 1'])
    expect(cop.offenses.size).to eq(1)
    expect(cop.messages)
      .to eq(['Use only ascii symbols in identifiers.'])
  end

  it 'accepts identifiers with only ascii chars' do
    inspect_source(cop,
                   ['x.empty?'])
    expect(cop.offenses).to be_empty
  end

  it 'does not get confused by a byte order mark' do
    bom = "\xef\xbb\xbf"
    inspect_source(cop,
                   [bom + '# encoding: utf-8',
                    "puts 'foo'"])
    expect(cop.offenses).to be_empty
  end

  it 'does not get confused by an empty file' do
    inspect_source(cop,
                   [''])
    expect(cop.offenses).to be_empty
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.22.0 spec/rubocop/cop/style/ascii_identifiers_spec.rb
rubocop-0.21.0 spec/rubocop/cop/style/ascii_identifiers_spec.rb
rubocop-0.20.1 spec/rubocop/cop/style/ascii_identifiers_spec.rb
rubocop-0.20.0 spec/rubocop/cop/style/ascii_identifiers_spec.rb
rubocop-0.19.1 spec/rubocop/cop/style/ascii_identifiers_spec.rb
rubocop-0.19.0 spec/rubocop/cop/style/ascii_identifiers_spec.rb