Sha256: f042f3beb5540e909a65e7e3c1eb96319c956284f356407d8965a22e57ff2fcf

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Style::HashMethods 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(['has_key? is deprecated in favor of 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(['has_value? is deprecated in favor of 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

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.19.1 spec/rubocop/cop/style/hash_methods_spec.rb
rubocop-0.19.0 spec/rubocop/cop/style/hash_methods_spec.rb