Sha256: b3fb81ab4fc241bb8bed914945ada570c679e2372e82ad9b4ac35c06b6381418

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

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

RSpec.describe Reek::SmellDetectors::MissingSafeMethod do
  it 'reports the right values' do
    src = <<-RUBY
      class Alfa
        def bravo!
        end
      end
    RUBY

    expect(src).to reek_of(:MissingSafeMethod,
                           lines:   [2],
                           context: 'Alfa',
                           message: "has missing safe method 'bravo!'",
                           source:  'string',
                           name:    'bravo!')
  end

  it 'does count all occurences' do
    src = <<-RUBY
      class Alfa
        def bravo!
        end

        def charlie!
        end
      end
    RUBY

    expect(src).
      to reek_of(:MissingSafeMethod, lines: [2], name: 'bravo!').
      and reek_of(:MissingSafeMethod, lines: [5], name: 'charlie!')
  end

  it 'reports nothing when method and bang counterpart exist' do
    src = <<-RUBY
      class Alfa
        def bravo
        end

        def bravo!
        end
      end
    RUBY

    expect(src).not_to reek_of(:MissingSafeMethod)
  end

  it 'does not report methods we excluded via comment' do
    source = <<-RUBY
      # :reek:MissingSafeMethod: { exclude: [ bravo! ] }
      class Alfa
        def bravo!
        end
      end
    RUBY

    expect(source).not_to reek_of(:MissingSafeMethod)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reek-5.6.0 spec/reek/smell_detectors/missing_safe_method_spec.rb
reek-5.5.0 spec/reek/smell_detectors/missing_safe_method_spec.rb
reek-5.4.1 spec/reek/smell_detectors/missing_safe_method_spec.rb
reek-5.4.0 spec/reek/smell_detectors/missing_safe_method_spec.rb
reek-5.3.2 spec/reek/smell_detectors/missing_safe_method_spec.rb