Sha256: fde31a6b3cc6fa9ea147771c3d4033954179c117727134e915d73a8a4c5fe822

Contents?: true

Size: 1.98 KB

Versions: 28

Compression:

Stored size: 1.98 KB

Contents

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

RSpec.describe Reek::SmellDetectors::TooManyStatements do
  let(:config) do
    { Reek::SmellDetectors::TooManyStatements::MAX_ALLOWED_STATEMENTS_KEY => 2 }
  end

  it 'reports the right values' do
    src = <<-EOS
      class Alfa
        def bravo
          charlie = 1
          delta   = 2
          echo    = 3
        end
      end
    EOS

    expect(src).to reek_of(:TooManyStatements,
                           lines:   [2],
                           context: 'Alfa#bravo',
                           message: 'has approx 3 statements',
                           source:  'string',
                           count:   3).with_config(config)
  end

  it 'does count all occurences' do
    src = <<-EOS
      class Alfa
        def bravo
          charlie = 1
          delta   = 2
          echo    = 3
        end

        def foxtrot
          golf  = 1
          hotel = 2
          india = 3
        end
      end
    EOS

    expect(src).
      to reek_of(:TooManyStatements, lines: [2], context: 'Alfa#bravo').with_config(config).
      and reek_of(:TooManyStatements, lines: [8], context: 'Alfa#foxtrot').with_config(config)
  end

  it 'does not report short methods' do
    src = <<-EOS
      class Alfa
        def bravo
          charlie = 1
          delta   = 2
        end
      end
    EOS

    expect(src).not_to reek_of(:TooManyStatements).with_config(config)
  end

  it 'does not report initialize' do
    src = <<-EOS
      class Alfa
        def initialize
          charlie = 1
          delta   = 2
          echo    = 3
        end
      end
    EOS

    expect(src).not_to reek_of(:TooManyStatements).with_config(config)
  end

  it 'reports long inner block' do
    src = <<-EOS
      def long
        self.each do |x|
          charlie = 1
          delta   = 2
          echo    = 3
        end
      end
    EOS

    expect(src).to reek_of(:TooManyStatements).with_config(config)
  end
end

Version data entries

28 entries across 26 versions & 2 rubygems

Version Path
reek-5.3.1 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-5.3.0 spec/reek/smell_detectors/too_many_statements_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/smell_detectors/too_many_statements_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/too_many_statements_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/smell_detectors/too_many_statements_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/too_many_statements_spec.rb
reek-5.2.0 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-5.1.0 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-5.0.2 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-5.0.1 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-5.0.0 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-4.8.2 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-4.8.1 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-4.8.0 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-4.7.3 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-4.7.2 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-4.7.1 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-4.7.0 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-4.6.2 spec/reek/smell_detectors/too_many_statements_spec.rb
reek-4.6.1 spec/reek/smell_detectors/too_many_statements_spec.rb