Sha256: 9dce1e015ad443ea43d8655a924d3c13e481ed156cb06db1fdda0ea46f5dfcbb

Contents?: true

Size: 887 Bytes

Versions: 5

Compression:

Stored size: 887 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    describe FavorPercentR do
      let(:fpr) { FavorPercentR.new }

      it 'registers an offence for // with two slashes in regexp' do
        inspect_source(fpr, 'file.rb', ['x =~ /home\/\//',
                                        'y =~ /etc\/top\//'])
        expect(fpr.offences.map(&:message))
          .to eq([FavorPercentR::ERROR_MESSAGE] * 2)
      end

      it 'accepts // with only one slash in regexp' do
        inspect_source(fpr, 'file.rb', ['x =~ /\/home/',
                                        'y =~ /\//)'])
        expect(fpr.offences.map(&:message)).to be_empty
      end

      it 'accepts %r delimiters for regexp with two or more slashes' do
        inspect_source(fpr, 'file.rb', ['x =~ %r(/home/)'])
        expect(fpr.offences.map(&:message)).to be_empty
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-0.7.2 spec/rubocop/cops/favor_percent_r.rb
rubocop-0.7.1 spec/rubocop/cops/favor_percent_r.rb
rubocop-0.7.0 spec/rubocop/cops/favor_percent_r.rb
rubocop-0.6.1 spec/rubocop/cops/favor_percent_r.rb
rubocop-0.6.0 spec/rubocop/cops/favor_percent_r.rb