reek 1.2.6 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. data/.yardopts +10 -0
  2. data/History.txt +62 -0
  3. data/README.md +74 -0
  4. data/bin/reek +2 -2
  5. data/config/defaults.reek +44 -5
  6. data/features/api.feature +20 -0
  7. data/features/masking_smells.feature +60 -42
  8. data/features/options.feature +7 -2
  9. data/features/rake_task.feature +29 -22
  10. data/features/reports.feature +9 -41
  11. data/features/samples.feature +184 -196
  12. data/features/stdin.feature +5 -8
  13. data/features/step_definitions/reek_steps.rb +8 -4
  14. data/features/support/env.rb +2 -3
  15. data/features/yaml.feature +85 -0
  16. data/lib/reek/cli/application.rb +46 -0
  17. data/lib/reek/cli/command_line.rb +108 -0
  18. data/lib/reek/cli/help_command.rb +18 -0
  19. data/lib/reek/cli/reek_command.rb +37 -0
  20. data/lib/reek/cli/report.rb +58 -0
  21. data/lib/reek/cli/version_command.rb +19 -0
  22. data/lib/reek/cli/yaml_command.rb +32 -0
  23. data/lib/reek/core/code_context.rb +64 -0
  24. data/lib/reek/core/code_parser.rb +166 -0
  25. data/lib/reek/core/method_context.rb +84 -0
  26. data/lib/reek/core/module_context.rb +20 -0
  27. data/lib/reek/core/object_refs.rb +51 -0
  28. data/lib/reek/core/singleton_method_context.rb +20 -0
  29. data/lib/reek/core/smell_configuration.rb +62 -0
  30. data/lib/reek/core/sniffer.rb +105 -0
  31. data/lib/reek/core/stop_context.rb +30 -0
  32. data/lib/reek/core/warning_collector.rb +27 -0
  33. data/lib/reek/examiner.rb +104 -0
  34. data/lib/reek/rake/task.rb +142 -0
  35. data/lib/reek/smell_warning.rb +73 -23
  36. data/lib/reek/smells/attribute.rb +26 -21
  37. data/lib/reek/smells/boolean_parameter.rb +38 -0
  38. data/lib/reek/smells/class_variable.rb +22 -9
  39. data/lib/reek/smells/control_couple.rb +40 -16
  40. data/lib/reek/smells/data_clump.rb +114 -23
  41. data/lib/reek/smells/duplication.rb +55 -15
  42. data/lib/reek/smells/feature_envy.rb +16 -7
  43. data/lib/reek/smells/irresponsible_module.rb +37 -0
  44. data/lib/reek/smells/large_class.rb +37 -19
  45. data/lib/reek/smells/long_method.rb +20 -9
  46. data/lib/reek/smells/long_parameter_list.rb +22 -10
  47. data/lib/reek/smells/long_yield_list.rb +43 -7
  48. data/lib/reek/smells/nested_iterators.rb +68 -8
  49. data/lib/reek/smells/simulated_polymorphism.rb +26 -15
  50. data/lib/reek/smells/smell_detector.rb +29 -51
  51. data/lib/reek/smells/uncommunicative_method_name.rb +74 -0
  52. data/lib/reek/smells/uncommunicative_module_name.rb +74 -0
  53. data/lib/reek/smells/uncommunicative_parameter_name.rb +79 -0
  54. data/lib/reek/smells/uncommunicative_variable_name.rb +89 -0
  55. data/lib/reek/smells/utility_function.rb +51 -12
  56. data/lib/reek/smells.rb +29 -0
  57. data/lib/reek/source/code_comment.rb +37 -0
  58. data/lib/reek/source/config_file.rb +72 -0
  59. data/lib/reek/source/core_extras.rb +46 -0
  60. data/lib/reek/source/reference_collector.rb +28 -0
  61. data/lib/reek/source/sexp_formatter.rb +17 -0
  62. data/lib/reek/source/source_code.rb +44 -0
  63. data/lib/reek/source/source_file.rb +32 -0
  64. data/lib/reek/source/source_locator.rb +42 -0
  65. data/lib/reek/source/tree_dresser.rb +204 -0
  66. data/lib/reek/source.rb +18 -0
  67. data/lib/reek/spec/should_reek.rb +31 -0
  68. data/lib/reek/spec/should_reek_of.rb +37 -0
  69. data/lib/reek/spec/should_reek_only_of.rb +37 -0
  70. data/lib/reek/spec.rb +51 -0
  71. data/lib/reek.rb +8 -4
  72. data/reek.gemspec +9 -7
  73. data/spec/matchers/smell_of_matcher.rb +58 -0
  74. data/spec/reek/{help_command_spec.rb → cli/help_command_spec.rb} +3 -4
  75. data/spec/reek/cli/reek_command_spec.rb +46 -0
  76. data/spec/reek/cli/report_spec.rb +30 -0
  77. data/spec/reek/{version_command_spec.rb → cli/version_command_spec.rb} +3 -3
  78. data/spec/reek/cli/yaml_command_spec.rb +47 -0
  79. data/spec/reek/core/code_context_spec.rb +145 -0
  80. data/spec/reek/{code_parser_spec.rb → core/code_parser_spec.rb} +7 -6
  81. data/spec/reek/{config_spec.rb → core/config_spec.rb} +2 -6
  82. data/spec/reek/{method_context_spec.rb → core/method_context_spec.rb} +16 -36
  83. data/spec/reek/core/module_context_spec.rb +27 -0
  84. data/spec/reek/{object_refs_spec.rb → core/object_refs_spec.rb} +5 -6
  85. data/spec/reek/core/singleton_method_context_spec.rb +9 -0
  86. data/spec/reek/core/smell_configuration_spec.rb +11 -0
  87. data/spec/reek/core/stop_context_spec.rb +17 -0
  88. data/spec/reek/core/warning_collector_spec.rb +27 -0
  89. data/spec/reek/examiner_spec.rb +103 -0
  90. data/spec/reek/smell_warning_spec.rb +74 -82
  91. data/spec/reek/smells/attribute_spec.rb +42 -23
  92. data/spec/reek/smells/behaves_like_variable_detector.rb +2 -2
  93. data/spec/reek/smells/boolean_parameter_spec.rb +66 -0
  94. data/spec/reek/smells/class_variable_spec.rb +60 -75
  95. data/spec/reek/smells/control_couple_spec.rb +37 -32
  96. data/spec/reek/smells/data_clump_spec.rb +63 -24
  97. data/spec/reek/smells/duplication_spec.rb +106 -57
  98. data/spec/reek/smells/feature_envy_spec.rb +113 -92
  99. data/spec/reek/smells/irresponsible_module_spec.rb +58 -0
  100. data/spec/reek/smells/large_class_spec.rb +67 -57
  101. data/spec/reek/smells/long_method_spec.rb +40 -10
  102. data/spec/reek/smells/long_parameter_list_spec.rb +50 -28
  103. data/spec/reek/smells/long_yield_list_spec.rb +57 -0
  104. data/spec/reek/smells/nested_iterators_spec.rb +115 -7
  105. data/spec/reek/smells/simulated_polymorphism_spec.rb +56 -20
  106. data/spec/reek/smells/smell_detector_shared.rb +42 -0
  107. data/spec/reek/smells/uncommunicative_method_name_spec.rb +42 -0
  108. data/spec/reek/smells/uncommunicative_module_name_spec.rb +66 -0
  109. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +71 -0
  110. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +120 -0
  111. data/spec/reek/smells/utility_function_spec.rb +50 -4
  112. data/spec/reek/source/code_comment_spec.rb +82 -0
  113. data/spec/reek/source/object_source_spec.rb +20 -0
  114. data/spec/reek/source/reference_collector_spec.rb +53 -0
  115. data/spec/reek/{adapters/source_spec.rb → source/source_code_spec.rb} +7 -8
  116. data/spec/reek/source/tree_dresser_spec.rb +270 -0
  117. data/spec/reek/spec/should_reek_of_spec.rb +76 -0
  118. data/spec/reek/spec/should_reek_only_of_spec.rb +89 -0
  119. data/spec/reek/{adapters → spec}/should_reek_spec.rb +8 -32
  120. data/spec/samples/all_but_one_masked/clean_one.rb +1 -0
  121. data/spec/samples/all_but_one_masked/dirty.rb +1 -0
  122. data/spec/samples/all_but_one_masked/masked.reek +5 -1
  123. data/spec/samples/clean_due_to_masking/clean_one.rb +1 -0
  124. data/spec/samples/clean_due_to_masking/clean_three.rb +1 -0
  125. data/spec/samples/clean_due_to_masking/clean_two.rb +1 -0
  126. data/spec/samples/clean_due_to_masking/dirty_one.rb +1 -1
  127. data/spec/samples/clean_due_to_masking/dirty_two.rb +1 -1
  128. data/spec/samples/clean_due_to_masking/masked.reek +5 -1
  129. data/spec/samples/config/allow_duplication.reek +3 -0
  130. data/spec/samples/config/deeper_nested_iterators.reek +3 -0
  131. data/spec/samples/corrupt_config_file/dirty.rb +1 -1
  132. data/spec/samples/demo/demo.rb +8 -0
  133. data/spec/samples/empty_config_file/dirty.rb +2 -1
  134. data/spec/samples/exceptions.reek +1 -1
  135. data/spec/samples/inline_config/dirty.rb +16 -0
  136. data/spec/samples/inline_config/masked.reek +7 -0
  137. data/spec/samples/mask_some/dirty.rb +8 -0
  138. data/spec/samples/mask_some/some.reek +8 -0
  139. data/spec/samples/masked/dirty.rb +2 -1
  140. data/spec/samples/masked/masked.reek +3 -1
  141. data/spec/samples/mixed_results/clean_one.rb +1 -0
  142. data/spec/samples/mixed_results/clean_three.rb +1 -0
  143. data/spec/samples/mixed_results/clean_two.rb +1 -0
  144. data/spec/samples/mixed_results/dirty_one.rb +1 -0
  145. data/spec/samples/mixed_results/dirty_two.rb +1 -0
  146. data/spec/samples/not_quite_masked/dirty.rb +2 -1
  147. data/spec/samples/not_quite_masked/masked.reek +1 -1
  148. data/spec/samples/overrides/masked/dirty.rb +2 -1
  149. data/spec/samples/overrides/masked/lower.reek +3 -1
  150. data/spec/samples/three_clean_files/clean_one.rb +1 -0
  151. data/spec/samples/three_clean_files/clean_three.rb +1 -0
  152. data/spec/samples/three_clean_files/clean_two.rb +1 -0
  153. data/spec/samples/two_smelly_files/dirty_one.rb +2 -1
  154. data/spec/samples/two_smelly_files/dirty_two.rb +2 -1
  155. data/spec/spec_helper.rb +10 -2
  156. data/tasks/reek.rake +2 -2
  157. data/tasks/test.rake +12 -3
  158. metadata +121 -79
  159. data/README.rdoc +0 -84
  160. data/features/profile.feature +0 -34
  161. data/lib/reek/adapters/application.rb +0 -46
  162. data/lib/reek/adapters/command_line.rb +0 -77
  163. data/lib/reek/adapters/config_file.rb +0 -31
  164. data/lib/reek/adapters/core_extras.rb +0 -64
  165. data/lib/reek/adapters/rake_task.rb +0 -121
  166. data/lib/reek/adapters/report.rb +0 -86
  167. data/lib/reek/adapters/source.rb +0 -72
  168. data/lib/reek/adapters/spec.rb +0 -133
  169. data/lib/reek/block_context.rb +0 -62
  170. data/lib/reek/class_context.rb +0 -41
  171. data/lib/reek/code_context.rb +0 -68
  172. data/lib/reek/code_parser.rb +0 -203
  173. data/lib/reek/configuration.rb +0 -57
  174. data/lib/reek/detector_stack.rb +0 -37
  175. data/lib/reek/help_command.rb +0 -14
  176. data/lib/reek/if_context.rb +0 -18
  177. data/lib/reek/masking_collection.rb +0 -33
  178. data/lib/reek/method_context.rb +0 -138
  179. data/lib/reek/module_context.rb +0 -49
  180. data/lib/reek/name.rb +0 -57
  181. data/lib/reek/object_refs.rb +0 -49
  182. data/lib/reek/reek_command.rb +0 -28
  183. data/lib/reek/sexp_formatter.rb +0 -10
  184. data/lib/reek/singleton_method_context.rb +0 -26
  185. data/lib/reek/smells/uncommunicative_name.rb +0 -84
  186. data/lib/reek/sniffer.rb +0 -177
  187. data/lib/reek/stop_context.rb +0 -35
  188. data/lib/reek/tree_dresser.rb +0 -82
  189. data/lib/reek/version_command.rb +0 -14
  190. data/lib/reek/yield_call_context.rb +0 -12
  191. data/spec/reek/adapters/report_spec.rb +0 -31
  192. data/spec/reek/adapters/should_reek_of_spec.rb +0 -138
  193. data/spec/reek/adapters/should_reek_only_of_spec.rb +0 -87
  194. data/spec/reek/block_context_spec.rb +0 -65
  195. data/spec/reek/class_context_spec.rb +0 -161
  196. data/spec/reek/code_context_spec.rb +0 -182
  197. data/spec/reek/configuration_spec.rb +0 -12
  198. data/spec/reek/if_context_spec.rb +0 -17
  199. data/spec/reek/masking_collection_spec.rb +0 -236
  200. data/spec/reek/module_context_spec.rb +0 -46
  201. data/spec/reek/name_spec.rb +0 -37
  202. data/spec/reek/object_source_spec.rb +0 -23
  203. data/spec/reek/reek_command_spec.rb +0 -45
  204. data/spec/reek/singleton_method_context_spec.rb +0 -16
  205. data/spec/reek/smells/smell_detector_spec.rb +0 -36
  206. data/spec/reek/smells/uncommunicative_name_spec.rb +0 -146
  207. data/spec/reek/sniffer_spec.rb +0 -11
  208. data/spec/reek/stop_context_spec.rb +0 -33
  209. data/spec/reek/tree_dresser_spec.rb +0 -20
