Sha256: 9d10d12706409e3fe2d7f82d3f88c6b4dd3dc1b59f9935049381543e220cfadc

Contents?: true

Size: 1.99 KB

Versions: 9

Compression:

Stored size: 1.99 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 = <<-RUBY
      class Alfa
        def bravo
          charlie = 1
          delta   = 2
          echo    = 3
        end
      end
    RUBY

    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 = <<-RUBY
      class Alfa
        def bravo
          charlie = 1
          delta   = 2
          echo    = 3
        end

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

    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 = <<-RUBY
      class Alfa
        def bravo
          charlie = 1
          delta   = 2
        end
      end
    RUBY

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

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

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

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

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

Version data entries

9 entries across 9 versions & 1 rubygems

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