Sha256: 1f4aa6e48635139552fab76db1f1dc318d5caae20900019557f27f5a8d880b8d

Contents?: true

Size: 1.2 KB

Versions: 13

Compression:

Stored size: 1.2 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    describe CollectionMethods do
      let(:cm) { CollectionMethods.new }

      it 'registers an offence for collect' do
        inspect_source(cm, 'file.rb', ['[1, 2, 3].collect { |e| e + 1 }'])
        expect(cm.offences.size).to eq(1)
        expect(cm.offences.map(&:message))
          .to eq(['Prefer map over collect.'])
      end

      it 'registers an offence for inject' do
        inspect_source(cm, 'file.rb', ['[1, 2, 3].inject { |e| e + 1 }'])
        expect(cm.offences.size).to eq(1)
        expect(cm.offences.map(&:message))
          .to eq(['Prefer reduce over inject.'])
      end

      it 'registers an offence for detect' do
        inspect_source(cm, 'file.rb', ['[1, 2, 3].detect { |e| e + 1 }'])
        expect(cm.offences.size).to eq(1)
        expect(cm.offences.map(&:message))
          .to eq(['Prefer find over detect.'])
      end

      it 'registers an offence for find_all' do
        inspect_source(cm, 'file.rb', ['[1, 2, 3].find_all { |e| e + 1 }'])
        expect(cm.offences.size).to eq(1)
        expect(cm.offences.map(&:message))
          .to eq(['Prefer select over find_all.'])
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rubocop-0.7.2 spec/rubocop/cops/collection_methods_spec.rb
rubocop-0.7.1 spec/rubocop/cops/collection_methods_spec.rb
rubocop-0.7.0 spec/rubocop/cops/collection_methods_spec.rb
rubocop-0.6.1 spec/rubocop/cops/collection_methods_spec.rb
rubocop-0.6.0 spec/rubocop/cops/collection_methods_spec.rb
rubocop-0.5.0 spec/rubocop/cops/collection_methods_spec.rb
rubocop-0.4.6 spec/rubocop/cops/collection_methods_spec.rb
rubocop-0.4.5 spec/rubocop/cops/collection_methods_spec.rb
rubocop-0.4.4 spec/rubocop/cops/collection_methods_spec.rb
rubocop-0.4.3 spec/rubocop/cops/collection_methods_spec.rb
rubocop-0.4.2 spec/rubocop/cops/collection_methods_spec.rb
rubocop-0.4.1 spec/rubocop/cops/collection_methods_spec.rb
rubocop-0.4.0 spec/rubocop/cops/collection_methods_spec.rb