teksymmetry-reek 1.1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/History.txt +131 -0
  2. data/README.txt +36 -0
  3. data/Rakefile +17 -0
  4. data/bin/reek +27 -0
  5. data/config/defaults.reek +51 -0
  6. data/lib/reek/block_context.rb +59 -0
  7. data/lib/reek/class_context.rb +68 -0
  8. data/lib/reek/code_context.rb +54 -0
  9. data/lib/reek/code_parser.rb +221 -0
  10. data/lib/reek/exceptions.reek +13 -0
  11. data/lib/reek/if_context.rb +25 -0
  12. data/lib/reek/method_context.rb +91 -0
  13. data/lib/reek/module_context.rb +33 -0
  14. data/lib/reek/name.rb +49 -0
  15. data/lib/reek/object_refs.rb +52 -0
  16. data/lib/reek/object_source.rb +53 -0
  17. data/lib/reek/options.rb +100 -0
  18. data/lib/reek/rake_task.rb +121 -0
  19. data/lib/reek/report.rb +81 -0
  20. data/lib/reek/sexp_formatter.rb +10 -0
  21. data/lib/reek/singleton_method_context.rb +27 -0
  22. data/lib/reek/smell_warning.rb +49 -0
  23. data/lib/reek/smells/control_couple.rb +61 -0
  24. data/lib/reek/smells/duplication.rb +50 -0
  25. data/lib/reek/smells/feature_envy.rb +58 -0
  26. data/lib/reek/smells/large_class.rb +69 -0
  27. data/lib/reek/smells/long_method.rb +43 -0
  28. data/lib/reek/smells/long_parameter_list.rb +43 -0
  29. data/lib/reek/smells/long_yield_list.rb +18 -0
  30. data/lib/reek/smells/nested_iterators.rb +28 -0
  31. data/lib/reek/smells/smell_detector.rb +66 -0
  32. data/lib/reek/smells/smells.rb +81 -0
  33. data/lib/reek/smells/uncommunicative_name.rb +97 -0
  34. data/lib/reek/smells/utility_function.rb +34 -0
  35. data/lib/reek/source.rb +127 -0
  36. data/lib/reek/spec.rb +146 -0
  37. data/lib/reek/stop_context.rb +50 -0
  38. data/lib/reek/yield_call_context.rb +12 -0
  39. data/lib/reek.rb +7 -0
  40. data/reek.gemspec +44 -0
  41. data/spec/reek/block_context_spec.rb +40 -0
  42. data/spec/reek/class_context_spec.rb +169 -0
  43. data/spec/reek/code_context_spec.rb +93 -0
  44. data/spec/reek/code_parser_spec.rb +34 -0
  45. data/spec/reek/config_spec.rb +42 -0
  46. data/spec/reek/if_context_spec.rb +17 -0
  47. data/spec/reek/method_context_spec.rb +66 -0
  48. data/spec/reek/module_context_spec.rb +38 -0
  49. data/spec/reek/name_spec.rb +13 -0
  50. data/spec/reek/object_refs_spec.rb +131 -0
  51. data/spec/reek/options_spec.rb +13 -0
  52. data/spec/reek/report_spec.rb +48 -0
  53. data/spec/reek/singleton_method_context_spec.rb +17 -0
  54. data/spec/reek/smells/control_couple_spec.rb +23 -0
  55. data/spec/reek/smells/duplication_spec.rb +81 -0
  56. data/spec/reek/smells/feature_envy_spec.rb +221 -0
  57. data/spec/reek/smells/large_class_spec.rb +87 -0
  58. data/spec/reek/smells/long_method_spec.rb +195 -0
  59. data/spec/reek/smells/long_parameter_list_spec.rb +85 -0
  60. data/spec/reek/smells/nested_iterators_spec.rb +33 -0
  61. data/spec/reek/smells/smell_spec.rb +24 -0
  62. data/spec/reek/smells/uncommunicative_name_spec.rb +123 -0
  63. data/spec/reek/smells/utility_function_spec.rb +93 -0
  64. data/spec/slow/inline_spec.rb +40 -0
  65. data/spec/slow/optparse_spec.rb +109 -0
  66. data/spec/slow/redcloth_spec.rb +101 -0
  67. data/spec/slow/reek_source_spec.rb +20 -0
  68. data/spec/slow/samples/inline.rb +704 -0
  69. data/spec/slow/samples/optparse.rb +1788 -0
  70. data/spec/slow/samples/redcloth.rb +1130 -0
  71. data/spec/slow/script_spec.rb +55 -0
  72. data/spec/slow/source_list_spec.rb +40 -0
  73. data/spec/spec.opts +1 -0
  74. data/spec/spec_helper.rb +13 -0
  75. data/tasks/reek.rake +7 -0
  76. data/tasks/rspec.rake +22 -0
  77. metadata +163 -0