@@ -1,182 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
-
3
- require 'reek/block_context'
4
- require 'reek/if_context'
5
- require 'reek/class_context'
6
- require 'reek/module_context'
7
- require 'reek/method_context'
8
- require 'reek/stop_context'
9
-
10
- include Reek
11
-
12
- describe CodeContext do
13
- context 'full_name' do
14
- it "reports the full context" do
15
- element = StopContext.new
16
- element = ModuleContext.new(element, Name.new(:mod), s(:module, :mod, nil))
17
- element = ClassContext.new(element, [0, :klass], s())
18
- element = MethodContext.new(element, [0, :bad])
19
- element = BlockContext.new(element, s(nil, nil))
20
- element.full_name.should match(/bad/)
21
- element.full_name.should match(/klass/)
22
- element.full_name.should match(/mod/)
23
- end
24
-
25
- it 'reports the method name via if context' do
26
- element1 = StopContext.new
27
- element2 = MethodContext.new(element1, [0, :bad])
28
- element3 = IfContext.new(element2, [0,1])
29
- BlockContext.new(element3, s(nil, nil)).full_name.should match(/bad/)
30
- end
31
-
32
- it 'reports the method name via nested blocks' do
33
- element1 = StopContext.new
34
- element2 = MethodContext.new(element1, [0, :bad])
35
- element3 = BlockContext.new(element2, s(nil, nil))
36
- BlockContext.new(element3, s(nil, nil)).full_name.should match(/bad/)
37
- end
38
- it 'includes the enclosing context name' do
39
- outer_name = 'randomstring'
40
- outer = mock('outer')
41
- outer.should_receive(:full_name).and_return(outer_name)
42
- ifc = IfContext.new(outer, s(:if, s()))
43
- ifc.full_name.should == outer_name
44
- end
45
- end
46
-
47
- context 'instance variables' do
48
- it 'should pass instance variables down to the first class' do
49
- element = StopContext.new
50
- element = ModuleContext.new(element, Name.new(:mod), s(:module, :mod, nil))
51
- class_element = ClassContext.new(element, [0, :klass], s())
52
- element = MethodContext.new(class_element, [0, :bad])
53
- element = BlockContext.new(element, s(nil, nil))
54
- element.record_instance_variable(:fred)
55
- class_element.variable_names.size.should == 1
56
- class_element.variable_names.should include(Name.new(:fred))
57
- end
58
- end
59
-
60
- context 'generics' do
61
- it 'should pass unknown method calls down the stack' do
62
- stop = StopContext.new
63
- def stop.bananas(arg1, arg2) arg1 + arg2 + 43 end
64
- element = ModuleContext.new(stop, Name.new(:mod), s(:module, :mod, nil))
65
- class_element = ClassContext.new(element, [0, :klass], s())
66
- element = MethodContext.new(class_element, [0, :bad])
67
- element = BlockContext.new(element, s(nil, nil))
68
- element.bananas(17, -5).should == 55
69
- end
70
- end
71
-
72
- context 'name matching' do
73
- it 'should recognise itself in a collection of names' do
74
- element = StopContext.new
75
- element = ModuleContext.new(element, Name.new(:mod), s(:module, :mod, nil))
76
- element.matches?(['banana', 'mod']).should == true
77
- end
78
-
79
- it 'should recognise itself in a collection of REs' do
80
- element = StopContext.new
81
- element = ModuleContext.new(element, Name.new(:mod), s(:module, :mod, nil))
82
- element.matches?([/banana/, /mod/]).should == true
83
- end
84
-
85
- it 'should recognise its fq name in a collection of names' do
86
- element = StopContext.new
87
- element = ModuleContext.new(element, Name.new(:mod), s(:module, :mod, nil))
88
- element = ClassContext.create(element, s(:class, :klass))
89
- element.matches?(['banana', 'mod']).should == true
90
- element.matches?(['banana', 'mod::klass']).should == true
91
- end
92
-
93
- it 'should recognise its fq name in a collection of names' do
94
- element = StopContext.new
95
- element = ModuleContext.new(element, Name.new(:mod), s(:module, :mod, nil))
96
- element = ClassContext.create(element, s(:class, :klass))
97
- element.matches?([/banana/, /mod/]).should == true
98
- element.matches?([/banana/, /mod::klass/]).should == true
99
- end
100
- end
101
-
102
- context 'enumerating syntax elements' do
103
- context 'in an empty module' do
104
- before :each do
105
- @module_name = 'Emptiness'
106
- src = "module #{@module_name}; end"
107
- ast = src.to_reek_source.syntax_tree
108
- @ctx = CodeContext.new(nil, ast)
109
- end
110
- it 'yields no calls' do
111
- @ctx.each_node(:call, []) {|exp| raise "#{exp} yielded by empty module!"}
112
- end
113
- it 'yields one module' do
114
- mods = 0
115
- @ctx.each_node(:module, []) {|exp| mods += 1}
116
- mods.should == 1
117
- end
118
- it "yields the module's full AST" do
119
- @ctx.each_node(:module, []) {|exp| exp[1].should == @module_name.to_sym}
120
- end
121
-
122
- context 'with no block' do
123
- it 'returns an empty array of ifs' do
124
- @ctx.each_node(:if, []).should be_empty
125
- end
126
- end
127
- end
128
-
129
- context 'with a nested element' do
130
- before :each do
131
- @module_name = 'Loneliness'
132
- @method_name = 'calloo'
133
- src = "module #{@module_name}; def #{@method_name}; puts('hello') end; end"
134
- ast = src.to_reek_source.syntax_tree
135
- @ctx = CodeContext.new(nil, ast)
136
- end
137
- it 'yields no ifs' do
138
- @ctx.each_node(:if, []) {|exp| raise "#{exp} yielded by empty module!"}
139
- end
140
- it 'yields one module' do
141
- @ctx.each_node(:module, []).length.should == 1
142
- end
143
- it "yields the module's full AST" do
144
- @ctx.each_node(:module, []) {|exp| exp[1].should == @module_name.to_sym}
145
- end
146
- it 'yields one method' do
147
- @ctx.each_node(:defn, []).length.should == 1
148
- end
149
- it "yields the method's full AST" do
150
- @ctx.each_node(:defn, []) {|exp| exp[1].should == @method_name.to_sym}
151
- end
152
-
153
- context 'pruning the traversal' do
154
- it 'ignores the call inside the method' do
155
- @ctx.each_node(:call, [:defn]).should be_empty
156
- end
157
- end
158
- end
159
-
160
- it 'finds 3 ifs in a class' do
161
- src = <<EOS
162
- class Scrunch
163
- def first
164
- return @field == :sym ? 0 : 3;
165
- end
166
- def second
167
- if @field == :sym
168
- @other += " quarts"
169
- end
170
- end
171
- def third
172
- raise 'flu!' unless @field == :sym
173
- end
174
- end
175
- EOS
176
-
177
- ast = src.to_reek_source.syntax_tree
178
- ctx = CodeContext.new(nil, ast)
179
- ctx.each_node(:if, []).length.should == 3
180
- end
181
- end
182
- end
@@ -1,12 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
-
3
- require 'reek/configuration'
4
-
5
- include Reek
6
-
7
- describe SmellConfiguration do
8
- it 'returns the default value when key not found' do
9
- cf = SmellConfiguration.new({})
10
- cf.value('fred', nil, 27).should == 27
11
- end
12
- end
@@ -1,17 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
-
3
- require 'reek/if_context'
4
-
5
- include Reek
6
-
7
- describe IfContext do
8
- it 'finds a class within top-level code' do
9
- 'unless jim; class Array; end; end'.should_not reek
10
- end
11
-
12
- it 'finds class within top-level code' do
13
- stopctx = StopContext.new
14
- ifctx = IfContext.new(stopctx, [:if, [:vcall, :jim]])
15
- ifctx.find_module(Name.new(:Array)).should_not be_nil
16
- end
17
- end
@@ -1,236 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
-
3
- require 'reek/masking_collection'
4
-
5
- include Reek
6
-
7
- describe MaskingCollection do
8
- before(:each) do
9
- @collection = MaskingCollection.new
10
- end
11
-
12
- context 'when empty' do
13
- it 'has no visible items' do
14
- @collection.num_visible_items.should == 0
15
- end
16
- it 'has no masked items' do
17
- @collection.num_masked_items.should == 0
18
- end
19
- it 'yields no items' do
20
- count = 0
21
- @collection.each_item {|item| count+= 1}
22
- count.should == 0
23
- end
24
- it 'yields no visible items' do
25
- count = 0
26
- @collection.each_visible_item {|item| count+= 1}
27
- count.should == 0
28
- end
29
- end
30
-
31
- shared_examples_for 'one visible item' do
32
- it 'has one visible item' do
33
- @collection.num_visible_items.should == 1
34
- end
35
- it 'has no masked items' do
36
- @collection.num_masked_items.should == 0
37
- end
38
- it 'yields one item' do
39
- count = 0
40
- @collection.each_item do |item|
41
- item.should == @item
42
- count+= 1
43
- end
44
- count.should == 1
45
- end
46
- it 'yields one visible item' do
47
- count = 0
48
- @collection.each_visible_item do |item|
49
- item.should == @item
50
- count+= 1
51
- end
52
- count.should == 1
53
- end
54
- end
55
-
56
- shared_examples_for 'one masked item' do
57
- it 'has no visible items' do
58
- @collection.num_visible_items.should == 0
59
- end
60
- it 'has one masked item' do
61
- @collection.num_masked_items.should == 1
62
- end
63
- it 'yields one item' do
64
- count = 0
65
- @collection.each_item do |item|
66
- item.should == @item
67
- count+= 1
68
- end
69
- count.should == 1
70
- end
71
- it 'yields no visible items' do
72
- count = 0
73
- @collection.each_visible_item { |item| count+= 1 }
74
- count.should == 0
75
- end
76
- end
77
-
78
- context 'with one visible item' do
79
- before :each do
80
- @item = "hello"
81
- @collection.found_smell(@item)
82
- end
83
- it_should_behave_like 'one visible item'
84
- end
85
-
86
- context 'with one masked item' do
87
- before :each do
88
- @item = "hiding!"
89
- @collection.found_masked_smell(@item)
90
- end
91
- it_should_behave_like 'one masked item'
92
- end
93
-
94
- context 'with one masked and one visible' do
95
- before :each do
96
- @visible = "visible"
97
- @masked = "masked"
98
- @collection.found_masked_smell(@masked)
99
- @collection.found_smell(@visible)
100
- end
101
- it 'has one visible item' do
102
- @collection.num_visible_items.should == 1
103
- end
104
- it 'has one masked item' do
105
- @collection.num_masked_items.should == 1
106
- end
107
- it 'yields both items' do
108
- yielded_items = []
109
- @collection.each_item { |item| yielded_items << item }
110
- yielded_items.length.should == 2
111
- yielded_items.should include(@visible)
112
- yielded_items.should include(@masked)
113
- end
114
- it 'yields one visible item' do
115
- count = 0
116
- @collection.each_visible_item do |item|
117
- item.should == @visible
118
- count+= 1
119
- end
120
- count.should == 1
121
- end
122
- it 'yields the items in sort order' do
123
- yielded_items = []
124
- @collection.each_item { |item| yielded_items << item }
125
- yielded_items.length.should == 2
126
- yielded_items[0].should == @masked
127
- yielded_items[1].should == @visible
128
- end
129
- end
130
-
131
- context 'with one visible item added twice' do
132
- before :each do
133
- @item = "hello"
134
- @collection.found_smell(@item)
135
- @collection.found_smell(@item)
136
- end
137
- it_should_behave_like 'one visible item'
138
- end
139
-
140
- context 'with one masked item added twice' do
141
- before :each do
142
- @item = "hello"
143
- @collection.found_masked_smell(@item)
144
- @collection.found_masked_smell(@item)
145
- end
146
- it_should_behave_like 'one masked item'
147
- end
148
-
149
- context 'with two different visible items' do
150
- before :each do
151
- @first_item = "hello"
152
- @second_item = "goodbye"
153
- @collection.found_smell(@first_item)
154
- @collection.found_smell(@second_item)
155
- end
156
- it 'has 2 visible items' do
157
- @collection.num_visible_items.should == 2
158
- end
159
- it 'has no masked items' do
160
- @collection.num_masked_items.should == 0
161
- end
162
- it 'yields both items' do
163
- yielded_items = []
164
- @collection.each_item { |item| yielded_items << item }
165
- yielded_items.length.should == 2
166
- yielded_items.should include(@first_item)
167
- yielded_items.should include(@second_item)
168
- end
169
- it 'yields both visible items' do
170
- yielded_items = []
171
- @collection.each_visible_item { |item| yielded_items << item }
172
- yielded_items.length.should == 2
173
- yielded_items.should include(@first_item)
174
- yielded_items.should include(@second_item)
175
- end
176
- it 'yields the items in sort order' do
177
- yielded_items = []
178
- @collection.each_visible_item { |item| yielded_items << item }
179
- yielded_items.length.should == 2
180
- yielded_items[0].should == @second_item
181
- yielded_items[1].should == @first_item
182
- end
183
- end
184
-
185
- context 'with two different masked items' do
186
- before :each do
187
- @first_item = "hello"
188
- @second_item = "goodbye"
189
- @collection.found_masked_smell(@first_item)
190
- @collection.found_masked_smell(@second_item)
191
- end
192
- it 'has 0 visible items' do
193
- @collection.num_visible_items.should == 0
194
- end
195
- it 'has 2 masked items' do
196
- @collection.num_masked_items.should == 2
197
- end
198
- it 'yields both items' do
199
- yielded_items = []
200
- @collection.each_item { |item| yielded_items << item }
201
- yielded_items.length.should == 2
202
- yielded_items.should include(@first_item)
203
- yielded_items.should include(@second_item)
204
- end
205
- it 'yields no visible items' do
206
- count = 0
207
- @collection.each_visible_item { |item| count+= 1 }
208
- count.should == 0
209
- end
210
- it 'yields the items in sort order' do
211
- yielded_items = []
212
- @collection.each_item { |item| yielded_items << item }
213
- yielded_items.length.should == 2
214
- yielded_items[0].should == @second_item
215
- yielded_items[1].should == @first_item
216
- end
217
- end
218
-
219
- context 'with one masked item later made visible' do
220
- before :each do
221
- @item = "hello"
222
- @collection.found_masked_smell(@item)
223
- @collection.found_smell(@item)
224
- end
225
- it_should_behave_like 'one visible item'
226
- end
227
-
228
- context 'with one visible item later masked' do
229
- before :each do
230
- @item = "hello"
231
- @collection.found_smell(@item)
232
- @collection.found_masked_smell(@item)
233
- end
234
- it_should_behave_like 'one visible item'
235
- end
236
- end
@@ -1,46 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
- require 'reek/module_context'
3
- require 'reek/stop_context'
4
-
5
- include Reek
6
-
7
- describe ModuleContext do
8
- it 'should report module name for smell in method' do
9
- 'module Fred; def simple(x) true; end; end'.should reek_of(:UncommunicativeName, /x/, /simple/, /Fred/)
10
- end
11
-
12
- it 'should not report module with empty class' do
13
- 'module Fred; class Jim; end; end'.should_not reek
14
- end
15
-
16
- it 'should handle module with empty class' do
17
- stop = StopContext.new
18
- modctx = ModuleContext.create(stop, [:module, :Fred, []])
19
- modctx.find_module(Name.new(:Jim)).should be_nil
20
- end
21
- end
22
-
23
- describe ModuleContext do
24
- it 'should recognise global constant' do
25
- 'module ::Global class Inside; end; end'.should_not reek
26
- end
27
-
28
- it 'should not find missing global constant' do
29
- element = ModuleContext.create(StopContext.new, [:module, [:colon3, :Global], nil])
30
- element.myself.should be_nil
31
- end
32
-
33
- it 'should find global constant' do
34
- module ::GlobalTestModule; end
35
- element = ModuleContext.create(StopContext.new, [:module, [:colon3, :GlobalTestModule], nil])
36
- element.myself.name.should == 'GlobalTestModule'
37
- end
38
-
39
- context 'full_name' do
40
- it "reports full context" do
41
- element = StopContext.new
42
- element = ModuleContext.new(element, Name.new(:mod), s(:module, :mod, nil))
43
- element.full_name.should == 'mod'
44
- end
45
- end
46
- end
@@ -1,37 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
- require 'reek/name'
3
-
4
- include Reek
5
-
6
- describe Name, 'resolving symbols' do
7
- it 'finds fq loaded class' do
8
- exp = [:class, :"Reek::Smells::LargeClass", nil]
9
- ctx = StopContext.new
10
- res = Name.resolve(exp[1], ctx)
11
- res[1].should == "LargeClass"
12
- end
13
- end
14
-
15
- describe Name do
16
- it 'compares correctly' do
17
- a1 = [Name.new('conts'), Name.new('p1'), Name.new('p2'), Name.new('p3')]
18
- a2 = [Name.new('name'), Name.new('windowH'), Name.new('windowW')]
19
- (a1 & a2).should == []
20
- end
21
-
22
- it do
23
- [Name.new(:fred)].should include(Name.new(:fred))
24
- end
25
-
26
- it do
27
- set = Set.new
28
- set << Name.new(:fred)
29
- set.should include(Name.new(:fred))
30
- end
31
-
32
- it do
33
- fred = Name.new(:fred)
34
- fred.should eql(fred)
35
- fred.should eql(Name.new(:fred))
36
- end
37
- end
@@ -1,23 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
-
3
- include Reek
4
-
5
- describe Dir do
6
- it 'reports correct smells via the Dir matcher' do
7
- Dir['spec/samples/two_smelly_files/*.rb'].should reek
8
- Dir['spec/samples/two_smelly_files/*.rb'].should reek_of(:UncommunicativeName)
9
- end
10
-
11
- it 'reports correct smells via Dir' do
12
- sniffer = Dir['spec/samples/two_smelly_files/*.rb'].sniff
13
- sniffer.has_smell?(:UncommunicativeName).should be_true
14
- end
15
-
16
- it 'copes with daft file specs' do
17
- Dir["spec/samples/two_smelly_files/*/.rb"].should_not reek
18
- end
19
-
20
- it 'copes with empty array' do
21
- [].should_not reek
22
- end
23
- end
@@ -1,45 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
-
3
- require 'reek/reek_command'
4
-
5
- include Reek
6
-
7
- describe ReekCommand do
8
- before :each do
9
- @view = mock('view', :null_object => true)
10
- end
11
-
12
- context 'with smells' do
13
- before :each do
14
- src = 'def x(); end'
15
- @cmd = ReekCommand.new(src, QuietReport, false)
16
- end
17
-
18
- it 'displays the correct text on the view' do
19
- @view.should_receive(:output).with(/Uncommunicative Name/)
20
- @cmd.execute(@view)
21
- end
22
-
23
- it 'tells the view it succeeded' do
24
- @view.should_receive(:report_smells)
25
- @cmd.execute(@view)
26
- end
27
- end
28
-
29
- context 'with no smells' do
30
- before :each do
31
- src = 'def clean(); end'
32
- @cmd = ReekCommand.new(src, QuietReport, false)
33
- end
34
-
35
- it 'displays nothing on the view' do
36
- @view.should_receive(:output).with('')
37
- @cmd.execute(@view)
38
- end
39
-
40
- it 'tells the view it succeeded' do
41
- @view.should_receive(:report_success)
42
- @cmd.execute(@view)
43
- end
44
- end
45
- end
@@ -1,16 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
-
3
- require 'reek/module_context'
4
- require 'reek/singleton_method_context'
5
- require 'reek/stop_context'
6
-
7
- include Reek
8
-
9
- describe SingletonMethodContext do
10
- it "reports full context" do
11
- element = StopContext.new
12
- element = ModuleContext.new(element, Name.new(:mod), s(:module, :mod, nil))
13
- element = SingletonMethodContext.new(element, s(:defs, s(:call, nil, :a, s(:arglist)), :b, s(:args)))
14
- element.full_name.should match(/mod#a\.b/)
15
- end
16
- end
@@ -1,36 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- require 'reek/configuration'
4
- require 'reek/smells/duplication'
5
- require 'reek/smells/large_class'
6
- require 'reek/smells/long_method'
7
-
8
- include Reek
9
- include Reek::Smells
10
-
11
- describe SmellDetector, 'configuration' do
12
- before:each do
13
- @detector = LongMethod.new
14
- end
15
-
16
- it 'adopts new max_statements value' do
17
- @detector.configure_with(LongMethod::MAX_ALLOWED_STATEMENTS_KEY => 25)
18
- @detector.value(LongMethod::MAX_ALLOWED_STATEMENTS_KEY, nil, 0).should == 25
19
- end
20
- end
21
-
22
- describe SmellDetector, 'configuration' do
23
- # it 'stays enabled when not disabled' do
24
- # @detector = LargeClass.new
25
- # @detector.should be_enabled
26
- # @detector.configure({'LargeClass' => {'max_methods' => 50}})
27
- # @detector.should be_enabled
28
- # end
29
-
30
- it 'becomes disabled when disabled' do
31
- @detector = LargeClass.new
32
- @detector.should be_enabled
33
- @detector.configure({'LargeClass' => {SmellConfiguration::ENABLED_KEY => false}})
34
- @detector.should_not be_enabled
35
- end
36
- end