Sha256: 9b873885f5c2867f684c877fdccf6c0bc92bbdf393d23f9fd89041ebbf614dc5
Contents?: true
Size: 1.27 KB
Versions: 4
Compression:
Stored size: 1.27 KB
Contents
# encoding: utf-8 require 'spec_helper' describe Rubocop::Cop::Style::DeprecatedHashMethods do subject(:cop) { described_class.new } it 'registers an offense for has_key? with one arg' do inspect_source(cop, ['o.has_key?(o)']) expect(cop.offenses.size).to eq(1) expect(cop.messages) .to eq(['`Hash#has_key?` is deprecated in favor of `Hash#key?`.']) end it 'accepts has_key? with no args' do inspect_source(cop, ['o.has_key?']) expect(cop.offenses).to be_empty end it 'registers an offense for has_value? with one arg' do inspect_source(cop, ['o.has_value?(o)']) expect(cop.offenses.size).to eq(1) expect(cop.messages) .to eq(['`Hash#has_value?` is deprecated in favor of `Hash#value?`.']) end it 'accepts has_value? with no args' do inspect_source(cop, ['o.has_value?']) expect(cop.offenses).to be_empty end it 'auto-corrects has_key? with key?' do new_source = autocorrect_source(cop, 'hash.has_key?(:test)') expect(new_source).to eq('hash.key?(:test)') end it 'auto-corrects has_value? with value?' do new_source = autocorrect_source(cop, 'hash.has_value?(value)') expect(new_source).to eq('hash.value?(value)') end end
Version data entries
4 entries across 4 versions & 1 rubygems