reek 1.2.7.3 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/History.txt +17 -0
  2. data/README.md +32 -48
  3. data/config/defaults.reek +7 -1
  4. data/features/api.feature +20 -0
  5. data/features/masking_smells.feature +41 -0
  6. data/features/options.feature +4 -0
  7. data/features/rake_task.feature +14 -0
  8. data/features/yaml.feature +8 -8
  9. data/lib/reek.rb +1 -1
  10. data/lib/reek/cli/command_line.rb +9 -2
  11. data/lib/reek/cli/reek_command.rb +5 -4
  12. data/lib/reek/cli/yaml_command.rb +2 -2
  13. data/lib/reek/core/code_context.rb +10 -1
  14. data/lib/reek/core/method_context.rb +2 -2
  15. data/lib/reek/core/sniffer.rb +3 -1
  16. data/lib/reek/core/stop_context.rb +4 -0
  17. data/lib/reek/examiner.rb +2 -2
  18. data/lib/reek/rake/task.rb +16 -0
  19. data/lib/reek/smell_warning.rb +3 -2
  20. data/lib/reek/smells/attribute.rb +13 -9
  21. data/lib/reek/smells/boolean_parameter.rb +14 -9
  22. data/lib/reek/smells/class_variable.rb +16 -5
  23. data/lib/reek/smells/control_couple.rb +11 -6
  24. data/lib/reek/smells/data_clump.rb +33 -30
  25. data/lib/reek/smells/duplication.rb +39 -8
  26. data/lib/reek/smells/feature_envy.rb +7 -8
  27. data/lib/reek/smells/irresponsible_module.rb +12 -3
  28. data/lib/reek/smells/large_class.rb +31 -15
  29. data/lib/reek/smells/long_method.rb +15 -5
  30. data/lib/reek/smells/long_parameter_list.rb +14 -7
  31. data/lib/reek/smells/long_yield_list.rb +12 -9
  32. data/lib/reek/smells/nested_iterators.rb +46 -11
  33. data/lib/reek/smells/simulated_polymorphism.rb +16 -8
  34. data/lib/reek/smells/smell_detector.rb +13 -13
  35. data/lib/reek/smells/uncommunicative_method_name.rb +12 -20
  36. data/lib/reek/smells/uncommunicative_module_name.rb +17 -19
  37. data/lib/reek/smells/uncommunicative_parameter_name.rb +22 -15
  38. data/lib/reek/smells/uncommunicative_variable_name.rb +24 -18
  39. data/lib/reek/smells/utility_function.rb +6 -6
  40. data/lib/reek/source/code_comment.rb +19 -1
  41. data/lib/reek/source/tree_dresser.rb +40 -22
  42. data/reek.gemspec +6 -4
  43. data/spec/matchers/smell_of_matcher.rb +58 -0
  44. data/spec/reek/core/code_context_spec.rb +4 -2
  45. data/spec/reek/core/code_parser_spec.rb +2 -1
  46. data/spec/reek/core/method_context_spec.rb +5 -5
  47. data/spec/reek/smells/attribute_spec.rb +2 -4
  48. data/spec/reek/smells/boolean_parameter_spec.rb +32 -42
  49. data/spec/reek/smells/class_variable_spec.rb +22 -6
  50. data/spec/reek/smells/control_couple_spec.rb +15 -14
  51. data/spec/reek/smells/data_clump_spec.rb +29 -111
  52. data/spec/reek/smells/duplication_spec.rb +79 -49
  53. data/spec/reek/smells/feature_envy_spec.rb +1 -2
  54. data/spec/reek/smells/irresponsible_module_spec.rb +43 -22
  55. data/spec/reek/smells/large_class_spec.rb +34 -59
  56. data/spec/reek/smells/long_method_spec.rb +15 -10
  57. data/spec/reek/smells/long_parameter_list_spec.rb +24 -24
  58. data/spec/reek/smells/long_yield_list_spec.rb +13 -14
  59. data/spec/reek/smells/nested_iterators_spec.rb +93 -76
  60. data/spec/reek/smells/smell_detector_shared.rb +4 -2
  61. data/spec/reek/smells/uncommunicative_method_name_spec.rb +10 -27
  62. data/spec/reek/smells/uncommunicative_module_name_spec.rb +22 -23
  63. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +36 -26
  64. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +45 -48
  65. data/spec/reek/smells/utility_function_spec.rb +14 -13
  66. data/spec/reek/source/code_comment_spec.rb +61 -3
  67. data/spec/reek/source/tree_dresser_spec.rb +96 -1
  68. data/spec/samples/config/allow_duplication.reek +3 -0
  69. data/spec/samples/config/deeper_nested_iterators.reek +3 -0
  70. data/spec/samples/demo/demo.rb +8 -0
  71. data/spec/samples/inline_config/dirty.rb +16 -0
  72. data/spec/samples/inline_config/masked.reek +7 -0
  73. data/spec/samples/mask_some/dirty.rb +8 -0
  74. data/spec/samples/mask_some/some.reek +8 -0
  75. data/spec/spec_helper.rb +2 -0
  76. metadata +15 -5
