Sha256: 246eb681a67c445d48a9b305fb968bfa81757ccb82ac63e346d1fbdc53d07f37

Contents?: true

Size: 1.81 KB

Versions: 9

Compression:

Stored size: 1.81 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe RuboCop::Cop::Style::PredicateName, :config do
  subject(:cop) { described_class.new(config) }

  context 'with blacklisted prefices' do
    let(:cop_config) do
      { 'NamePrefix' => %w(has_ is_),
        'NamePrefixBlacklist' => %w(has_ is_) }
    end

    %w(has is).each do |prefix|
      it 'registers an offense when method name starts with known prefix' 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 method name that starts with unknown prefix' do
      inspect_source(cop, ['def have_attr',
                           '  # ...',
                           'end'])
      expect(cop.offenses).to be_empty
    end

    context 'with blacklisted prefices' do
      let(:cop_config) do
        { 'NamePrefix' => %w(has_ is_), 'NamePrefixBlacklist' => [] }
      end

      %w(has is).each do |prefix|
        it 'registers an offense when method name starts with known prefix' do
          inspect_source(cop, ["def #{prefix}_attr",
                               '  # ...',
                               'end'])
          expect(cop.offenses.size).to eq(1)
          expect(cop.messages)
            .to eq(["Rename `#{prefix}_attr` to `#{prefix}_attr?`."])
          expect(cop.highlights).to eq(["#{prefix}_attr"])
        end
      end

      it 'accepts method name that starts with unknown prefix' do
        inspect_source(cop, ['def have_attr',
                             '  # ...',
                             'end'])
        expect(cop.offenses).to be_empty
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/predicate_name_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/predicate_name_spec.rb
rubocop-0.29.1 spec/rubocop/cop/style/predicate_name_spec.rb
rubocop-0.29.0 spec/rubocop/cop/style/predicate_name_spec.rb
rubocop-0.28.0 spec/rubocop/cop/style/predicate_name_spec.rb
rubocop-0.27.1 spec/rubocop/cop/style/predicate_name_spec.rb
rubocop-0.27.0 spec/rubocop/cop/style/predicate_name_spec.rb
rubocop-0.26.1 spec/rubocop/cop/style/predicate_name_spec.rb
rubocop-0.26.0 spec/rubocop/cop/style/predicate_name_spec.rb