Sha256: 0ca49cd0a52b8e7d9b294de50dcce9dd50c569e082ad3e02913f3fa4cce3e095

Contents?: true

Size: 814 Bytes

Versions: 4

Compression:

Stored size: 814 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Style::PredicateName, :config do
  subject(:cop) { described_class.new(config) }
  let(:cop_config) { { 'NamePrefixBlacklist' => %w(has_ is_) } }

  %w(has is).each do |prefix|
    it 'registers an offense for blacklisted method_name' do
      inspect_source(cop, ["def #{prefix}_attr",
                           '  # ...',
                           'end'])
      expect(cop.offenses.size).to eq(1)
      expect(cop.messages).to eq(["Rename `#{prefix}_attr` to `attr?`."])
      expect(cop.highlights).to eq(["#{prefix}_attr"])
    end
  end

  it 'accepts non-blacklisted method name' do
    inspect_source(cop, ['def have_attr',
                         '  # ...',
                         'end'])
    expect(cop.offenses).to be_empty
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.22.0 spec/rubocop/cop/style/predicate_name_spec.rb
rubocop-0.21.0 spec/rubocop/cop/style/predicate_name_spec.rb
rubocop-0.20.1 spec/rubocop/cop/style/predicate_name_spec.rb
rubocop-0.20.0 spec/rubocop/cop/style/predicate_name_spec.rb