@@ -17,20 +17,24 @@ describe LongYieldList do
17
17
 
18
18
  context 'yield' do
19
19
  it 'should not report yield with no parameters' do
20
- 'def simple(arga, argb, &blk) f(3);yield; end'.should_not reek
20
+ src = 'def simple(arga, argb, &blk) f(3);yield; end'
21
+ src.should_not smell_of(LongYieldList)
21
22
  end
22
23
  it 'should not report yield with few parameters' do
23
- 'def simple(arga, argb, &blk) f(3);yield a,b; end'.should_not reek
24
+ src = 'def simple(arga, argb, &blk) f(3);yield a,b; end'
25
+ src.should_not smell_of(LongYieldList)
24
26
  end
25
27
  it 'should report yield with many parameters' do
26
- 'def simple(arga, argb, &blk) f(3);yield arga,argb,arga,argb; end'.should reek_only_of(:LongYieldList, /simple/, /yields/, /4/)
28
+ src = 'def simple(arga, argb, &blk) f(3);yield arga,argb,arga,argb; end'
29
+ src.should smell_of(LongYieldList, LongYieldList::PARAMETER_COUNT_KEY => 4)
27
30
  end
28
31
  it 'should not report yield of a long expression' do
29
- 'def simple(arga, argb, &blk) f(3);yield(if @dec then argb else 5+3 end); end'.should_not reek
32
+ src = 'def simple(arga, argb, &blk) f(3);yield(if @dec then argb else 5+3 end); end'
33
+ src.should_not smell_of(LongYieldList)
30
34
  end
31
35
  end
32
36
 
33
- context 'looking at the YAML' do
37
+ context 'when a smells is reported' do
34
38
  before :each do
35
39
  src = <<EOS
36
40
  def simple(arga, argb, &blk)
@@ -38,20 +42,15 @@ def simple(arga, argb, &blk)
38
42
  yield(arga,argb,arga,argb)
39
43
  end
40
44
  EOS
41
- source = src.to_reek_source
42
- sniffer = Sniffer.new(source)
43
- mctx = CodeParser.new(sniffer).process_defn(source.syntax_tree)
44
- @detector.examine_context(mctx)
45
- @warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
45
+ ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
46
+ @smells = @detector.examine_context(ctx)
47
+ @warning = @smells[0]
46
48
  end
47
49
 
48
50
  it_should_behave_like 'common fields set correctly'
49
51
 
50
- it 'reports the number of parameters' do
52
+ it 'reports the correct values' do
51
53
  @warning.smell['parameter_count'].should == 4
52
- # SMELL: many tests duplicate the names of the YAML fields
53
- end
54
- it 'reports the line number of the method' do
55
54
  @warning.lines.should == [3]
56
55
  end
57
56
  end
@@ -6,8 +6,23 @@ include Reek::Smells
6
6
 
7
7
  describe NestedIterators do
8
8
 
9
+ context 'with no iterators' do
10
+ it 'reports no smells' do
11
+ src = 'def fred() nothing = true; end'
12
+ src.should_not smell_of(NestedIterators)
13
+ end
14
+ end
15
+
16
+ context 'with one iterator' do
17
+ it 'reports no smells' do
18
+ src = 'def fred() nothing.each {|item| item}; end'
19
+ src.should_not smell_of(NestedIterators)
20
+ end
21
+ end
22
+
9
23
  it 'should report nested iterators in a method' do
10
- 'def bad(fred) @fred.each {|item| item.each {|ting| ting.ting} } end'.should reek_only_of(:NestedIterators)
24
+ src = 'def bad(fred) @fred.each {|item| item.each {|ting| ting.ting} } end'
25
+ src.should smell_of(NestedIterators)
11
26
  end
