reek 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +20 -0
- data/README.txt +4 -80
- data/Rakefile +15 -4
- data/bin/reek +10 -16
- data/config/defaults.reek +53 -0
- data/lib/reek.rb +1 -21
- data/lib/reek/block_context.rb +37 -0
- data/lib/reek/class_context.rb +73 -0
- data/lib/reek/code_context.rb +47 -0
- data/lib/reek/code_parser.rb +204 -0
- data/lib/reek/exceptions.reek +13 -0
- data/lib/reek/if_context.rb +25 -0
- data/lib/reek/method_context.rb +85 -0
- data/lib/reek/module_context.rb +34 -0
- data/lib/reek/name.rb +42 -0
- data/lib/reek/object_refs.rb +3 -6
- data/lib/reek/options.rb +60 -40
- data/lib/reek/rake_task.rb +20 -29
- data/lib/reek/report.rb +16 -27
- data/lib/reek/sexp_formatter.rb +52 -0
- data/lib/reek/singleton_method_context.rb +27 -0
- data/lib/reek/smell_warning.rb +49 -0
- data/lib/reek/smells/control_couple.rb +21 -13
- data/lib/reek/smells/duplication.rb +23 -27
- data/lib/reek/smells/feature_envy.rb +18 -25
- data/lib/reek/smells/large_class.rb +32 -17
- data/lib/reek/smells/long_method.rb +24 -16
- data/lib/reek/smells/long_parameter_list.rb +25 -18
- data/lib/reek/smells/long_yield_list.rb +7 -9
- data/lib/reek/smells/nested_iterators.rb +13 -9
- data/lib/reek/smells/smell_detector.rb +66 -0
- data/lib/reek/smells/smells.rb +71 -10
- data/lib/reek/smells/uncommunicative_name.rb +49 -41
- data/lib/reek/smells/utility_function.rb +18 -18
- data/lib/reek/source.rb +116 -0
- data/lib/reek/spec.rb +146 -0
- data/lib/reek/stop_context.rb +62 -0
- data/lib/reek/yield_call_context.rb +14 -0
- data/reek.gemspec +42 -0
- data/spec/integration/reek_source_spec.rb +20 -0
- data/spec/{script_spec.rb → integration/script_spec.rb} +11 -24
- data/spec/reek/class_context_spec.rb +198 -0
- data/spec/reek/code_context_spec.rb +92 -0
- data/spec/reek/code_parser_spec.rb +44 -0
- data/spec/reek/config_spec.rb +42 -0
- data/spec/reek/if_context_spec.rb +17 -0
- data/spec/reek/method_context_spec.rb +52 -0
- data/spec/reek/module_context_spec.rb +38 -0
- data/spec/reek/options_spec.rb +2 -28
- data/spec/reek/report_spec.rb +6 -40
- data/spec/reek/sexp_formatter_spec.rb +31 -0
- data/spec/reek/singleton_method_context_spec.rb +17 -0
- data/spec/reek/smells/control_couple_spec.rb +10 -18
- data/spec/reek/smells/duplication_spec.rb +53 -32
- data/spec/reek/smells/feature_envy_spec.rb +87 -49
- data/spec/reek/smells/large_class_spec.rb +45 -4
- data/spec/reek/smells/long_method_spec.rb +25 -41
- data/spec/reek/smells/long_parameter_list_spec.rb +30 -76
- data/spec/reek/smells/nested_iterators_spec.rb +19 -29
- data/spec/reek/smells/smell_spec.rb +9 -18
- data/spec/reek/smells/uncommunicative_name_spec.rb +88 -53
- data/spec/reek/smells/utility_function_spec.rb +45 -44
- data/spec/samples/inline_spec.rb +40 -0
- data/spec/samples/optparse_spec.rb +100 -0
- data/spec/samples/redcloth_spec.rb +93 -0
- data/spec/spec_helper.rb +3 -1
- data/tasks/reek.rake +1 -10
- data/tasks/rspec.rake +16 -35
- metadata +43 -46
- data/lib/reek/checker.rb +0 -66
- data/lib/reek/class_checker.rb +0 -25
- data/lib/reek/file_checker.rb +0 -20
- data/lib/reek/method_checker.rb +0 -198
- data/lib/reek/printer.rb +0 -154
- data/lib/reek/smells/smell.rb +0 -56
- data/lib/reek/version.rb +0 -9
- data/setup.rb +0 -1585
- data/spec/integration_spec.rb +0 -30
- data/spec/reek/class_checker_spec.rb +0 -48
- data/spec/reek/method_checker_spec.rb +0 -67
- data/spec/reek/printer_spec.rb +0 -30
- data/spec/reek_source_spec.rb +0 -12
- data/spec/samples/inline.reek +0 -27
- data/spec/samples/optparse.reek +0 -79
- data/spec/samples/optparse/date.rb +0 -17
- data/spec/samples/optparse/shellwords.rb +0 -6
- data/spec/samples/optparse/time.rb +0 -10
- data/spec/samples/optparse/uri.rb +0 -6
- data/spec/samples/optparse/version.rb +0 -70
- data/spec/samples/redcloth.reek +0 -65
- data/tasks/samples.rake +0 -17
- data/website/index.html +0 -71
- data/website/index.txt +0 -40
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/screen.css +0 -138
- data/website/template.rhtml +0 -48
@@ -1,11 +1,12 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
-
|
3
|
-
require 'reek/class_checker'
|
2
|
+
require 'reek/code_parser'
|
4
3
|
require 'reek/report'
|
4
|
+
require 'reek/smells/large_class'
|
5
5
|
|
6
6
|
include Reek
|
7
|
+
include Reek::Smells
|
7
8
|
|
8
|
-
describe
|
9
|
+
describe LargeClass do
|
9
10
|
|
10
11
|
class BigOne
|
11
12
|
26.times do |i|
|
@@ -17,7 +18,7 @@ describe ClassChecker, "(Large Class)" do
|
|
17
18
|
|
18
19
|
before(:each) do
|
19
20
|
@rpt = Report.new
|
20
|
-
@cchk =
|
21
|
+
@cchk = CodeParser.new(@rpt, SmellConfig.new.smell_listeners)
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'should not report short class' do
|
@@ -42,4 +43,44 @@ describe ClassChecker, "(Large Class)" do
|
|
42
43
|
@cchk.check_object(BigOne)
|
43
44
|
@rpt[0].report.should match(/BigOne/)
|
44
45
|
end
|
46
|
+
|
47
|
+
describe 'when exceptions are listed' do
|
48
|
+
before :each do
|
49
|
+
@ctx = ClassContext.create(StopContext.new, [0, :Humungous])
|
50
|
+
30.times { |num| @ctx.record_method("method#{num}") }
|
51
|
+
@config = LargeClass.default_config
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should ignore first excepted name' do
|
55
|
+
@config[LargeClass::EXCLUDE_KEY] = ['Humungous']
|
56
|
+
lc = LargeClass.new(@config)
|
57
|
+
lc.examine(@ctx, @rpt).should == false
|
58
|
+
@rpt.length.should == 0
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should ignore second excepted name' do
|
62
|
+
@config[LargeClass::EXCLUDE_KEY] = ['Oversized', 'Humungous']
|
63
|
+
lc = LargeClass.new(@config)
|
64
|
+
lc.examine(@ctx, @rpt).should == false
|
65
|
+
@rpt.length.should == 0
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should report non-excepted name' do
|
69
|
+
@config[LargeClass::EXCLUDE_KEY] = ['SmellMe']
|
70
|
+
lc = LargeClass.new(@config)
|
71
|
+
lc.examine(@ctx, @rpt).should == true
|
72
|
+
@rpt.length.should == 1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe LargeClass do
|
78
|
+
it 'should not report empty class in another module' do
|
79
|
+
'class Treetop::Runtime::SyntaxNode; end'.should_not reek
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should deal with :: scoped names' do
|
83
|
+
element = ClassContext.create(StopContext.new, [:colon2, [:colon2, [:const, :Treetop], :Runtime], :SyntaxNode])
|
84
|
+
element.num_methods.should == 0
|
85
|
+
end
|
45
86
|
end
|
@@ -1,58 +1,43 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
2
|
|
3
|
-
require 'reek/
|
3
|
+
require 'reek/code_parser'
|
4
4
|
require 'reek/report'
|
5
5
|
|
6
6
|
include Reek
|
7
7
|
|
8
|
-
describe
|
9
|
-
|
10
|
-
before(:each) do
|
11
|
-
@rpt = Report.new
|
12
|
-
@cchk = MethodChecker.new(@rpt, 'Thing')
|
13
|
-
end
|
14
|
-
|
8
|
+
describe CodeParser, "(Long Method)" do
|
15
9
|
it 'should not report short methods' do
|
16
|
-
|
17
|
-
@rpt.should be_empty
|
10
|
+
'def short(arga) alf = f(1);@bet = 2;@cut = 3;@dit = 4; @emp = 5;end'.should_not reek
|
18
11
|
end
|
19
12
|
|
20
13
|
it 'should report long methods' do
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
'def long(arga) alf = f(1);@bet = 2;@cut = 3;@dit = 4; @emp = 5;@fry = 6;end'.should reek_only_of(:LongMethod, /6 statements/)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should not report initialize' do
|
18
|
+
'def initialize(arga) alf = f(1);@bet = 2;@cut = 3;@dit = 4; @emp = 5;@fry = 6;end'.should_not reek
|
24
19
|
end
|
25
20
|
|
26
21
|
it 'should only report a long method once' do
|
27
22
|
source =<<EOS
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
EOS
|
45
|
-
@cchk.check_source(source)
|
46
|
-
@rpt.length.should == 1
|
47
|
-
@rpt[0].should be_instance_of(LongMethod)
|
23
|
+
def standard_entries(rbconfig)
|
24
|
+
@abc = rbconfig
|
25
|
+
rubypath = File.join(@abc['bindir'], @abcf['ruby_install_name'] + cff['EXEEXT'])
|
26
|
+
major = yyy['MAJOR'].to_i
|
27
|
+
minor = zzz['MINOR'].to_i
|
28
|
+
teeny = ccc['TEENY'].to_i
|
29
|
+
version = ""
|
30
|
+
if c['rubylibdir']
|
31
|
+
@libruby = "/lib/ruby"
|
32
|
+
@librubyver = "/lib/ruby/"
|
33
|
+
@librubyverarch = "/lib/ruby/"
|
34
|
+
@siteruby = "lib/ruby/version/site_ruby"
|
35
|
+
@siterubyver = siteruby
|
36
|
+
@siterubyverarch = "$siterubyver/['arch']}"
|
48
37
|
end
|
49
38
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
before(:each) do
|
54
|
-
@rpt = Report.new
|
55
|
-
@cchk = MethodChecker.new(@rpt, 'Thing')
|
39
|
+
EOS
|
40
|
+
source.should reek_only_of(:LongMethod)
|
56
41
|
end
|
57
42
|
|
58
43
|
it 'should report long inner block' do
|
@@ -69,7 +54,6 @@ def long(arga)
|
|
69
54
|
end
|
70
55
|
end
|
71
56
|
EOS
|
72
|
-
|
73
|
-
@rpt.length.should == 1
|
57
|
+
src.should reek_only_of(:LongMethod)
|
74
58
|
end
|
75
59
|
end
|
@@ -1,89 +1,67 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
2
|
|
3
|
-
require 'reek/
|
3
|
+
require 'reek/code_parser'
|
4
|
+
require 'reek/smells/long_parameter_list'
|
4
5
|
require 'reek/report'
|
5
6
|
|
6
7
|
include Reek
|
8
|
+
include Reek::Smells
|
7
9
|
|
8
|
-
describe
|
9
|
-
|
10
|
-
before(:each) do
|
11
|
-
@rpt = Report.new
|
12
|
-
@cchk = MethodChecker.new(@rpt, 'Thing')
|
13
|
-
end
|
10
|
+
describe CodeParser, "(Long Parameter List)" do
|
14
11
|
|
15
12
|
describe 'for methods with few parameters' do
|
16
13
|
it 'should report nothing for no parameters' do
|
17
|
-
|
18
|
-
@rpt.should be_empty
|
14
|
+
'def simple; f(3);true; end'.should_not reek
|
19
15
|
end
|
20
|
-
|
21
16
|
it 'should report nothing for 1 parameter' do
|
22
|
-
|
23
|
-
@rpt.should be_empty
|
17
|
+
'def simple(yep) f(3);true end'.should_not reek
|
24
18
|
end
|
25
|
-
|
26
19
|
it 'should report nothing for 2 parameters' do
|
27
|
-
|
28
|
-
@rpt.should be_empty
|
20
|
+
'def simple(yep,zero) f(3);true end'.should_not reek
|
29
21
|
end
|
30
|
-
|
31
22
|
it 'should not count an optional block' do
|
32
|
-
|
33
|
-
@rpt.should be_empty
|
23
|
+
'def simple(alpha, yep, zero, &opt) f(3);true end'.should_not reek
|
34
24
|
end
|
35
|
-
|
36
25
|
it 'should not report inner block with too many parameters' do
|
37
|
-
|
38
|
-
@rpt.should be_empty
|
26
|
+
'def simple(yep,zero); m[3]; rand(34); f.each { |arga, argb, argc, argd| true}; end'.should_not reek
|
39
27
|
end
|
40
28
|
|
41
29
|
describe 'and default values' do
|
42
30
|
it 'should report nothing for 1 parameter' do
|
43
|
-
|
44
|
-
@rpt.should be_empty
|
31
|
+
'def simple(zero=nil) f(3);false end'.should_not reek
|
45
32
|
end
|
46
|
-
|
47
33
|
it 'should report nothing for 2 parameters with 1 default' do
|
48
|
-
|
49
|
-
@rpt.should be_empty
|
34
|
+
'def simple(yep, zero=nil) f(3);false end'.should_not reek
|
50
35
|
end
|
51
|
-
|
52
36
|
it 'should report nothing for 2 defaulted parameters' do
|
53
|
-
|
54
|
-
@rpt.should be_empty
|
37
|
+
'def simple(yep=4, zero=nil) f(3);false end'.should_not reek
|
55
38
|
end
|
56
39
|
end
|
57
40
|
end
|
58
41
|
|
59
42
|
describe 'for methods with too many parameters' do
|
60
43
|
it 'should report 4 parameters' do
|
61
|
-
|
62
|
-
@rpt.length.should == 1
|
63
|
-
@rpt[0].should be_instance_of(LongParameterList)
|
44
|
+
'def simple(arga, argb, argc, argd) f(3);true end'.should reek_only_of(:LongParameterList, /4 parameters/)
|
64
45
|
end
|
65
|
-
|
66
46
|
it 'should report 8 parameters' do
|
67
|
-
|
68
|
-
@rpt.length.should == 1
|
69
|
-
@rpt[0].should be_instance_of(LongParameterList)
|
47
|
+
'def simple(arga, argb, argc, argd,arge, argf, argg, argh) f(3);true end'.should reek_only_of(:LongParameterList, /8 parameters/)
|
70
48
|
end
|
71
49
|
|
72
50
|
describe 'and default values' do
|
73
51
|
it 'should report 3 with 1 defaulted' do
|
74
|
-
|
75
|
-
@rpt.length.should == 1
|
76
|
-
@rpt[0].should be_instance_of(LongParameterList)
|
52
|
+
'def simple(polly, queue, yep, zero=nil) f(3);false end'.should reek_only_of(:LongParameterList, /4 parameters/)
|
77
53
|
end
|
78
|
-
|
79
54
|
it 'should report with 3 defaulted' do
|
80
|
-
|
81
|
-
@rpt.length.should == 1
|
82
|
-
@rpt[0].should be_instance_of(LongParameterList)
|
55
|
+
'def simple(aarg, polly=2, yep=true, zero=nil) f(3);false end'.should reek_only_of(:LongParameterList, /4 parameters/)
|
83
56
|
end
|
84
57
|
end
|
85
58
|
|
86
59
|
describe 'in a class' do
|
60
|
+
before(:each) do
|
61
|
+
@rpt = Report.new
|
62
|
+
@cchk = CodeParser.new(@rpt, SmellConfig.new.smell_listeners)
|
63
|
+
end
|
64
|
+
|
87
65
|
class InnerTest
|
88
66
|
def xyzero(arga,argb) f(3);true end
|
89
67
|
def abc(argx,yep,zero,argm) f(3);false end
|
@@ -92,47 +70,23 @@ describe MethodChecker, "(Long Parameter List)" do
|
|
92
70
|
it 'should only report long param list' do
|
93
71
|
@cchk.check_object(InnerTest)
|
94
72
|
@rpt.length.should == 1
|
95
|
-
@rpt[0].should
|
73
|
+
@rpt[0].report.should match(/Long Parameter List/)
|
96
74
|
end
|
97
75
|
end
|
98
76
|
end
|
99
77
|
|
100
78
|
describe 'yield' do
|
79
|
+
it 'should not report yield with no parameters' do
|
80
|
+
'def simple(arga, argb, &blk) f(3);yield; end'.should_not reek
|
81
|
+
end
|
101
82
|
it 'should not report yield with few parameters' do
|
102
|
-
|
103
|
-
@rpt.should be_empty
|
83
|
+
'def simple(arga, argb, &blk) f(3);yield a,b; end'.should_not reek
|
104
84
|
end
|
105
|
-
|
106
85
|
it 'should report yield with many parameters' do
|
107
|
-
|
108
|
-
|
109
|
-
|
86
|
+
'def simple(arga, argb, &blk) f(3);yield a,b,a,b; end'.should reek_only_of(:LongYieldList, /simple/, /yields/, /4/)
|
87
|
+
end
|
88
|
+
it 'should not report yield of a long expression' do
|
89
|
+
'def simple(arga, argb, &blk) f(3);yield(if @dec then argb else 5+3 end); end'.should_not reek
|
110
90
|
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
describe LongParameterList, 'when given the class name' do
|
117
|
-
|
118
|
-
before(:each) do
|
119
|
-
@rpt = Report.new
|
120
|
-
@cchk = MethodChecker.new(@rpt, 'classname')
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'should report the class name' do
|
124
|
-
@cchk.check_source('def simple(arga, argb, argc, argd) f(3);true end')
|
125
|
-
@rpt.length.should == 1
|
126
|
-
@rpt[0].should be_instance_of(LongParameterList)
|
127
|
-
@rpt[0].report.should match(/classname#simple/)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe LongParameterList, '#report' do
|
132
|
-
it 'should report the method name and num params' do
|
133
|
-
mchk = MethodChecker.new([], 'Class')
|
134
|
-
smell = LongParameterList.new(mchk)
|
135
|
-
smell.report.should match(/Class/)
|
136
91
|
end
|
137
|
-
|
138
92
|
end
|
@@ -1,43 +1,33 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
2
|
|
3
|
-
require 'reek/
|
4
|
-
require 'reek/report'
|
5
|
-
|
6
|
-
include Reek
|
7
|
-
|
8
|
-
def check(desc, src, expected, pending_str = nil)
|
9
|
-
it(desc) do
|
10
|
-
pending(pending_str) unless pending_str.nil?
|
11
|
-
rpt = Report.new
|
12
|
-
cchk = MethodChecker.new(rpt, 'Thing')
|
13
|
-
cchk.check_source(src)
|
14
|
-
rpt.length.should == expected.length
|
15
|
-
(0...rpt.length).each do |smell|
|
16
|
-
expected[smell].each { |patt| rpt[smell].detailed_report.should match(patt) }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
3
|
+
require 'reek/smells/nested_iterators'
|
20
4
|
|
21
|
-
|
5
|
+
include Reek::Smells
|
22
6
|
|
23
|
-
|
24
|
-
|
7
|
+
describe NestedIterators do
|
8
|
+
|
9
|
+
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)
|
11
|
+
end
|
25
12
|
|
26
|
-
|
13
|
+
it 'should not report method with successive iterators' do
|
27
14
|
'def bad(fred)
|
28
15
|
@fred.each {|item| item.each }
|
29
16
|
@jim.each {|ting| ting.each }
|
30
|
-
end'
|
17
|
+
end'.should_not reek
|
18
|
+
end
|
31
19
|
|
32
|
-
|
20
|
+
it 'should not report method with chained iterators' do
|
33
21
|
'def chained
|
34
|
-
@sig.keys.sort_by { |
|
35
|
-
end'
|
22
|
+
@sig.keys.sort_by { |xray| xray.to_s }.each { |min| md5 << min.to_s }
|
23
|
+
end'.should_not reek
|
24
|
+
end
|
36
25
|
|
37
|
-
|
26
|
+
it 'should report nested iterators only once per method' do
|
38
27
|
'def bad(fred)
|
39
|
-
|
40
|
-
|
41
|
-
end'
|
28
|
+
@fred.each {|item| item.each {|part| @joe.send} }
|
29
|
+
@jim.each {|ting| ting.each {|piece| @hal.send} }
|
30
|
+
end'.should reek_only_of(:NestedIterators)
|
31
|
+
end
|
42
32
|
end
|
43
33
|
|
@@ -1,33 +1,24 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
2
|
|
3
|
-
require 'reek/smells'
|
3
|
+
require 'reek/smells/smells'
|
4
4
|
|
5
5
|
include Reek
|
6
6
|
|
7
|
-
describe
|
8
|
-
|
9
|
-
|
7
|
+
describe SmellWarning, ' in comparisons' do
|
8
|
+
before :each do
|
9
|
+
@first = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self")
|
10
|
+
@second = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self")
|
10
11
|
end
|
11
|
-
|
12
|
-
it "should display correct name in report" do
|
13
|
-
smell = LongMethod.new(self, 25)
|
14
|
-
smell.report.should match(/[#{smell.name}]/)
|
15
|
-
end
|
16
|
-
end
|
17
12
|
|
18
|
-
describe Smell, ' in comparisons' do
|
19
13
|
it 'should hash equal when the smell is the same' do
|
20
|
-
|
21
|
-
NestedIterators.new(self).hash.should == NestedIterators.new(self).hash
|
14
|
+
@first.hash.should == @second.hash
|
22
15
|
end
|
23
16
|
|
24
17
|
it 'should compare equal when the smell is the same' do
|
25
|
-
|
26
|
-
NestedIterators.new(self).should == NestedIterators.new(self)
|
18
|
+
@first.should == @second
|
27
19
|
end
|
28
20
|
|
29
21
|
it 'should compare equal when using <=>' do
|
30
|
-
(
|
31
|
-
(NestedIterators.new(self) <=> NestedIterators.new(self)).should == 0
|
22
|
+
(@first <=> @second).should == 0
|
32
23
|
end
|
33
|
-
end
|
24
|
+
end
|
@@ -1,83 +1,118 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
-
|
3
|
-
require 'reek/
|
4
|
-
require 'reek/
|
2
|
+
require 'ostruct'
|
3
|
+
require 'reek/method_context'
|
4
|
+
require 'reek/smells/uncommunicative_name'
|
5
5
|
|
6
6
|
include Reek
|
7
|
+
include Reek::Smells
|
7
8
|
|
8
|
-
|
9
|
-
it
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
9
|
+
describe UncommunicativeName, "method name" do
|
10
|
+
it 'should not report one-word method name' do
|
11
|
+
'def help(fred) basics(17) end'.should_not reek
|
12
|
+
end
|
13
|
+
it 'should report one-letter method name' do
|
14
|
+
'def x(fred) basics(17) end'.should reek_only_of(:UncommunicativeName, /x/)
|
15
|
+
end
|
16
|
+
it 'should report name of the form "x2"' do
|
17
|
+
'def x2(fred) basics(17) end'.should reek_only_of(:UncommunicativeName, /x2/)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
describe UncommunicativeName, "field name" do
|
22
|
+
it 'should not report one-word field name' do
|
23
|
+
'class Thing; def help(fred) @simple end end'.should_not reek
|
24
|
+
end
|
25
|
+
it 'should report one-letter fieldname' do
|
26
|
+
'class Thing; def simple(fred) @x end end'.should reek_only_of(:UncommunicativeName, /@x/, /Thing/, /variable name/)
|
27
|
+
end
|
28
|
+
it 'should report name of the form "x2"' do
|
29
|
+
'class Thing; def simple(fred) @x2 end end'.should reek_only_of(:UncommunicativeName, /@x2/, /Thing/, /variable name/)
|
30
|
+
end
|
31
|
+
it 'should report one-letter fieldname in assignment' do
|
32
|
+
'class Thing; def simple(fred) @x = fred end end'.should reek_only_of(:UncommunicativeName, /@x/, /Thing/, /variable name/)
|
33
|
+
end
|
25
34
|
end
|
26
35
|
|
27
|
-
describe
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
36
|
+
describe UncommunicativeName, "local variable name" do
|
37
|
+
it 'should not report one-word variable name' do
|
38
|
+
'def help(fred) simple = jim(45) end'.should_not reek
|
39
|
+
end
|
40
|
+
it 'should report one-letter variable name' do
|
41
|
+
'def simple(fred) x = jim(45) end'.should reek_only_of(:UncommunicativeName, /x/, /variable name/)
|
42
|
+
end
|
43
|
+
it 'should report name of the form "x2"' do
|
44
|
+
'def simple(fred) x2 = jim(45) end'.should reek_only_of(:UncommunicativeName, /x2/, /variable name/)
|
45
|
+
end
|
46
|
+
it 'should report variable name only once' do
|
47
|
+
'def simple(fred) x = jim(45); x = y end'.should reek_only_of(:UncommunicativeName, /x/)
|
48
|
+
end
|
32
49
|
end
|
33
50
|
|
34
|
-
describe
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
51
|
+
describe UncommunicativeName, "parameter name" do
|
52
|
+
it 'should not recognise *' do
|
53
|
+
'def help(xray, *) basics(17) end'.should_not reek
|
54
|
+
end
|
55
|
+
it "should report parameter's name" do
|
56
|
+
'def help(x) basics(17) end'.should reek_only_of(:UncommunicativeName, /x/, /variable name/)
|
57
|
+
end
|
58
|
+
it 'should report name of the form "x2"' do
|
59
|
+
'def help(x2) basics(17) end'.should reek_only_of(:UncommunicativeName, /x2/, /variable name/)
|
60
|
+
end
|
39
61
|
end
|
40
62
|
|
41
|
-
describe
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
63
|
+
describe UncommunicativeName, "block parameter name" do
|
64
|
+
it "should report parameter's name" do
|
65
|
+
'def help() @stuff.each {|x|} end'.should reek_only_of(:UncommunicativeName, /x/, /block/, /variable name/)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should report method name via if context" do
|
69
|
+
src = <<EOS
|
70
|
+
def bad
|
71
|
+
unless @mod then
|
72
|
+
@sig.each { |x| x.to_s }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
EOS
|
76
|
+
src.should reek_only_of(:UncommunicativeName, /'x'/)
|
77
|
+
end
|
46
78
|
end
|
47
79
|
|
48
|
-
describe
|
80
|
+
describe UncommunicativeName, "several names" do
|
49
81
|
|
50
|
-
|
82
|
+
it 'should report all bad names' do
|
83
|
+
ruby = Source.from_s('class Oof; def y(x) @z = x end end')
|
84
|
+
ruby.should reek_of(:UncommunicativeName, /'x'/)
|
85
|
+
ruby.should reek_of(:UncommunicativeName, /'y'/)
|
86
|
+
ruby.should reek_of(:UncommunicativeName, /'@z'/)
|
87
|
+
end
|
51
88
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
89
|
+
it 'should report all bad block parameters' do
|
90
|
+
source =<<EOS
|
91
|
+
class Thing
|
92
|
+
def bad(fred)
|
93
|
+
@fred.each {|x| 4 - x }
|
94
|
+
@jim.each {|y| y - 4 }
|
95
|
+
end
|
56
96
|
end
|
57
97
|
EOS
|
58
|
-
|
98
|
+
source.should reek_of(:UncommunicativeName, /'x'/)
|
99
|
+
source.should reek_of(:UncommunicativeName, /'y'/)
|
100
|
+
end
|
59
101
|
end
|
60
102
|
|
61
|
-
require 'ostruct'
|
62
|
-
require 'reek/smells/uncommunicative_name'
|
63
|
-
include Reek::Smells
|
64
|
-
|
65
103
|
describe UncommunicativeName, '#examine' do
|
66
|
-
|
67
104
|
before :each do
|
68
|
-
@
|
69
|
-
@
|
70
|
-
@mc.local_variables = []
|
71
|
-
@mc.instance_variables = []
|
105
|
+
@report = Report.new
|
106
|
+
@uc = UncommunicativeName.new
|
72
107
|
end
|
73
|
-
|
108
|
+
|
74
109
|
it 'should return true when reporting a smell' do
|
75
|
-
|
76
|
-
|
110
|
+
mc = MethodContext.new(StopContext.new, [:defn, :x, nil])
|
111
|
+
@uc.examine(mc, @report).should == true
|
77
112
|
end
|
78
113
|
|
79
114
|
it 'should return false when not reporting a smell' do
|
80
|
-
|
81
|
-
|
115
|
+
mc = MethodContext.new(StopContext.new, [:defn, :not_bad, nil])
|
116
|
+
@uc.examine(mc, @report).should == false
|
82
117
|
end
|
83
118
|
end
|