Sha256: 4e9671efc84fe587f9e8c63d795211d7cb623ea8e73e82721dddbdd29b4bc0f8

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    module Style
      describe ColonMethodCall do
        subject(:cop) { described_class.new }

        it 'registers an offence for instance method call' do
          inspect_source(cop,
                         ['test::method_name'])
          expect(cop.offences.size).to eq(1)
        end

        it 'registers an offence for instance method call with arg' do
          inspect_source(cop,
                         ['test::method_name(arg)'])
          expect(cop.offences.size).to eq(1)
        end

        it 'registers an offence for class method call' do
          inspect_source(cop,
                         ['Class::method_name'])
          expect(cop.offences.size).to eq(1)
        end

        it 'registers an offence for class method call with arg' do
          inspect_source(cop,
                         ['Class::method_name(arg, arg2)'])
          expect(cop.offences.size).to eq(1)
        end

        it 'does not register an offence for constant access' do
          inspect_source(cop,
                         ['Tip::Top::SOME_CONST'])
          expect(cop.offences).to be_empty
        end

        it 'does not register an offence for nested class' do
          inspect_source(cop,
                         ['Tip::Top.some_method'])
          expect(cop.offences).to be_empty
        end

        it 'does not register an offence for op methods' do
          inspect_source(cop,
                         ['Tip::Top.some_method[3]'])
          expect(cop.offences).to be_empty
        end

        it 'does not register an offence when for constructor methods' do
          inspect_source(cop,
                         ['Tip::Top(some_arg)'])
          expect(cop.offences).to be_empty
        end

        it 'auto-corrects "::" with "."' do
          new_source = autocorrect_source(cop, 'test::method')
          expect(new_source).to eq('test.method')
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.13.1 spec/rubocop/cop/style/colon_method_call_spec.rb
rubocop-0.13.0 spec/rubocop/cop/style/colon_method_call_spec.rb