12
27
 
13
28
  it 'should not report method with successive iterators' do
@@ -17,7 +32,7 @@ def bad(fred)
17
32
  @jim.each {|ting| ting.each }
18
33
  end
19
34
  EOS
20
- src.should_not reek
35
+ src.should_not smell_of(NestedIterators)
21
36
  end
22
37
 
23
38
  it 'should not report method with chained iterators' do
@@ -26,7 +41,7 @@ def chained
26
41
  @sig.keys.sort_by { |xray| xray.to_s }.each { |min| md5 << min.to_s }
27
42
  end
28
43
  EOS
29
- src.should_not reek
44
+ src.should_not smell_of(NestedIterators)
30
45
  end
31
46
 
32
47
  it 'should report nested iterators only once per method' do
@@ -36,98 +51,100 @@ def bad(fred)
36
51
  @jim.each {|ting| ting.each {|piece| @hal.send} }
37
52
  end
38
53
  EOS
39
- src.should reek_only_of(:NestedIterators)
54
+ src.should smell_of(NestedIterators, {}, {})
40
55
  end
56
+
57
+ context 'when the allowed nesting depth is 3' do
58
+ before :each do
59
+ @config = {NestedIterators::MAX_ALLOWED_NESTING_KEY => 3}
60
+ end
61
+
62
+ it 'should not report nested iterators 2 levels deep' do
63
+ src = <<EOS
64
+ def bad(fred)
65
+ @fred.each {|one| one.each {|two| two.two} }
66
+ end
67
+ EOS
68
+ src.should_not smell_of(NestedIterators).with_config(@config)
69
+ end
70
+
71
+ it 'should not report nested iterators 3 levels deep' do
72
+ src = <<EOS
73
+ def bad(fred)
74
+ @fred.each {|one| one.each {|two| two.each {|three| three.three} } }
41
75
  end
76
+ EOS
77
+ src.should_not smell_of(NestedIterators).with_config(@config)
78
+ end
42
79
 
43
- describe NestedIterators do
44
- before(:each) do
45
- @detector = NestedIterators.new('cuckoo')
80
+ it 'should report nested iterators 4 levels deep' do
81
+ src = <<EOS
82
+ def bad(fred)
83
+ @fred.each {|one| one.each {|two| two.each {|three| three.each {|four| four.four} } } }
84
+ end
85
+ EOS
86
+ src.should smell_of(NestedIterators).with_config(@config)
87
+ end
46
88
  end
47
89
 
48
- it_should_behave_like 'SmellDetector'
90
+ context 'when ignoring iterators' do
91
+ before :each do
92
+ @config = {NestedIterators::IGNORE_ITERATORS_KEY => ['ignore_me']}
93
+ end
49
94
 
50
- context 'find_deepest_iterators' do
51
- context 'with no iterators' do
52
- it 'returns an empty list' do
53
- src = 'def fred() nothing = true; end'
54
- source = src.to_reek_source
55
- sniffer = Sniffer.new(source)
56
- @mctx = CodeParser.new(sniffer).process_defn(source.syntax_tree)
57
- @detector.find_deepest_iterators(@mctx).should == []
58
- end
95
+ it 'should not report nesting the ignored iterator inside another' do
96
+ src = 'def bad(fred) @fred.each {|item| item.ignore_me {|ting| ting.ting} } end'
97
+ src.should_not smell_of(NestedIterators).with_config(@config)
59
98
  end
60
99
 
61
- context 'with one iterator' do
62
- before :each do
63
- src = 'def fred() nothing.each {|item| item}; end'
64
- source = src.to_reek_source
65
- sniffer = Sniffer.new(source)
66
- mctx = CodeParser.new(sniffer).process_defn(source.syntax_tree)
67
- @result = @detector.find_deepest_iterators(mctx)
68
- end
69
- it 'returns a depth of 1' do
70
- @result.should == []
71
- end
100
+ it 'should not report nesting inside the ignored iterator' do
101
+ src = 'def bad(fred) @fred.ignore_me {|item| item.each {|ting| ting.ting} } end'
102
+ src.should_not smell_of(NestedIterators).with_config(@config)
72
103
  end
73
104
 
