Sha256: 50388fdc394f2fd7d21e1657f752d7dafab2b87229330022c7856b3c03d09c54

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

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

RSpec.describe Reek::SmellDetectors::ManualDispatch do
  it 'reports the right values' do
    src = <<-EOS
      class Alfa
        def bravo(charlie)
          true if charlie.respond_to?(:to_a)
        end
      end
    EOS

    expect(src).to reek_of(:ManualDispatch,
                           lines:   [3],
                           context: 'Alfa#bravo',
                           message: 'manually dispatches method call',
                           source:  'string')
  end

  it 'does count all occurences' do
    src = <<-EOS
      class Alfa
        def bravo(charlie)
          true if charlie.respond_to?(:to_a)
        end

        def delta(echo)
          true if echo.respond_to?(:to_a)
        end
      end
    EOS

    expect(src).
      to reek_of(:ManualDispatch, lines: [3], context: 'Alfa#bravo').
      and reek_of(:ManualDispatch, lines: [7], context: 'Alfa#delta')
  end

  it 'reports manual dispatch smell when using #respond_to? on implicit self' do
    src = <<-EOS
      class Alfa
        def bravo
          charlie if respond_to?(:delta)
        end
      end
    EOS

    expect(src).to reek_of(:ManualDispatch)
  end

  it 'reports manual dispatch within a conditional' do
    src = <<-EOS
      class Alfa
        def bravo
          charlie.respond_to?(:delta) && charlie.echo
        end
      end
    EOS

    expect(src).to reek_of(:ManualDispatch)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reek-4.5.4 spec/reek/smell_detectors/manual_dispatch_spec.rb
reek-4.5.3 spec/reek/smell_detectors/manual_dispatch_spec.rb
reek-4.5.2 spec/reek/smell_detectors/manual_dispatch_spec.rb
reek-4.5.1 spec/reek/smell_detectors/manual_dispatch_spec.rb
reek-4.5.0 spec/reek/smell_detectors/manual_dispatch_spec.rb