Sha256: 9062a3e6187f2f6ad2ea0d2ab7686da0ad4986bbcd2863baaad5ff99479e674f

Contents?: true

Size: 1008 Bytes

Versions: 2

Compression:

Stored size: 1008 Bytes

Contents

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

RSpec.describe Reek::Smells::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 'does not report with 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 'does not smell with 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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reek-4.4.2 spec/reek/smells/module_initialize_spec.rb
reek-4.4.1 spec/reek/smells/module_initialize_spec.rb