Sha256: 1e803ee3c8850123be1af1ebcf1aa0aa8e53bd6e581c250a4cd5956b91d0cce6

Contents?: true

Size: 1.7 KB

Versions: 9

Compression:

Stored size: 1.7 KB

Contents

require_relative '../../spec_helper'
require_lib 'reek/smell_detectors/module_initialize'

RSpec.describe Reek::SmellDetectors::ModuleInitialize do
  it 'reports the right values' do
    src = <<-RUBY
      module Alfa
        def initialize; end
      end
    RUBY

    expect(src).to reek_of(:ModuleInitialize,
                           lines:   [1],
                           context: 'Alfa',
                           message: 'has initialize method',
                           source:  'string')
  end

  it 'reports nothing for a method with a different name' do
    src = <<-RUBY
      module Alfa
        def bravo; end
      end
    RUBY

    expect(src).not_to reek_of(:ModuleInitialize)
  end

  it 'reports nothing for a method named initialize in a nested class' do
    src = <<-RUBY
      module Alfa
        class Bravo
          def initialize; end
        end
      end
    RUBY

    expect(src).not_to reek_of(:ModuleInitialize)
  end

  it 'reports nothing for a method named initialize in a nested struct' do
    src = <<-RUBY
      module Alfa
        Bravo = Struct.new(:charlie) do
          def initialize; end
        end
      end
    RUBY

    expect(src).not_to reek_of(:ModuleInitialize)
  end

  it 'reports nothing for a method named initialize in a nested dynamic class' do
    src = <<-RUBY
      module Alfa
        def self.bravo
          Class.new do
            def initialize; end
          end
        end
      end
    RUBY

    expect(src).not_to reek_of(:ModuleInitialize)
  end

  it 'can be disabled via comment' do
    src = <<-RUBY
      # :reek:ModuleInitialize
      module Alfa
        def initialize; end
      end
    RUBY

    expect(src).not_to reek_of(:ModuleInitialize)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
reek-6.0.3 spec/reek/smell_detectors/module_initialize_spec.rb
reek-6.0.2 spec/reek/smell_detectors/module_initialize_spec.rb
reek-6.0.1 spec/reek/smell_detectors/module_initialize_spec.rb
reek-6.0.0 spec/reek/smell_detectors/module_initialize_spec.rb
reek-5.6.0 spec/reek/smell_detectors/module_initialize_spec.rb
reek-5.5.0 spec/reek/smell_detectors/module_initialize_spec.rb
reek-5.4.1 spec/reek/smell_detectors/module_initialize_spec.rb
reek-5.4.0 spec/reek/smell_detectors/module_initialize_spec.rb
reek-5.3.2 spec/reek/smell_detectors/module_initialize_spec.rb