Sha256: 0e0e2b88ed002dd4e1aeb76c8c9021ce5f102269b4f42a375bcdc107c7d95d40

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

require_relative '../../spec_helper'
require_lib 'reek/context/module_context'
require_relative 'smell_detector_shared'

RSpec.describe Reek::Smells::PrimaDonnaMethod do
  it 'reports the right values' do
    src = 'class C; def m!; end; end'
    expect(src).to reek_of :PrimaDonnaMethod,
                           lines: [1],
                           message: 'has prima donna method `m!`',
                           name: :m!
  end

  it 'should report nothing when method and bang counterpart exist' do
    expect('class C; def m; end; def m!; end; end').not_to reek_of(:PrimaDonnaMethod)
  end

  it 'should report PrimaDonnaMethod when only bang method exists' do
    expect('class C; def m!; end; end').to reek_of(:PrimaDonnaMethod)
  end

  describe 'the right smell' do
    let(:detector) { build(:smell_detector, smell_type: :PrimaDonnaMethod) }
    let(:src)      { 'class C; def m!; end; end' }
    let(:ctx)      do
      Reek::Context::ModuleContext.new(nil,
                                       Reek::Source::SourceCode.from(src).syntax_tree)
    end

    it 'should be reported' do
      smells = detector.sniff(ctx)
      warning = smells[0]

      expect(warning.smell_type).to eq('PrimaDonnaMethod')
      expect(warning.lines).to eq([1])
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
reek-4.4.0 spec/reek/smells/prima_donna_method_spec.rb
reek-4.3.0 spec/reek/smells/prima_donna_method_spec.rb
reek-4.2.5 spec/reek/smells/prima_donna_method_spec.rb
reek-4.2.4 spec/reek/smells/prima_donna_method_spec.rb