Sha256: 4816703a7c17a4a8ea7f70b3a454ae673d26a68fe7e75e392b0f8076cf7a87d2

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    module Style
      describe ClassMethods do
        subject(:cm) { ClassMethods.new }

        it 'registers an offence for methods using a class name' do
          inspect_source(cm,
                         ['class Test',
                          '  def Test.some_method',
                          '    do_something',
                          '  end',
                          'end'])
          expect(cm.offences.size).to eq(1)
        end

        it 'registers an offence for methods using a module name' do
          inspect_source(cm,
                         ['module Test',
                          '  def Test.some_method',
                          '    do_something',
                          '  end',
                          'end'])
          expect(cm.offences.size).to eq(1)
        end

        it 'does not register an offence for methods using self' do
          inspect_source(cm,
                         ['module Test',
                          '  def self.some_method',
                          '    do_something',
                          '  end',
                          'end'])
          expect(cm.offences).to be_empty
        end

        it 'does not register an offence outside class/module bodies' do
          inspect_source(cm,
                         ['def self.some_method',
                          '  do_something',
                          'end'])
          expect(cm.offences).to be_empty
        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/class_methods_spec.rb
rubocop-0.13.0 spec/rubocop/cop/style/class_methods_spec.rb