74
- context 'with two non-nested iterators' do
75
- before :each do
76
- src = <<EOS
77
- def fred()
78
- nothing.each do |item|
79
- item
105
+ it 'should report nested iterators inside the ignored iterator' do
106
+ src = 'def bad(fred) @fred.ignore_me {|item| item.each {|ting| ting.each {|other| other.other} } } end'
107
+ src.should smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 2).with_config(@config)
108
+ end
109
+
110
+ it 'should report nested iterators outside the ignored iterator' do
111
+ src = 'def bad(fred) @fred.each {|item| item.each {|ting| ting.ignore_me {|other| other.other} } } end'
112
+ src.should smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 2).with_config(@config)
113
+ end
114
+
115
+ it 'should report nested iterators with the ignored iterator between them' do
116
+ src = 'def bad(fred) @fred.each {|item| item.ignore_me {|ting| ting.ting {|other| other.other} } } end'
117
+ src.should smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 2).with_config(@config)
118
+ end
80
119
  end
81
- again.each {|thing| }
82
120
  end
83
- EOS
84
- source = src.to_reek_source
85
- sniffer = Sniffer.new(source)
86
- mctx = CodeParser.new(sniffer).process_defn(source.syntax_tree)
87
- @result = @detector.find_deepest_iterators(mctx)
88
- end
89
- it 'returns both iterators' do
90
- @result.length.should == 0
91
- end
92
- end
93
121
 
94
- context 'with one nested iterator' do
95
- before :each do
96
- src = <<EOS
122
+ describe NestedIterators do
123
+ before(:each) do
124
+ @source_name = 'cuckoo'
125
+ @detector = NestedIterators.new(@source_name)
126
+ end
127
+
128
+ it_should_behave_like 'SmellDetector'
129
+
130
+ context 'when a smell is reported' do
131
+ before :each do
132
+ src = <<EOS
97
133
  def fred()
98
134
  nothing.each do |item|
99
135
  again.each {|thing| item }
100
136
  end
101
137
  end
102
138
  EOS
103
- source = src.to_reek_source
104
- sniffer = Sniffer.new(source)
105
- @mctx = CodeParser.new(sniffer).process_defn(source.syntax_tree)
106
- @result = @detector.find_deepest_iterators(@mctx)
107
- end
108
- it 'returns only the deepest iterator' do
109
- @result.length.should == 1
110
- end
111
- it 'has depth of 2' do
112
- @result[0][1].should == 2
113
- end
114
- it 'refers to the innermost exp' do
115
- @result[0][0].line.should == 3
116
- end
117
-
118
- context 'when reporting yaml' do
119
- before :each do
120
- @detector.examine_context(@mctx)
121
- warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
122
- @yaml = warning.to_yaml
123
- end
124
- it 'reports the depth' do
125
- @yaml.should match(/depth:\s*2/)
126
- end
127
- it 'reports the deepest line number' do
128
- @yaml.should match(/lines:[\s-]*3/)
129
- end
130
- end
139
+ ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
140
+ @warning = @detector.examine_context(ctx)[0]
141
+ end
142
+
143
+ it_should_behave_like 'common fields set correctly'
144
+
145
+ it 'reports correct values' do
146
+ @warning.smell[NestedIterators::NESTING_DEPTH_KEY].should == 2
147
+ @warning.lines.should == [3]
131
148
  end
132
149
  end
133
150
  end
@@ -7,14 +7,16 @@ shared_examples_for 'SmellDetector' do
7
7
  context 'exception matching follows the context' do
8
8
  before :each do
9
9
  @ctx = mock('context')
10
+ # @ctx.should_receive(:exp).and_return(nil)
11
+ @ctx.should_receive(:config).and_return({})
10
12
  end
11
13
  it 'when false' do
12
- @ctx.should_receive(:matches?).and_return(false)
14
+ @ctx.should_receive(:matches?).at_least(:once).and_return(false)
13
15
  @detector.exception?(@ctx).should == false
14
16
  end
15
17
 
16
18
  it 'when true' do
17
- @ctx.should_receive(:matches?).and_return(true)
19
+ @ctx.should_receive(:matches?).at_least(:once).and_return(true)
18
20
  @detector.exception?(@ctx).should == true
19
21
  end
20
22
  end
@@ -17,42 +17,25 @@ describe UncommunicativeMethodName do
17
17
 
18
18
  ['help', '+', '-', '/', '*'].each do |method_name|
19
19
  it "accepts the method name '#{method_name}'" do
20
- "def #{method_name}(fred) basics(17) end".should_not reek
20
+ "def #{method_name}(fred) basics(17) end".should_not smell_of(UncommunicativeMethodName)
21
21
  end
