Sha256: 7136190790fb4e2e5176ccce1ef3851000fa24c6e804e1453ea527cd7fefa321

Contents?: true

Size: 921 Bytes

Versions: 11

Compression:

Stored size: 921 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe RuboCop::Cop::Style::CharacterLiteral do
  subject(:cop) { described_class.new }

  it 'registers an offense for character literals' do
    inspect_source(cop, ['x = ?x'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'registers an offense for literals like \n' do
    inspect_source(cop, ['x = ?\n'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'accepts literals like ?\C-\M-d' do
    inspect_source(cop, ['x = ?\C-\M-d'])
    expect(cop.offenses).to be_empty
  end

  it 'accepts ? in a %w literal' do
    inspect_source(cop, ['%w{? A}'])
    expect(cop.offenses).to be_empty
  end

  it "auto-corrects ?x to 'x'" do
    new_source = autocorrect_source(cop, 'x = ?x')
    expect(new_source).to eq("x = 'x'")
  end

  it 'auto-corrects ?\n to "\\n"' do
    new_source = autocorrect_source(cop, 'x = ?\n')
    expect(new_source).to eq('x = "\\n"')
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/character_literal_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.28.0 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.27.1 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.27.0 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.26.1 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.26.0 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.25.0 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.24.1 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.24.0 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.23.0 spec/rubocop/cop/style/character_literal_spec.rb