Sha256: 92c597a971cc68424a1e3983114fad25a4e4daddb07408df1fbf7a90cae8992d
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
# encoding: utf-8 require 'spec_helper' describe Rubocop::Cop::Lint::StringConversionInInterpolation do subject(:cop) { described_class.new } it 'registers an offense for #to_s in interpolation' do inspect_source(cop, '"this is the #{result.to_s}"') expect(cop.offenses.size).to eq(1) end it 'detects #to_s in an interpolation with several expressions' do inspect_source(cop, '"this is the #{top; result.to_s}"') expect(cop.offenses.size).to eq(1) end it 'accepts #to_s with arguments in an interpolation' do inspect_source(cop, '"this is a #{result.to_s(8)}"') expect(cop.offenses).to be_empty end it 'accepts interpolation without #to_s' do inspect_source(cop, '"this is the #{result}"') expect(cop.offenses).to be_empty end it 'does not explode on empty interpolation' do inspect_source(cop, '"this is #{} silly"') expect(cop.offenses).to be_empty end it 'autocorrects by removing the redundant to_s' do corrected = autocorrect_source(cop, ['"some #{something.to_s}"']) expect(corrected).to eq '"some #{something}"' end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.20.0 | spec/rubocop/cop/lint/string_conversion_in_interpolation_spec.rb |