Sha256: 48a53df8b3a3a60404828de837a46a7fda85012e711d69990cd3cc6b0ac74498

Contents?: true

Size: 1.77 KB

Versions: 7

Compression:

Stored size: 1.77 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    module Style
      describe VariableInterpolation do
        let(: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.offences.map(&:message))
            .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.offences.map(&:message))
            .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.offences.map(&:message))
            .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.offences.map(&:message))
            .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

7 entries across 7 versions & 2 rubygems

Version Path
rubocop-0.12.0 spec/rubocop/cop/style/variable_interpolation_spec.rb
rubocop-0.11.1 spec/rubocop/cop/style/variable_interpolation_spec.rb
rubocop-0.11.0 spec/rubocop/cops/style/variable_interpolation_spec.rb
rubocop-0.10.0 spec/rubocop/cops/style/variable_interpolation_spec.rb
rubocop-0.9.1 spec/rubocop/cops/style/variable_interpolation_spec.rb
sabat-rubocop-0.9.0 spec/rubocop/cops/style/variable_interpolation_spec.rb
rubocop-0.9.0 spec/rubocop/cops/style/variable_interpolation_spec.rb