Sha256: f821ebcfcd3efc4864f31b574818bdfd7f66661820b28f455f9f75b42327d708
Contents?: true
Size: 1.57 KB
Versions: 4
Compression:
Stored size: 1.57 KB
Contents
# encoding: utf-8 require 'spec_helper' module Rubocop module Cop module Style describe CollectionMethods do CollectionMethods.config = { 'PreferredMethods' => { 'collect' => 'map', 'inject' => 'reduce', 'detect' => 'find', 'find_all' => 'select' } } let(:cop) { CollectionMethods.new } CollectionMethods.preferred_methods.keys.each do |method| it "registers an offence for #{method} with block" do inspect_source(cop, ["[1, 2, 3].#{method} { |e| e + 1 }"]) expect(cop.offences.size).to eq(1) preferred_method = CollectionMethods.preferred_methods[method] expect(cop.messages) .to eq(["Prefer #{preferred_method} over #{method}."]) end it "registers an offence for #{method} with proc param" do inspect_source(cop, ["[1, 2, 3].#{method}(&:test)"]) expect(cop.offences.size).to eq(1) preferred_method = CollectionMethods.preferred_methods[method] expect(cop.messages) .to eq(["Prefer #{preferred_method} over #{method}."]) end it "accepts #{method} with more than 1 param" do inspect_source(cop, ["[1, 2, 3].#{method}(other, &:test)"]) expect(cop.offences).to be_empty end it "accepts #{method} without a block" do inspect_source(cop, ["[1, 2, 3].#{method}"]) expect(cop.offences).to be_empty end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems