spec/reek/smells/data_clump_spec.rb in reek-1.2.2 vs spec/reek/smells/data_clump_spec.rb in reek-1.2.3

- old
+ new

@@ -2,50 +2,50 @@ require 'reek/smells/data_clump' include Reek::Smells -describe DataClump do - it 'should not report small parameter sets' do +shared_examples_for 'a data clump detector' do + it 'does not report small parameter sets' do src = <<EOS -class Scrunch +#{@context} Scrunch def first(pa) @field == :sym ? 0 : 3; end def second(pa) @field == :sym; end def third(pa) pa - pb + @fred; end end EOS src.should_not reek end - it 'should report 3 identical pairs in a class' do + it 'reports 3 identical pairs in a class' do src = <<EOS -class Scrunch +#{@context} Scrunch 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 src.should reek_of(:DataClump, /\[pa, pb\]/, /3 methods/) end - it 'should report 3 swapped pairs in a class' do + it 'reports 3 swapped pairs in a class' do src = <<EOS -class Scrunch +#{@context} Scrunch def one(pa, pb) @field == :sym ? 0 : 3; end def two(pb, pa) @field == :sym; end def tri(pa, pb) pa - pb + @fred; end end EOS src.should reek_of(:DataClump, /\[pa, pb\]/, /3 methods/) end - it 'should report 3 identical parameter sets in a class' do + it 'reports 3 identical parameter sets in a class' do src = <<EOS -class Scrunch +#{@context} Scrunch def first(pa, pb, pc) @field == :sym ? 0 : 3; end def second(pa, pb, pc) @field == :sym; end def third(pa, pb, pc) pa - pb + @fred; end end EOS @@ -54,13 +54,13 @@ src.should_not reek_of(:DataClump, /\[pa, pb\]/, /3 methods/) src.should_not reek_of(:DataClump, /\[pa, pc\]/, /3 methods/) src.should_not reek_of(:DataClump, /\[pb, pc\]/, /3 methods/) end - it 'should recognise re-ordered identical parameter sets' do + it 'recognises re-ordered identical parameter sets' do src = <<EOS -class Scrunch +#{@context} Scrunch def first(pb, pa, pc) @field == :sym ? 0 : 3; end def second(pc, pb, pa) @field == :sym; end def third(pa, pb, pc) pa - pb + @fred; end end EOS @@ -69,19 +69,37 @@ src.should_not reek_of(:DataClump, /\[pa, pb\]/, /3 methods/) src.should_not reek_of(:DataClump, /\[pa, pc\]/, /3 methods/) src.should_not reek_of(:DataClump, /\[pb, pc\]/, /3 methods/) end - it 'should count only identical parameter sets' do + it 'counts only identical parameter sets' do src = <<EOS -class RedCloth +#{@context} RedCloth def fa(p1, p2, p3, conten) end def fb(p1, p2, p3, conten) end def fc(name, windowW, windowH) end end EOS src.should_not reek_of(:DataClump) + end +end + +describe DataClump do + context 'in a class' do + before :each do + @context = 'class' + end + + it_should_behave_like 'a data clump detector' + end + + context 'in a module' do + before :each do + @context = 'module' + end + + it_should_behave_like 'a data clump detector' end # TODO: include singleton methods in the calcs end