22
22
  end
23
23
 
24
24
  ['x', 'x2', 'method2'].each do |method_name|
25
25
  context 'with a bad name' do
26
26
  before :each do
27
- @full_name = 'anything you like'
28
- ctx = mock('method', :null_object => true)
29
- ctx.should_receive(:name).and_return(method_name)
30
- ctx.should_receive(:full_name).at_least(:once).and_return(@full_name)
31
- ctx.should_receive(:exp).and_return(ast(:defn))
32
- @detector.examine_context(ctx)
33
- @smells = @detector.smells_found.to_a
27
+ src = 'def x() end'
28
+ ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
29
+ @smells = @detector.examine_context(ctx)
30
+ @warning = @smells[0]
34
31
  end
35
32
 
36
- it 'records only that attribute' do
37
- @smells.length.should == 1
38
- end
39
- it 'reports the attribute name' do
40
- @smells[0].smell[UncommunicativeMethodName::METHOD_NAME_KEY].should == method_name
41
- end
42
- it 'reports the declaration line number' do
33
+ it_should_behave_like 'common fields set correctly'
34
+
35
+ it 'reports the correct values' do
36
+ @smells[0].smell[UncommunicativeMethodName::METHOD_NAME_KEY].should == 'x'
43
37
  @smells[0].lines.should == [1]
44
- end
45
- it 'reports the correct smell class' do
46
- @smells[0].smell_class.should == UncommunicativeMethodName::SMELL_CLASS
47
- end
48
- it 'reports the correct smell subclass' do
49
- @smells[0].subclass.should == UncommunicativeMethodName::SMELL_SUBCLASS
50
- end
51
- it 'reports the context fq name' do
52
- @smells[0].context.should == @full_name
53
- end
54
- it 'reports the source name' do
55
- @smells[0].source.should == @source_name
38
+ @smells[0].context.should == 'x'
56
39
  end
57
40
  end
58
41
  end
@@ -28,40 +28,39 @@ describe UncommunicativeModuleName do
28
28
  it 'reports long name ending in a number' do
29
29
  "#{type} Printer2; end".should reek_of(:UncommunicativeModuleName, /Printer2/)
30
30
  end
