spec/reek/smells/utility_function_spec.rb in reek-3.2.1 vs spec/reek/smells/utility_function_spec.rb in reek-3.3.0

- old
+ new

@@ -3,33 +3,29 @@ require_relative '../../../lib/reek/examiner' require_relative 'smell_detector_shared' RSpec.describe Reek::Smells::UtilityFunction do describe 'a detector' do - before(:each) do - @source_name = 'string' - @detector = build(:smell_detector, - smell_type: :UtilityFunction, - source: @source_name) - end + let(:detector) { build(:smell_detector, smell_type: :UtilityFunction, source: source_name) } + let(:source_name) { 'string' } it_should_behave_like 'SmellDetector' context 'when a smells is reported' do - before :each do + let(:warning) do src = <<-EOS - def simple(arga) - arga.b.c - end + def simple(arga) + arga.b.c + end EOS - @warning = Reek::Examiner.new(src, ['UtilityFunction']).smells[0] + Reek::Examiner.new(src, ['UtilityFunction']).smells[0] end it_should_behave_like 'common fields set correctly' it 'reports the line number of the method' do - expect(@warning.lines).to eq([1]) + expect(warning.lines).to eq([1]) end end end context 'with a singleton method' do @@ -156,22 +152,22 @@ end end context 'with only one call' do it 'reports a call to a parameter' do - expect('def simple(arga) arga.to_s end').to reek_of(:UtilityFunction, name: 'simple') + expect('def simple(arga) arga.to_s end').to reek_of(:UtilityFunction, name: 'simple') end it 'reports a call to a constant' do expect('def simple(arga) FIELDS[arga] end').to reek_of(:UtilityFunction) end end context 'with two or more calls' do it 'reports two calls' do src = 'def simple(arga) arga.to_s + arga.to_i end' - expect(src).to reek_of(:UtilityFunction, name: 'simple') + expect(src).to reek_of(:UtilityFunction, name: 'simple') expect(src).not_to reek_of(:FeatureEnvy) end it 'counts a local call in a param initializer' do expect('def simple(arga=local) arga.to_s end').not_to reek_of(:UtilityFunction) @@ -192,10 +188,10 @@ not_to reek_of(:UtilityFunction) end it 'should report message chain' do src = 'def simple(arga) arga.b.c end' - expect(src).to reek_of(:UtilityFunction, name: 'simple') + expect(src).to reek_of(:UtilityFunction, name: 'simple') expect(src).not_to reek_of(:FeatureEnvy) end it 'does not report a method that calls super' do expect('def child(arg) super; arg.to_s; end').not_to reek_of(:UtilityFunction)