Sha256: a60fd1911173de05dfaf45cf6ec5441108a8e2a13f47e73723592a5f2fb4df3b

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'unused_parameters')
require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')

include Reek
include Reek::Smells

describe UnusedParameters do

  context 'for methods' do

    it 'should report nothing for no parameters' do
      'def simple; true end'.should_not smell_of(UnusedParameters)
    end

    it 'should report nothing for used parameter' do
      'def simple(sum); sum end'.should_not smell_of(UnusedParameters)
    end

    it 'should report for 1 used and 2 unused parameter' do
      src = 'def simple(num,sum,denum); sum end'
      src.should smell_of(UnusedParameters,
                          {UnusedParameters::PARAMETER_KEY => 'num'},
                          {UnusedParameters::PARAMETER_KEY => 'denum'})
    end

    it 'should report for 3 used and 1 unused parameter' do
      src = 'def simple(num,sum,denum,quotient); num + denum + sum end'
      src.should smell_of(UnusedParameters,
                          {UnusedParameters::PARAMETER_KEY => 'quotient'})
    end

    it 'should report nothing for used splatted parameter' do
      'def simple(*sum); sum end'.should_not smell_of(UnusedParameters)
    end

    it 'should report nothing for unused anonymous parameter' do
      'def simple(_); end'.should_not smell_of(UnusedParameters)
    end

    it 'should report nothing for unused anonymous splatted parameter' do
      'def simple(*); end'.should_not smell_of(UnusedParameters)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reek-1.3.1 spec/reek/smells/unused_parameters_spec.rb
reek-1.3 spec/reek/smells/unused_parameters_spec.rb