31
+ it 'reports a bad scoped name' do
32
+ src = "#{type} Foo::X; end"
33
+ ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
34
+ smells = @detector.examine_context(ctx)
35
+ smells.length.should == 1
36
+ smells[0].smell_class.should == UncommunicativeModuleName::SMELL_CLASS
37
+ smells[0].subclass.should == UncommunicativeModuleName::SMELL_SUBCLASS
38
+ smells[0].smell[UncommunicativeModuleName::MODULE_NAME_KEY].should == 'X'
39
+ smells[0].context.should match(/#{smells[0].smell[UncommunicativeModuleName::MODULE_NAME_KEY]}/)
40
+ end
31
41
  end
32
42
 
33
43
  context 'accepting names' do
34
44
  it 'accepts Inline::C' do
35
- ctx = mock('context')
36
- ctx.should_receive(:full_name).and_return('Inline::C')
37
- @detector.accept?(ctx).should == true
45
+ src = 'module Inline::C; end'
46
+ ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
47
+ @detector.examine_context(ctx).should be_empty
38
48
  end
39
49
  end
40
50
 
41
51
  context 'looking at the YAML' do
42
52
  before :each do
43
53
  src = 'module Printer2; end'
44
- source = src.to_reek_source
45
- sniffer = Core::Sniffer.new(source)
46
- @mctx = Core::CodeParser.new(sniffer).process_module(source.syntax_tree)
47
- @detector.examine(@mctx)
48
- warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
49
- @yaml = warning.to_yaml
50
- end
51
- it 'reports the source' do
52
- @yaml.should match(/source:\s*#{@source_name}/)
53
- end
54
- it 'reports the class' do
55
- @yaml.should match(/class:\s*UncommunicativeName/)
56
- end
57
- it 'reports the subclass' do
58
- @yaml.should match(/subclass:\s*UncommunicativeModuleName/)
54
+ ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
55
+ smells = @detector.examine_context(ctx)
56
+ @warning = smells[0]
59
57
  end
60
- it 'reports the variable name' do
61
- @yaml.should match(/module_name:\s*Printer2/)
62
- end
63
- it 'reports the line number of the declaration' do
64
- @yaml.should match(/lines:\s*- 1/)
58
+
59
+ it_should_behave_like 'common fields set correctly'
60
+
61
+ it 'reports the correct values' do
62
+ @warning.smell[UncommunicativeModuleName::MODULE_NAME_KEY].should == 'Printer2'
63
+ @warning.lines.should == [1]
65
64
  end
66
65
  end
67
66
  end
@@ -17,17 +17,38 @@ describe UncommunicativeParameterName do
17
17
  context "parameter name" do
18
18
  ['obj.', ''].each do |host|
19
19
  it 'does not recognise *' do
20
- "def #{host}help(xray, *) basics(17) end".should_not reek
20
+ "def #{host}help(xray, *) basics(17) end".should_not smell_of(UncommunicativeParameterName)
21
21
  end
22
22
  it "reports parameter's name" do
23
- "def #{host}help(x) basics(17) end".should reek_only_of(:UncommunicativeParameterName, /x/, /parameter name/)
23
+ src = "def #{host}help(x) basics(17) end"
24
+ src.should smell_of(UncommunicativeParameterName, {UncommunicativeParameterName::PARAMETER_NAME_KEY => 'x'})
24
25
  end
25
- it 'reports name of the form "x2"' do
26
- "def #{host}help(x2) basics(17) end".should reek_only_of(:UncommunicativeParameterName, /x2/, /parameter name/)
27
- #SMELL: should match either the class or the subclass!
26
+
27
+ context 'with a name of the form "x2"' do
28
+ before :each do
29
+ @bad_param = 'x2'
30
+ src = "def #{host}help(#{@bad_param}) basics(17) end"
31
+ ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
32
+ @smells = @detector.examine_context(ctx)
33
+ end
34
+ it 'reports only 1 smell' do
35
+ @smells.length.should == 1
36
+ end
37
+ it 'reports uncommunicative parameter name' do
38
+ @smells[0].subclass.should == UncommunicativeParameterName::SMELL_SUBCLASS
39
+ end
40
+ it 'reports the parameter name' do
41
+ @smells[0].smell[UncommunicativeParameterName::PARAMETER_NAME_KEY].should == @bad_param
42
+ end
28
43
  end
29
44
  it 'reports long name ending in a number' do
30
- "def #{host}help(param1) basics(17) end".should reek_only_of(:UncommunicativeParameterName, /param1/, /parameter name/)
45
+ @bad_param = 'param2'
46
+ src = "def #{host}help(#{@bad_param}) basics(17) end"
47
+ ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
48
+ smells = @detector.examine_context(ctx)
49
+ smells.length.should == 1
50
+ smells[0].subclass.should == UncommunicativeParameterName::SMELL_SUBCLASS
51
+ smells[0].smell[UncommunicativeParameterName::PARAMETER_NAME_KEY].should == @bad_param
31
52
  end
32
53
  end
33
54
  end
@@ -35,27 +56,16 @@ describe UncommunicativeParameterName do
35
56
  context 'looking at the YAML' do
36
57
  before :each do
37
58
  src = 'def bad(good, bad2, good_again) end'
38
- source = src.to_reek_source
39
- sniffer = Sniffer.new(source)
40
- @mctx = CodeParser.new(sniffer).process_defn(source.syntax_tree)
41
- @detector.examine(@mctx)
42
- warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
43
- @yaml = warning.to_yaml
44
- end
45
- it 'reports the source' do
46
- @yaml.should match(/source:\s*#{@source_name}/)
47
- end
48
- it 'reports the class' do
49
- @yaml.should match(/class:\s*UncommunicativeName/)
50
- end
51
- it 'reports the subclass' do
52
- @yaml.should match(/subclass:\s*UncommunicativeParameterName/)
59
+ ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
60
+ @smells = @detector.examine_context(ctx)
61
+ @warning = @smells[0]
53
62
  end
54
- it 'reports the variable name' do
55
- @yaml.should match(/parameter_name:\s*bad2/)
56
- end
57
- it 'reports the line number of the declaration' do
58
- @yaml.should match(/lines:\s*- 1/)
63
+
64
+ it_should_behave_like 'common fields set correctly'
65
+
66
+ it 'reports the correct values' do
67
+ @warning.smell[UncommunicativeParameterName::PARAMETER_NAME_KEY].should == 'bad2'
68
+ @warning.lines.should == [1]
59
69
  end
60
70
  end
61
71
  end