Sha256: a778663254c8110da66ee0e2d064fd48320bb11513cc28035a27e80414420954

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    describe FavorSprintf do
      let(:fs) { FavorSprintf.new }

      it 'registers an offence for a string followed by something' do
        inspect_source(fs,
                       ['puts "%d" % 10'])
        expect(fs.offences.size).to eq(1)
        expect(fs.offences.map(&:message))
          .to eq([FavorSprintf::MSG])
      end

      it 'registers an offence for something followed by an array' do
        inspect_source(fs,
                       ['puts x % [10, 11]'])
        expect(fs.offences.size).to eq(1)
        expect(fs.offences.map(&:message))
          .to eq([FavorSprintf::MSG])
      end

      it 'does not register an offence for numbers' do
        inspect_source(fs,
                       ['puts 10 % 4'])
        expect(fs.offences).to be_empty
      end

      it 'does not register an offence for ambiguous cases' do
        inspect_source(fs,
                       ['puts x % 4'])
        expect(fs.offences).to be_empty

        inspect_source(fs,
                       ['puts x % Y'])
        expect(fs.offences).to be_empty
      end

      it 'works if the first operand contains embedded expressions' do
        inspect_source(fs,
                       ['puts "#{x * 5} %d #{@test}" % 10'])
        expect(fs.offences.size).to eq(1)
        expect(fs.offences.map(&:message))
          .to eq([FavorSprintf::MSG])
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.8.3 spec/rubocop/cops/favor_sprintf_spec.rb
rubocop-0.8.2 spec/rubocop/cops/favor_sprintf_spec.rb
rubocop-0.8.1 spec/rubocop/cops/favor_sprintf_spec.rb
rubocop-0.8.0 spec/rubocop/cops/favor_sprintf_spec.rb