Sha256: 2c332587b9c0ee97ef6f66f5b2c981b0a0eb76e827fb935090349221ab72e9ec

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    module Style
      describe VariableInterpolation do
        subject(:vi) { VariableInterpolation.new }

        it 'registers an offence for interpolated global variables' do
          inspect_source(vi,
                         ['puts "this is a #$test"'])
          expect(vi.offences.size).to eq(1)
          expect(vi.messages)
            .to eq(['Replace interpolated var $test' +
              ' with expression #{$test}.'])
        end

        it 'registers an offence for interpolated regexp back references' do
          inspect_source(vi,
                         ['puts "this is a #$1"'])
          expect(vi.offences.size).to eq(1)
          expect(vi.messages)
            .to eq(['Replace interpolated var $1 with expression #{$1}.'])
        end

        it 'registers an offence for interpolated instance variables' do
          inspect_source(vi,
                         ['puts "this is a #@test"'])
          expect(vi.offences.size).to eq(1)
          expect(vi.messages)
            .to eq(['Replace interpolated var @test' +
              ' with expression #{@test}.'])
        end

        it 'registers an offence for interpolated class variables' do
          inspect_source(vi,
                         ['puts "this is a #@@t"'])
          expect(vi.offences.size).to eq(1)
          expect(vi.messages)
            .to eq(['Replace interpolated var @@t with expression #{@@t}.'])
        end

        it 'does not register an offence for variables in expressions' do
          inspect_source(vi,
                         ['puts "this is a #{@test} #{@@t} #{$t} #{$1}"'])
          expect(vi.offences).to be_empty
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.13.1 spec/rubocop/cop/style/variable_interpolation_spec.rb
rubocop-0.13.0 spec/rubocop/cop/style/variable_interpolation_spec.rb