Sha256: bda9bd25b23f635d9c8d2cd547c6628efde8ef8ad6932943853c63bc4dcc2aea

Contents?: true

Size: 1.66 KB

Versions: 4

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'
require 'reek/core/code_context'
require 'reek/smells/long_yield_list'
require 'reek/smells/smell_detector_shared'

describe Reek::Smells::LongYieldList do
  before(:each) do
    @source_name = 'dummy_source'
    @detector = build(:smell_detector, smell_type: :LongYieldList, source: @source_name)
  end

  it_should_behave_like 'SmellDetector'

  context 'yield' do
    it 'should not report yield with no parameters' do
      src = 'def simple(arga, argb, &blk) f(3);yield; end'
      expect(src).not_to reek_of(:LongYieldList)
    end
    it 'should not report yield with few parameters' do
      src = 'def simple(arga, argb, &blk) f(3);yield a,b; end'
      expect(src).not_to reek_of(:LongYieldList)
    end
    it 'should report yield with many parameters' do
      src = 'def simple(arga, argb, &blk) f(3);yield arga,argb,arga,argb; end'
      expect(src).to reek_of(:LongYieldList, count: 4)
    end
    it 'should not report yield of a long expression' do
      src = 'def simple(arga, argb, &blk) f(3);yield(if @dec then argb else 5+3 end); end'
      expect(src).not_to reek_of(:LongYieldList)
    end
  end

  context 'when a smells is reported' do
    before :each do
      src = <<-EOS
        def simple(arga, argb, &blk)
          f(3)
          yield(arga,argb,arga,argb)
          end
      EOS
      ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
      @smells = @detector.examine_context(ctx)
      @warning = @smells[0]
    end

    it_should_behave_like 'common fields set correctly'

    it 'reports the correct values' do
      expect(@warning.parameters[:count]).to eq(4)
      expect(@warning.lines).to eq([3])
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
reek-2.0.4 spec/reek/smells/long_yield_list_spec.rb
reek-2.0.3 spec/reek/smells/long_yield_list_spec.rb
reek-2.0.2 spec/reek/smells/long_yield_list_spec.rb
reek-2.0.1 spec/reek/smells/long_yield_list_spec.rb