Sha256: 8c8f630d1e37134fc49ed1e316c7bad93b232b4849a181a9a4a29716e78d7673

Contents?: true

Size: 1.4 KB

Versions: 11

Compression:

Stored size: 1.4 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 = <<-EOS
      module Alfa
        def initialize; end
      end
    EOS

    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 = <<-EOF
      module Alfa
        def bravo; end
      end
    EOF

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

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

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

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

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

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

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
reek-4.7.3 spec/reek/smell_detectors/module_initialize_spec.rb
reek-4.7.2 spec/reek/smell_detectors/module_initialize_spec.rb
reek-4.7.1 spec/reek/smell_detectors/module_initialize_spec.rb
reek-4.7.0 spec/reek/smell_detectors/module_initialize_spec.rb
reek-4.6.2 spec/reek/smell_detectors/module_initialize_spec.rb
reek-4.6.1 spec/reek/smell_detectors/module_initialize_spec.rb
reek-4.6.0 spec/reek/smell_detectors/module_initialize_spec.rb
reek-4.5.6 spec/reek/smell_detectors/module_initialize_spec.rb
reek-4.5.5 spec/reek/smell_detectors/module_initialize_spec.rb
reek-4.5.4 spec/reek/smell_detectors/module_initialize_spec.rb
reek-4.5.3 spec/reek/smell_detectors/module_initialize_spec.rb