Sha256: 2c9274f8554c5167e5978c7d1daf9e356f829e04e8435f356dccfcaa0ba94540

Contents?: true

Size: 787 Bytes

Versions: 2

Compression:

Stored size: 787 Bytes

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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.19.1 spec/rubocop/cop/lint/string_conversion_in_interpolation_spec.rb
rubocop-0.19.0 spec/rubocop/cop/lint/string_conversion_in_interpolation_spec.rb