Sha256: e6e7e3dc208b366cd8e4e8699de2019ed4474a971d873b5602bf27ba4a6bf2d2

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    describe StringLiterals do
      let(:sl) { StringLiterals.new }

      it 'registers an offence for double quotes when single quotes suffice' do
        inspect_source(sl, ['s = "abc"'])
        expect(sl.offences.map(&:message)).to eq(
          ["Prefer single-quoted strings when you don't need string " +
           'interpolation or special symbols.'])
      end

      it 'accepts double quotes when they are needed' do
        src = ['a = "\n"',
               'b = "#{encode_severity}:#{sprintf("%3d", line_number)}: #{m}"',
               'c = "\'"',
               'd = "#@test"',
               'e = "#$test"',
               'f = "#@@test"']
        inspect_source(sl, src)
        expect(sl.offences.map(&:message)).to be_empty
      end

      it 'accepts double quotes with some other special symbols' do
        pending
        # "Substitutions in double-quoted strings"
        # http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
        src = ['g = "\xf9"']
        inspect_source(sl, src)
        expect(sl.offences.map(&:message)).to be_empty
      end

      it 'can handle double quotes within embedded expression' do
        # This seems to be a Parser bug
        pending do
          src = ['"#{"A"}"']
          inspect_source(sl, src)
          expect(sl.offences.map(&:message)).to be_empty
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.8.0 spec/rubocop/cops/string_literals_spec.rb