@@ -0,0 +1,123 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+ require 'ostruct'
3
+ require 'reek/method_context'
4
+ require 'reek/smells/uncommunicative_name'
5
+
6
+ include Reek
7
+ include Reek::Smells
8
+
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
+ end
19
+ end
20
+
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
34
+ end
35
+
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
49
+
50
+ it 'should report a bad name inside a block' do
51
+ src = 'def clean(text) text.each { q2 = 3 } end'
52
+ src.should reek_of(:UncommunicativeName, /q2/)
53
+ end
54
+ end
55
+
56
+ describe UncommunicativeName, "parameter name" do
57
+ it 'should not recognise *' do
58
+ 'def help(xray, *) basics(17) end'.should_not reek
59
+ end
60
+ it "should report parameter's name" do
61
+ 'def help(x) basics(17) end'.should reek_only_of(:UncommunicativeName, /x/, /variable name/)
62
+ end
63
+ it 'should report name of the form "x2"' do
64
+ 'def help(x2) basics(17) end'.should reek_only_of(:UncommunicativeName, /x2/, /variable name/)
65
+ end
66
+ end
67
+
68
+ describe UncommunicativeName, "block parameter name" do
69
+ it "should report parameter's name" do
70
+ 'def help() @stuff.each {|x|} end'.should reek_only_of(:UncommunicativeName, /x/, /block/, /variable name/)
71
+ end
72
+
73
+ it "should report method name via if context" do
74
+ src = <<EOS
75
+ def bad
76
+ unless @mod then
77
+ @sig.each { |x| x.to_s }
78
+ end
79
+ end
80
+ EOS
81
+ src.should reek_only_of(:UncommunicativeName, /'x'/)
82
+ end
83
+ end
84
+
85
+ describe UncommunicativeName, "several names" do
86
+
87
+ it 'should report all bad names' do
88
+ ruby = Source.from_s('class Oof; def y(x) @z = x end end')
89
+ ruby.should reek_of(:UncommunicativeName, /'x'/)
90
+ ruby.should reek_of(:UncommunicativeName, /'y'/)
91
+ ruby.should reek_of(:UncommunicativeName, /'@z'/)
92
+ end
93
+
94
+ it 'should report all bad block parameters' do
95
+ source =<<EOS
96
+ class Thing
97
+ def bad(fred)
98
+ @fred.each {|x| 4 - x }
99
+ @jim.each {|y| y - 4 }
100
+ end
101
+ end
102
+ EOS
103
+ source.should reek_of(:UncommunicativeName, /'x'/)
104
+ source.should reek_of(:UncommunicativeName, /'y'/)
105
+ end
106
+ end
107
+
108
+ describe UncommunicativeName, '#examine' do
109
+ before :each do
110
+ @report = Report.new
111
+ @uc = UncommunicativeName.new
112
+ end
113
+
114
+ it 'should return true when reporting a smell' do
115
+ mc = MethodContext.new(StopContext.new, [:defn, :x, nil])
116
+ @uc.examine(mc, @report).should == true
117
+ end
118
+
119
+ it 'should return false when not reporting a smell' do
120
+ mc = MethodContext.new(StopContext.new, [:defn, :not_bad, nil])
121
+ @uc.examine(mc, @report).should == false
122
+ end
123
+ end
@@ -0,0 +1,93 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ require 'reek/smells/utility_function'
4
+
5
+ include Reek
6
+ include Reek::Smells
7
+
8
+ describe UtilityFunction do
9
+
10
+ it 'should not report attrset' do
11
+ class Fred
12
+ attr_writer :xyz
13
+ end
14
+ Fred.should_not reek
15
+ end
16
+
17
+ it 'should count usages of self'do
18
+ 'def <=>(other) Options[:sort_order].compare(self, other) end'.should_not reek
19
+ end
20
+ it 'should count self reference within a dstr' do
21
+ 'def as(alias_name); "#{self} as #{alias_name}".to_sym; end'.should_not reek
22
+ end
23
+ it 'should count calls to self within a dstr' do
24
+ 'def to_sql; "\'#{self.gsub(/\'/, "\'\'")}\'"; end'.should_not reek
25
+ end
26
+ it 'should report simple parameter call' do
27
+ 'def simple(arga) arga.to_s end'.should reek_of(:UtilityFunction, /simple/)
28
+ end
29
+ it 'should report message chain' do
30
+ 'def simple(arga) arga.b.c end'.should reek_of(:UtilityFunction, /simple/)
31
+ end
32
+
33
+ it 'should not report overriding methods' do
34
+ class Father
35
+ def thing(ff); @kids = 0; end
36
+ end
37
+ class Son < Father
38
+ def thing(ff); ff; end
39
+ end
40
+ Son.should_not reek
41
+ end
42
+
43
+ it 'should not report class method' do
44
+ pending('bug')
45
+ source = <<EOS
46
+ class Cache
47
+ class << self
48
+ def create_unless_known(attributes)
49
+ Cache.create(attributes) unless Cache.known?
50
+ end
51
+ end
52
+ end
53
+ EOS
54
+ source.should_not reek
55
+ end
56
+
57
+ it 'should recognise a deep call' do
58
+ src = <<EOS
59
+ class Red
60
+ def deep(text)
61
+ text.each { |mod| atts = shelve(mod) }
62
+ end
63
+
64
+ def shelve(val)
65
+ @shelf << val
66
+ end
67
+ end
68
+ EOS
69
+ src.should_not reek
70
+ end
71
+ end
72
+
73
+ describe UtilityFunction, 'should only report a method containing a call' do
74
+ it 'should not report empty method' do
75
+ 'def simple(arga) end'.should_not reek
76
+ end
77
+ it 'should not report literal' do
78
+ 'def simple(arga) 3; end'.should_not reek
79
+ end
80
+ it 'should not report instance variable reference' do
81
+ 'def simple(arga) @yellow end'.should_not reek
82
+ end
83
+ it 'should not report vcall' do
84
+ 'def simple(arga) y end'.should_not reek
85
+ end
86
+ it 'should not report references to self' do
87
+ 'def into; self; end'.should_not reek
88
+ end
89
+
90
+ it 'should recognise an ivar reference within a block' do
91
+ 'def clean(text) text.each { @fred = 3} end'.should_not reek
92
+ end
93
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe 'sample gem source code' do
4
+ it "reports the correct smells in inline.rb" do
5
+ ruby = File.new("#{SAMPLES_DIR}/inline.rb").to_source
6
+ ruby.should reek_of(:ControlCouple, /Inline::C#parse_signature/, /raw/)
7
+ ruby.should reek_of(:ControlCouple, /Module#inline/, /options/)
8
+ ruby.should reek_of(:Duplication, /Inline::C#build/, /\(\$\?\ == 0\)/)
9
+ ruby.should reek_of(:Duplication, /Inline::C#build/, /Inline.directory/)
10
+ ruby.should reek_of(:Duplication, /Inline::C#build/, /io.puts/)
11
+ ruby.should reek_of(:Duplication, /Inline::C#build/, /io.puts\("#endif"\)/)
12
+ ruby.should reek_of(:Duplication, /Inline::C#build/, /io.puts\("#ifdef __cplusplus"\)/)
13
+ ruby.should reek_of(:Duplication, /Inline::C#build/, /module_name/)
14
+ ruby.should reek_of(:Duplication, /Inline::C#build/, /warn\("Output:\\n\#\{result\}"\)/)
15
+ ruby.should reek_of(:Duplication, /Inline::C#crap_for_windoze/, /Config::CONFIG\["libdir"\]/)
16
+ ruby.should reek_of(:Duplication, /Inline::C#generate/, /result.sub!\(\/\\A\\n\/, ""\)/)
17
+ ruby.should reek_of(:Duplication, /Inline::C#generate/, /signature\["args"\]/)
18
+ ruby.should reek_of(:Duplication, /Inline::C#generate/, /signature\["args"\].map/)
19
+ ruby.should reek_of(:Duplication, /Inline::C#initialize/, /stack.empty?/)
20
+ ruby.should reek_of(:Duplication, /Inline::C#load/, /so_name/)
21
+ ruby.should reek_of(:Duplication, /Inline::self.rootdir/, /env.nil?/)
22
+ ruby.should reek_of(:Duplication, /Module#inline/, /Inline.const_get\(lang\)/)
23
+ ruby.should reek_of(:FeatureEnvy, /Inline::C#strip_comments/, /src/)
24
+ ruby.should reek_of(:LargeClass, /Inline::C/, /instance variables/)
25
+ ruby.should reek_of(:LongMethod, /Inline::C#build/)
26
+ ruby.should reek_of(:LongMethod, /Inline::C#generate/)
27
+ ruby.should reek_of(:LongMethod, /Inline::C#parse_signature/)
28
+ ruby.should reek_of(:LongMethod, /Inline::self.rootdir/)
29
+ ruby.should reek_of(:LongMethod, /Module#inline/)
30
+ ruby.should reek_of(:NestedIterators, /Inline::C#build/)
31
+ ruby.should reek_of(:UncommunicativeName, /Inline::C#build/, /'t'/)
32
+ ruby.should reek_of(:UncommunicativeName, /Inline::C#build/, /'n'/)
33
+ ruby.should reek_of(:UncommunicativeName, /Inline::C#c/, /'c'/)
34
+ ruby.should reek_of(:UncommunicativeName, /Inline::C#module_name/, /'m'/)
35
+ ruby.should reek_of(:UncommunicativeName, /Inline::C#module_name/, /'x'/)
36
+ ruby.should reek_of(:UncommunicativeName, /Inline::C#parse_signature/, /'x'/)
37
+ ruby.should reek_of(:UtilityFunction, /Inline::C#strip_comments/)
38
+ ruby.report.should have_at_most(32).smells
39
+ end
40
+ end
@@ -0,0 +1,109 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe 'sample gem source code' do
4
+ it "reports the correct smells in optparse.rb" do
5
+ ruby = File.new("#{SAMPLES_DIR}/optparse.rb").to_source
6
+ ruby.should reek_of(:ControlCouple, /OptionParser#List#accept/, /pat/)
7
+ ruby.should reek_of(:ControlCouple, /OptionParser#List#update/, /lopts/)
8
+ ruby.should reek_of(:ControlCouple, /OptionParser#List#update/, /sopts/)
9
+ ruby.should reek_of(:ControlCouple, /OptionParser#ParseError#set_option/, /eq/)
10
+ ruby.should reek_of(:ControlCouple, /OptionParser#Switch#NoArgument#parse/, /arg/)
11
+ ruby.should reek_of(:ControlCouple, /OptionParser#Switch#OptionalArgument#parse/, /arg/)
12
+ ruby.should reek_of(:ControlCouple, /OptionParser#Switch#RequiredArgument#parse/, /arg/)
13
+ ruby.should reek_of(:ControlCouple, /OptionParser#block/, /o/)
14
+ ruby.should reek_of(:ControlCouple, /OptionParser#block/, /s/)
15
+ ruby.should reek_of(:ControlCouple, /OptionParser#block\/block/, /pkg/)
16
+ ruby.should reek_of(:ControlCouple, /OptionParser#getopts\/block/, /val/)
17
+ ruby.should reek_of(:ControlCouple, /OptionParser#parse_in_order/, /setter/)
18
+ ruby.should reek_of(:Duplication, /OptionParser#Completion::complete/, /candidates.size/)
19
+ ruby.should reek_of(:Duplication, /OptionParser#Completion::complete/, /k.id2name/)
20
+ ruby.should reek_of(:Duplication, /OptionParser#Switch#parse_arg/, /s.length/)
21
+ ruby.should reek_of(:Duplication, /OptionParser#Switch#summarize/, /left.collect \{ \|s\| s\.length \}\.max/)
22
+ ruby.should reek_of(:Duplication, /OptionParser#Switch#summarize/, /left.collect \{ \|s\| s\.length \}\.max\.to_i/)
23
+ ruby.should reek_of(:Duplication, /OptionParser#Switch#summarize/, /\(indent \+ l\)/)
24
+ ruby.should reek_of(:Duplication, /OptionParser#Switch#summarize/, /left.collect/)
25
+ ruby.should reek_of(:Duplication, /OptionParser#Switch#summarize/, /left.shift/)
26
+ ruby.should reek_of(:Duplication, /OptionParser#Switch#summarize/, /left\[-1\]/)
27
+ ruby.should reek_of(:Duplication, /OptionParser#Switch#summarize/, /s.length/)
28
+ ruby.should reek_of(:Duplication, /OptionParser#getopts/, /result\[opt\] = false/)
29
+ ruby.should reek_of(:Duplication, /OptionParser#make_switch/, /default_style.guess\(arg = a\)/)
30
+ ruby.should reek_of(:Duplication, /OptionParser#make_switch/, /\(long << o = q.downcase\)/)
31
+ ruby.should reek_of(:Duplication, /OptionParser#make_switch/, /notwice\(a \? \(Object\) : \(TrueClass\), klass, "type"\)/)
32
+ ruby.should reek_of(:Duplication, /OptionParser#make_switch/, /notwice\(NilClass, klass, "type"\)/)
33
+ ruby.should reek_of(:Duplication, /OptionParser#make_switch/, /pattern.method\(:convert\)/)
34
+ ruby.should reek_of(:Duplication, /OptionParser#make_switch/, /pattern.method\(:convert\).to_proc/)
35
+ ruby.should reek_of(:Duplication, /OptionParser#make_switch/, /pattern.respond_to\?\(:convert\)/)
36
+ ruby.should reek_of(:Duplication, /OptionParser#make_switch/, /q.downcase/)
37
+ ruby.should reek_of(:Duplication, /OptionParser#make_switch/, /search\(:atype, o\)/)
38
+ ruby.should reek_of(:Duplication, /OptionParser#make_switch/, /search\(:atype, FalseClass\)/)
39
+ ruby.should reek_of(:Duplication, /OptionParser#make_switch/, /\(sdesc << "-\#\{q\}"\)/)
40
+ ruby.should reek_of(:Duplication, /OptionParser#order/, /argv\[0\]/)
41
+ ruby.should reek_of(:Duplication, /OptionParser#parse/, /argv\[0\]/)
42
+ ruby.should reek_of(:Duplication, /OptionParser#parse_in_order/, /\$\!.set_option\(arg, true\)/)
43
+ ruby.should reek_of(:Duplication, /OptionParser#parse_in_order/, /cb.call\(val\)/)
44
+ ruby.should reek_of(:Duplication, /OptionParser#parse_in_order/, /setter.call\(sw.switch_name, val\)/)
45
+ ruby.should reek_of(:Duplication, /OptionParser#parse_in_order/, /sw.block/)
46
+ ruby.should reek_of(:Duplication, /OptionParser#parse_in_order/, /sw.switch_name/)
47
+ ruby.should reek_of(:Duplication, /OptionParser#permute/, /argv\[0\]/)
48
+ ruby.should reek_of(:FeatureEnvy, /OptionParser#Completion::complete/, /candidates/)
49
+ ruby.should reek_of(:FeatureEnvy, /OptionParser#List#accept/, /pat/)
50
+ ruby.should reek_of(:FeatureEnvy, /OptionParser#Switch#summarize/, /left/)
51
+ ruby.should reek_of(:FeatureEnvy, /OptionParser#order/, /argv/)
52
+ ruby.should reek_of(:FeatureEnvy, /OptionParser#parse/, /argv/)
53
+ ruby.should reek_of(:FeatureEnvy, /OptionParser#permute/, /argv/)
54
+ ruby.should reek_of(:LargeClass, /OptionParser/)
55
+ ruby.should reek_of(:LongMethod, /OptionParser#Completion::complete/)
56
+ ruby.should reek_of(:LongMethod, /OptionParser#List#update/)
57
+ ruby.should reek_of(:LongMethod, /OptionParser#Switch#PlacedArgument#parse/)
58
+ ruby.should reek_of(:LongMethod, /OptionParser#Switch#parse_arg/)
59
+ ruby.should reek_of(:LongMethod, /OptionParser#Switch#summarize/)
60
+ ruby.should reek_of(:LongMethod, /OptionParser#getopts/)
61
+ ruby.should reek_of(:LongMethod, /OptionParser#make_switch/)
62
+ ruby.should reek_of(:LongMethod, /OptionParser#parse_in_order/)
63
+ ruby.should reek_of(:LongParameterList, /OptionParser#List#complete/)
64
+ ruby.should reek_of(:LongParameterList, /OptionParser#List#update/)
65
+ ruby.should reek_of(:LongParameterList, /OptionParser#Switch#initialize/)
66
+ ruby.should reek_of(:LongParameterList, /OptionParser#Switch#summarize/)
67
+ ruby.should reek_of(:LongParameterList, /OptionParser#complete/)
68
+ ruby.should reek_of(:LongParameterList, /OptionParser#summarize/)
69
+ ruby.should reek_of(:NestedIterators, /OptionParser#CompletingHash#match/)
70
+ ruby.should reek_of(:NestedIterators, /OptionParser#Switch#summarize/)
71
+ ruby.should reek_of(:NestedIterators, /OptionParser#block/)
72
+ ruby.should reek_of(:NestedIterators, /OptionParser#complete/)
73
+ ruby.should reek_of(:NestedIterators, /OptionParser#make_switch/)
74
+ ruby.should reek_of(:NestedIterators, /OptionParser#make_switch/)
75
+ ruby.should reek_of(:NestedIterators, /OptionParser#parse_in_order/)
76
+ ruby.should reek_of(:NestedIterators, /OptionParser#parse_in_order/)
77
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#Completion::complete/, /'k'/)
78
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#Completion::complete/, /'v'/)
79
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#List#accept/, /'t'/)
80
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#List#reject/, /'t'/)
81
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#List#update/, /'o'/)
82
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#Switch#add_banner/, /'s'/)
83
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#Switch#parse_arg/, /'m'/)
84
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#Switch#parse_arg/, /'s'/)
85
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#Switch#self.guess/, /'t'/)
86
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#Switch#self.incompatible_argument_styles/, /'t'/)
87
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#Switch#summarize/, /'l'/)
88
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#Switch#summarize/, /'r'/)
89
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#Switch#summarize/, /'s'/)
90
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#block/, /'f'/)
91
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#block/, /'k'/)
92
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#block/, /'o'/)
93
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#block/, /'s'/)
94
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#block/, /'v'/)
95
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#load/, /'s'/)
96
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#make_switch/, /'a'/)
97
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#make_switch/, /'n'/)
98
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#make_switch/, /'o'/)
99
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#make_switch/, /'q'/)
100
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#make_switch/, /'s'/)
101
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#make_switch/, /'c'/)
102
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#make_switch/, /'v'/)
103
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#search/, /'k'/)
104
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#summarize/, /'l'/)
105
+ ruby.should reek_of(:UncommunicativeName, /OptionParser#ver/, /'v'/)
106
+ ruby.should reek_of(:UncommunicativeName, /block/, /'q'/)
107
+ ruby.report.should have_at_most(117).smells
108
+ end
109
+ end
@@ -0,0 +1,101 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe 'sample gem source code' do
4
+ it "reports the correct smells in redcloth.rb" do
5
+ ruby = File.new("#{SAMPLES_DIR}/redcloth.rb").to_source
6
+ ruby.should reek_of(:ControlCouple, /RedCloth#blocks\/block/, /deep_code/)
7
+ ruby.should reek_of(:ControlCouple, /RedCloth#check_refs/, /text/)
8
+ ruby.should reek_of(:ControlCouple, /RedCloth#pba/, /text_in/)
9
+ ruby.should reek_of(:ControlCouple, /RedCloth#textile_bq/, /atts/)
10
+ ruby.should reek_of(:ControlCouple, /RedCloth#textile_bq/, /cite/)
11
+ ruby.should reek_of(:ControlCouple, /RedCloth#textile_fn_/, /atts/)
12
+ ruby.should reek_of(:ControlCouple, /RedCloth#textile_p/, /atts/)
13
+ ruby.should reek_of(:Duplication, /RedCloth#block_textile_lists/, /depth.last/)
14
+ ruby.should reek_of(:Duplication, /RedCloth#block_textile_lists/, /depth.last.length/)
15
+ ruby.should reek_of(:Duplication, /RedCloth#block_textile_lists/, /depth\[i\]/)
16
+ ruby.should reek_of(:Duplication, /RedCloth#block_textile_lists/, /\(line_id - 1\)/)
17
+ ruby.should reek_of(:Duplication, /RedCloth#block_textile_lists/, /lines\[\(line_id - 1\)\]/)
18
+ ruby.should reek_of(:Duplication, /RedCloth#block_textile_lists/, /tl.length/)
19
+ ruby.should reek_of(:Duplication, /RedCloth#clean_html/, /tags\[tag\]/)
20
+ ruby.should reek_of(:Duplication, /RedCloth#pba/, /\$1.length/)
21
+ ruby.should reek_of(:Duplication, /RedCloth#rip_offtags/, /@pre_list.last/)
22
+ ruby.should reek_of(:Duplication, /RedCloth#rip_offtags/, /\(@pre_list.last << line\)/)
23
+ ruby.should reek_of(:Duplication, /RedCloth#rip_offtags/, /\(codepre - used_offtags.length\)/)
24
+ ruby.should reek_of(:Duplication, /RedCloth#rip_offtags/, /\(\(codepre - used_offtags.length\) > 0\)/)
25
+ ruby.should reek_of(:Duplication, /RedCloth#rip_offtags/, /codepre.zero?/)
26
+ ruby.should reek_of(:Duplication, /RedCloth#rip_offtags/, /htmlesc\(line, :NoQuotes\)/)
27
+ ruby.should reek_of(:Duplication, /RedCloth#rip_offtags/, /used_offtags.length/)
28
+ ruby.should reek_of(:Duplication, /RedCloth#rip_offtags/, /used_offtags\["notextile"\]/)
29
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#block_markdown_atx/, /text/)
30
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#block_markdown_rule/, /text/)
31
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#block_markdown_setext/, /text/)
32
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#block_textile_lists/, /depth/)
33
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#clean_html/, /raw/)
34
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#clean_html/, /tags/)
35
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#clean_white_space/, /text/)
36
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#flush_left/, /indt/)
37
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#flush_left/, /text/)
38
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#footnote_ref/, /text/)
39
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#htmlesc/, /str/)
40
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#incoming_entities/, /text/)
41
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#no_textile/, /text/)
42
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#pba/, /style/)
43
+ ruby.should reek_of(:FeatureEnvy, /RedCloth#pba/, /text/)
44
+ ruby.should reek_of(:LargeClass, /RedCloth/)
45
+ ruby.should reek_of(:LongMethod, /RedCloth#block_markdown_bq/)
46
+ ruby.should reek_of(:LongMethod, /RedCloth#block_textile_lists/)
47
+ ruby.should reek_of(:LongMethod, /RedCloth#block_textile_table/)
48
+ ruby.should reek_of(:LongMethod, /RedCloth#blocks/)
49
+ ruby.should reek_of(:LongMethod, /RedCloth#clean_html/)
50
+ ruby.should reek_of(:LongMethod, /RedCloth#clean_white_space/)
51
+ ruby.should reek_of(:LongMethod, /RedCloth#glyphs_textile/)
52
+ ruby.should reek_of(:LongMethod, /RedCloth#inline_markdown_link/)
53
+ ruby.should reek_of(:LongMethod, /RedCloth#inline_markdown_reflink/)
54
+ ruby.should reek_of(:LongMethod, /RedCloth#inline_textile_image/)
55
+ ruby.should reek_of(:LongMethod, /RedCloth#inline_textile_link/)
56
+ ruby.should reek_of(:LongMethod, /RedCloth#inline_textile_span/)
57
+ ruby.should reek_of(:LongMethod, /RedCloth#pba/)
58
+ ruby.should reek_of(:LongMethod, /RedCloth#rip_offtags/)
59
+ ruby.should reek_of(:LongMethod, /RedCloth#to_html/)
60
+ ruby.should reek_of(:LongParameterList, /RedCloth#textile_bq/)
61
+ ruby.should reek_of(:LongParameterList, /RedCloth#textile_fn_/)
62
+ ruby.should reek_of(:LongParameterList, /RedCloth#textile_p/)
63
+ ruby.should reek_of(:NestedIterators, /RedCloth#block_textile_lists/)
64
+ ruby.should reek_of(:NestedIterators, /RedCloth#block_textile_lists/)
65
+ ruby.should reek_of(:NestedIterators, /RedCloth#block_textile_table/)
66
+ ruby.should reek_of(:NestedIterators, /RedCloth#block_textile_table/)
67
+ ruby.should reek_of(:NestedIterators, /RedCloth#blocks/)
68
+ ruby.should reek_of(:NestedIterators, /RedCloth#clean_html/)
69
+ ruby.should reek_of(:NestedIterators, /RedCloth#clean_html/)
70
+ ruby.should reek_of(:NestedIterators, /RedCloth#inline/)
71
+ ruby.should reek_of(:NestedIterators, /RedCloth#inline_textile_span/)
72
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#block/, /'a'/)
73
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#block/, /'b'/)
74
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#block_textile_lists/, /'i'/)
75
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#block_textile_lists/, /'v'/)
76
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#block_textile_table/, /'x'/)
77
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#clean_html/, /'q'/)
78
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#clean_html/, /'q2'/)
79
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#initialize/, /'r'/)
80
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#inline_markdown_link/, /'m'/)
81
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#inline_markdown_reflink/, /'m'/)
82
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#inline_textile_code/, /'m'/)
83
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#inline_textile_image/, /'m'/)
84
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#inline_textile_link/, /'m'/)
85
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#inline_textile_span/, /'m'/)
86
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#refs_markdown/, /'m'/)
87
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#refs_textile/, /'m'/)
88
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#retrieve/, /'i'/)
89
+ ruby.should reek_of(:UncommunicativeName, /RedCloth#retrieve/, /'r'/)
90
+ ruby.should reek_of(:UtilityFunction, /RedCloth#block_markdown_rule/)
91
+ ruby.should reek_of(:UtilityFunction, /RedCloth#clean_html/)
92
+ ruby.should reek_of(:UtilityFunction, /RedCloth#flush_left/)
93
+ ruby.should reek_of(:UtilityFunction, /RedCloth#footnote_ref/)
94
+ ruby.should reek_of(:UtilityFunction, /RedCloth#h_align/)
95
+ ruby.should reek_of(:UtilityFunction, /RedCloth#htmlesc/)
96
+ ruby.should reek_of(:UtilityFunction, /RedCloth#incoming_entities/)
97
+ ruby.should reek_of(:UtilityFunction, /RedCloth#no_textile/)
98
+ ruby.should reek_of(:UtilityFunction, /RedCloth#v_align/)
99
+ ruby.report.should have_at_most(93).smells
100
+ end
101
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe 'Reek source code:' do
4
+ Dir['lib/**/*.rb'].each do |path|
5
+ it "reports no smells in #{path}" do
6
+ File.new(path).should_not reek
7
+ end
8
+ end
9
+
10
+ it 'reports no smells via the Dir matcher' do
11
+ Dir['lib/**/*.rb'].should_not reek
12
+ end
13
+ end
14
+
15
+ describe 'RakeTask' do
16
+ it 'should report no duplication' do
17
+ report = `rake reek`.split("\n")
18
+ report.length.should == 1
19
+ end
20
+ end