spec/rubocop/cops/style/string_literals_spec.rb in rubocop-0.9.1 vs spec/rubocop/cops/style/string_literals_spec.rb in rubocop-0.10.0

- old
+ new

@@ -4,18 +4,18 @@ module Rubocop module Cop module Style describe StringLiterals do - let(:sl) { StringLiterals.new } + let(:cop) { StringLiterals.new } it 'registers offence for double quotes when single quotes suffice' do - inspect_source(sl, ['s = "abc"', + inspect_source(cop, ['s = "abc"', 'x = "a\\\\b"', 'y ="\\\\b"', 'z = "a\\\\"']) - expect(sl.offences.size).to eq(4) + expect(cop.offences.size).to eq(4) end it 'accepts double quotes when they are needed' do src = ['a = "\n"', 'b = "#{encode_severity}:' + @@ -23,39 +23,44 @@ 'c = "\'"', 'd = "#@test"', 'e = "#$test"', 'f = "\e"', 'g = "#@@test"'] - inspect_source(sl, src) - expect(sl.offences).to be_empty + inspect_source(cop, src) + expect(cop.offences).to be_empty end it 'accepts double quotes at the start of regexp literals' do - inspect_source(sl, ['s = /"((?:[^\\"]|\\.)*)"/']) - expect(sl.offences).to be_empty + inspect_source(cop, ['s = /"((?:[^\\"]|\\.)*)"/']) + expect(cop.offences).to be_empty end it 'accepts double quotes with some other special symbols' do # "Substitutions in double-quoted strings" # http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html src = ['g = "\xf9"', 'copyright = "\u00A9"'] - inspect_source(sl, src) - expect(sl.offences).to be_empty + inspect_source(cop, src) + expect(cop.offences).to be_empty end it 'can handle double quotes within embedded expression' do src = ['"#{"A"}"'] - inspect_source(sl, src) - expect(sl.offences).to be_empty + inspect_source(cop, src) + expect(cop.offences).to be_empty end it 'can handle a built-in constant parsed as string' do # Parser will produce str nodes for constants such as __FILE__. src = ['if __FILE__ == $PROGRAM_NAME', 'end'] - inspect_source(sl, src) - expect(sl.offences).to be_empty + inspect_source(cop, src) + expect(cop.offences).to be_empty + end + + it 'auto-corrects " with \'' do + new_source = autocorrect_source(cop, 's = "abc"') + expect(new_source).to eq("s = 'abc'") end end end end end