Sha256: 806dd8d2eb4b1a5d670dd085cdb8c8f9e714ee48381b7ff74f6bca6fc4c13bd6

Contents?: true

Size: 1.69 KB

Versions: 14

Compression:

Stored size: 1.69 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 'reports nothing for a method named initialize in a nested dynamic class' do
    src = <<-EOF
      module Alfa
        def self.bravo
          Class.new do
            def initialize; end
          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

14 entries across 12 versions & 2 rubygems

Version Path
reek-5.3.1 spec/reek/smell_detectors/module_initialize_spec.rb
reek-5.3.0 spec/reek/smell_detectors/module_initialize_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/smell_detectors/module_initialize_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/smell_detectors/module_initialize_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/smell_detectors/module_initialize_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/smell_detectors/module_initialize_spec.rb
reek-5.2.0 spec/reek/smell_detectors/module_initialize_spec.rb
reek-5.1.0 spec/reek/smell_detectors/module_initialize_spec.rb
reek-5.0.2 spec/reek/smell_detectors/module_initialize_spec.rb
reek-5.0.1 spec/reek/smell_detectors/module_initialize_spec.rb
reek-5.0.0 spec/reek/smell_detectors/module_initialize_spec.rb
reek-4.8.2 spec/reek/smell_detectors/module_initialize_spec.rb
reek-4.8.1 spec/reek/smell_detectors/module_initialize_spec.rb
reek-4.8.0 spec/reek/smell_detectors/module_initialize_spec.rb