spec/reek/smells/data_clump_spec.rb in reek-1.5.1 vs spec/reek/smells/data_clump_spec.rb in reek-1.6.0

- old
+ new

@@ -25,33 +25,31 @@ def first(pa, pb) @field == :sym ? 0 : 3; end def second(pa, pb) @field == :sym; end def third(pa, pb) pa - pb + @fred; end end EOS - ctx = CodeContext.new(nil, @src.to_reek_source.syntax_tree) + ctx = ModuleContext.new(nil, @src.to_reek_source.syntax_tree) detector = DataClump.new('newt') @smells = detector.examine_context(ctx) - @warning = @smells[0] # SMELL: too cumbersome! - @yaml = @warning.to_yaml end it 'records only the one smell' do expect(@smells.length).to eq(1) end it 'reports all parameters' do - expect(@smells[0].smell[DataClump::PARAMETERS_KEY]).to eq(['pa', 'pb']) + expect(@smells[0].parameters[:parameters]).to eq(['pa', 'pb']) end it 'reports the number of occurrences' do - expect(@smells[0].smell[DataClump::OCCURRENCES_KEY]).to eq(3) + expect(@smells[0].parameters[:count]).to eq(3) end it 'reports all methods' do - expect(@smells[0].smell[DataClump::METHODS_KEY]).to eq(['first', 'second', 'third']) + expect(@smells[0].parameters[:methods]).to eq(['first', 'second', 'third']) end it 'reports the declaration line numbers' do expect(@smells[0].lines).to eq([2, 3, 4]) end it 'reports the correct smell class' do - expect(@smells[0].smell_class).to eq(DataClump::SMELL_CLASS) + expect(@smells[0].smell_category).to eq(DataClump.smell_category) end it 'reports the context fq name' do expect(@smells[0].context).to eq(@module_name) end end @@ -63,12 +61,12 @@ def two(pb, pa) @field == :sym; end def tri(pa, pb) pa - pb + @fred; end end EOS expect(src).to smell_of(DataClump, - DataClump::OCCURRENCES_KEY => 3, - DataClump::PARAMETERS_KEY => ['pa', 'pb']) + count: 3, + parameters: ['pa', 'pb']) end it 'reports 3 identical parameter sets' do src = <<EOS #{@context} Scrunch @@ -76,12 +74,12 @@ def second(pa, pb, pc) @field == :sym; end def third(pa, pb, pc) pa - pb + @fred; end end EOS expect(src).to smell_of(DataClump, - DataClump::OCCURRENCES_KEY => 3, - DataClump::PARAMETERS_KEY => ['pa', 'pb', 'pc']) + count: 3, + parameters: ['pa', 'pb', 'pc']) end it 'reports re-ordered identical parameter sets' do src = <<EOS #{@context} Scrunch @@ -89,12 +87,12 @@ def second(pc, pb, pa) @field == :sym; end def third(pa, pb, pc) pa - pb + @fred; end end EOS expect(src).to smell_of(DataClump, - DataClump::OCCURRENCES_KEY => 3, - DataClump::PARAMETERS_KEY => ['pa', 'pb', 'pc']) + count: 3, + parameters: ['pa', 'pb', 'pc']) end it 'counts only identical parameter sets' do src = <<EOS #{@context} RedCloth @@ -114,11 +112,11 @@ def c_singleton (src, options) end def c_raw (src, options) end def c_raw_singleton (src, options) end end EOS - expect(src).to smell_of(DataClump, DataClump::OCCURRENCES_KEY => 5) + expect(src).to smell_of(DataClump, count: 5) end it 'correctly checks number of occurences' do src = <<-EOS #{@context} Smelly @@ -139,10 +137,22 @@ def fb(p1, p3, p2) end def fc(p4, p1, p2) end end EOS expect(src).to smell_of(DataClump, - DataClump::PARAMETERS_KEY => %w(p1 p2)) + parameters: %w(p1 p2)) + end + + it 'ignores anonymous parameters' do + src = <<-EOS + #{@context} Smelly + def fa(p1, p2, *) end + def fb(p1, p2, *) end + def fc(p1, p2, *) end + end + EOS + expect(src).to smell_of(DataClump, + parameters: %w(p1 p2)) end end describe DataClump do before(:each) do