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.
- data/.yardopts +10 -0
- data/History.txt +62 -0
- data/README.md +74 -0
- data/bin/reek +2 -2
- data/config/defaults.reek +44 -5
- data/features/api.feature +20 -0
- data/features/masking_smells.feature +60 -42
- data/features/options.feature +7 -2
- data/features/rake_task.feature +29 -22
- data/features/reports.feature +9 -41
- data/features/samples.feature +184 -196
- data/features/stdin.feature +5 -8
- data/features/step_definitions/reek_steps.rb +8 -4
- data/features/support/env.rb +2 -3
- data/features/yaml.feature +85 -0
- data/lib/reek/cli/application.rb +46 -0
- data/lib/reek/cli/command_line.rb +108 -0
- data/lib/reek/cli/help_command.rb +18 -0
- data/lib/reek/cli/reek_command.rb +37 -0
- data/lib/reek/cli/report.rb +58 -0
- data/lib/reek/cli/version_command.rb +19 -0
- data/lib/reek/cli/yaml_command.rb +32 -0
- data/lib/reek/core/code_context.rb +64 -0
- data/lib/reek/core/code_parser.rb +166 -0
- data/lib/reek/core/method_context.rb +84 -0
- data/lib/reek/core/module_context.rb +20 -0
- data/lib/reek/core/object_refs.rb +51 -0
- data/lib/reek/core/singleton_method_context.rb +20 -0
- data/lib/reek/core/smell_configuration.rb +62 -0
- data/lib/reek/core/sniffer.rb +105 -0
- data/lib/reek/core/stop_context.rb +30 -0
- data/lib/reek/core/warning_collector.rb +27 -0
- data/lib/reek/examiner.rb +104 -0
- data/lib/reek/rake/task.rb +142 -0
- data/lib/reek/smell_warning.rb +73 -23
- data/lib/reek/smells/attribute.rb +26 -21
- data/lib/reek/smells/boolean_parameter.rb +38 -0
- data/lib/reek/smells/class_variable.rb +22 -9
- data/lib/reek/smells/control_couple.rb +40 -16
- data/lib/reek/smells/data_clump.rb +114 -23
- data/lib/reek/smells/duplication.rb +55 -15
- data/lib/reek/smells/feature_envy.rb +16 -7
- data/lib/reek/smells/irresponsible_module.rb +37 -0
- data/lib/reek/smells/large_class.rb +37 -19
- data/lib/reek/smells/long_method.rb +20 -9
- data/lib/reek/smells/long_parameter_list.rb +22 -10
- data/lib/reek/smells/long_yield_list.rb +43 -7
- data/lib/reek/smells/nested_iterators.rb +68 -8
- data/lib/reek/smells/simulated_polymorphism.rb +26 -15
- data/lib/reek/smells/smell_detector.rb +29 -51
- data/lib/reek/smells/uncommunicative_method_name.rb +74 -0
- data/lib/reek/smells/uncommunicative_module_name.rb +74 -0
- data/lib/reek/smells/uncommunicative_parameter_name.rb +79 -0
- data/lib/reek/smells/uncommunicative_variable_name.rb +89 -0
- data/lib/reek/smells/utility_function.rb +51 -12
- data/lib/reek/smells.rb +29 -0
- data/lib/reek/source/code_comment.rb +37 -0
- data/lib/reek/source/config_file.rb +72 -0
- data/lib/reek/source/core_extras.rb +46 -0
- data/lib/reek/source/reference_collector.rb +28 -0
- data/lib/reek/source/sexp_formatter.rb +17 -0
- data/lib/reek/source/source_code.rb +44 -0
- data/lib/reek/source/source_file.rb +32 -0
- data/lib/reek/source/source_locator.rb +42 -0
- data/lib/reek/source/tree_dresser.rb +204 -0
- data/lib/reek/source.rb +18 -0
- data/lib/reek/spec/should_reek.rb +31 -0
- data/lib/reek/spec/should_reek_of.rb +37 -0
- data/lib/reek/spec/should_reek_only_of.rb +37 -0
- data/lib/reek/spec.rb +51 -0
- data/lib/reek.rb +8 -4
- data/reek.gemspec +9 -7
- data/spec/matchers/smell_of_matcher.rb +58 -0
- data/spec/reek/{help_command_spec.rb → cli/help_command_spec.rb} +3 -4
- data/spec/reek/cli/reek_command_spec.rb +46 -0
- data/spec/reek/cli/report_spec.rb +30 -0
- data/spec/reek/{version_command_spec.rb → cli/version_command_spec.rb} +3 -3
- data/spec/reek/cli/yaml_command_spec.rb +47 -0
- data/spec/reek/core/code_context_spec.rb +145 -0
- data/spec/reek/{code_parser_spec.rb → core/code_parser_spec.rb} +7 -6
- data/spec/reek/{config_spec.rb → core/config_spec.rb} +2 -6
- data/spec/reek/{method_context_spec.rb → core/method_context_spec.rb} +16 -36
- data/spec/reek/core/module_context_spec.rb +27 -0
- data/spec/reek/{object_refs_spec.rb → core/object_refs_spec.rb} +5 -6
- data/spec/reek/core/singleton_method_context_spec.rb +9 -0
- data/spec/reek/core/smell_configuration_spec.rb +11 -0
- data/spec/reek/core/stop_context_spec.rb +17 -0
- data/spec/reek/core/warning_collector_spec.rb +27 -0
- data/spec/reek/examiner_spec.rb +103 -0
- data/spec/reek/smell_warning_spec.rb +74 -82
- data/spec/reek/smells/attribute_spec.rb +42 -23
- data/spec/reek/smells/behaves_like_variable_detector.rb +2 -2
- data/spec/reek/smells/boolean_parameter_spec.rb +66 -0
- data/spec/reek/smells/class_variable_spec.rb +60 -75
- data/spec/reek/smells/control_couple_spec.rb +37 -32
- data/spec/reek/smells/data_clump_spec.rb +63 -24
- data/spec/reek/smells/duplication_spec.rb +106 -57
- data/spec/reek/smells/feature_envy_spec.rb +113 -92
- data/spec/reek/smells/irresponsible_module_spec.rb +58 -0
- data/spec/reek/smells/large_class_spec.rb +67 -57
- data/spec/reek/smells/long_method_spec.rb +40 -10
- data/spec/reek/smells/long_parameter_list_spec.rb +50 -28
- data/spec/reek/smells/long_yield_list_spec.rb +57 -0
- data/spec/reek/smells/nested_iterators_spec.rb +115 -7
- data/spec/reek/smells/simulated_polymorphism_spec.rb +56 -20
- data/spec/reek/smells/smell_detector_shared.rb +42 -0
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +42 -0
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +66 -0
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +71 -0
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +120 -0
- data/spec/reek/smells/utility_function_spec.rb +50 -4
- data/spec/reek/source/code_comment_spec.rb +82 -0
- data/spec/reek/source/object_source_spec.rb +20 -0
- data/spec/reek/source/reference_collector_spec.rb +53 -0
- data/spec/reek/{adapters/source_spec.rb → source/source_code_spec.rb} +7 -8
- data/spec/reek/source/tree_dresser_spec.rb +270 -0
- data/spec/reek/spec/should_reek_of_spec.rb +76 -0
- data/spec/reek/spec/should_reek_only_of_spec.rb +89 -0
- data/spec/reek/{adapters → spec}/should_reek_spec.rb +8 -32
- data/spec/samples/all_but_one_masked/clean_one.rb +1 -0
- data/spec/samples/all_but_one_masked/dirty.rb +1 -0
- data/spec/samples/all_but_one_masked/masked.reek +5 -1
- data/spec/samples/clean_due_to_masking/clean_one.rb +1 -0
- data/spec/samples/clean_due_to_masking/clean_three.rb +1 -0
- data/spec/samples/clean_due_to_masking/clean_two.rb +1 -0
- data/spec/samples/clean_due_to_masking/dirty_one.rb +1 -1
- data/spec/samples/clean_due_to_masking/dirty_two.rb +1 -1
- data/spec/samples/clean_due_to_masking/masked.reek +5 -1
- data/spec/samples/config/allow_duplication.reek +3 -0
- data/spec/samples/config/deeper_nested_iterators.reek +3 -0
- data/spec/samples/corrupt_config_file/dirty.rb +1 -1
- data/spec/samples/demo/demo.rb +8 -0
- data/spec/samples/empty_config_file/dirty.rb +2 -1
- data/spec/samples/exceptions.reek +1 -1
- data/spec/samples/inline_config/dirty.rb +16 -0
- data/spec/samples/inline_config/masked.reek +7 -0
- data/spec/samples/mask_some/dirty.rb +8 -0
- data/spec/samples/mask_some/some.reek +8 -0
- data/spec/samples/masked/dirty.rb +2 -1
- data/spec/samples/masked/masked.reek +3 -1
- data/spec/samples/mixed_results/clean_one.rb +1 -0
- data/spec/samples/mixed_results/clean_three.rb +1 -0
- data/spec/samples/mixed_results/clean_two.rb +1 -0
- data/spec/samples/mixed_results/dirty_one.rb +1 -0
- data/spec/samples/mixed_results/dirty_two.rb +1 -0
- data/spec/samples/not_quite_masked/dirty.rb +2 -1
- data/spec/samples/not_quite_masked/masked.reek +1 -1
- data/spec/samples/overrides/masked/dirty.rb +2 -1
- data/spec/samples/overrides/masked/lower.reek +3 -1
- data/spec/samples/three_clean_files/clean_one.rb +1 -0
- data/spec/samples/three_clean_files/clean_three.rb +1 -0
- data/spec/samples/three_clean_files/clean_two.rb +1 -0
- data/spec/samples/two_smelly_files/dirty_one.rb +2 -1
- data/spec/samples/two_smelly_files/dirty_two.rb +2 -1
- data/spec/spec_helper.rb +10 -2
- data/tasks/reek.rake +2 -2
- data/tasks/test.rake +12 -3
- metadata +121 -79
- data/README.rdoc +0 -84
- data/features/profile.feature +0 -34
- data/lib/reek/adapters/application.rb +0 -46
- data/lib/reek/adapters/command_line.rb +0 -77
- data/lib/reek/adapters/config_file.rb +0 -31
- data/lib/reek/adapters/core_extras.rb +0 -64
- data/lib/reek/adapters/rake_task.rb +0 -121
- data/lib/reek/adapters/report.rb +0 -86
- data/lib/reek/adapters/source.rb +0 -72
- data/lib/reek/adapters/spec.rb +0 -133
- data/lib/reek/block_context.rb +0 -62
- data/lib/reek/class_context.rb +0 -41
- data/lib/reek/code_context.rb +0 -68
- data/lib/reek/code_parser.rb +0 -203
- data/lib/reek/configuration.rb +0 -57
- data/lib/reek/detector_stack.rb +0 -37
- data/lib/reek/help_command.rb +0 -14
- data/lib/reek/if_context.rb +0 -18
- data/lib/reek/masking_collection.rb +0 -33
- data/lib/reek/method_context.rb +0 -138
- data/lib/reek/module_context.rb +0 -49
- data/lib/reek/name.rb +0 -57
- data/lib/reek/object_refs.rb +0 -49
- data/lib/reek/reek_command.rb +0 -28
- data/lib/reek/sexp_formatter.rb +0 -10
- data/lib/reek/singleton_method_context.rb +0 -26
- data/lib/reek/smells/uncommunicative_name.rb +0 -84
- data/lib/reek/sniffer.rb +0 -177
- data/lib/reek/stop_context.rb +0 -35
- data/lib/reek/tree_dresser.rb +0 -82
- data/lib/reek/version_command.rb +0 -14
- data/lib/reek/yield_call_context.rb +0 -12
- data/spec/reek/adapters/report_spec.rb +0 -31
- data/spec/reek/adapters/should_reek_of_spec.rb +0 -138
- data/spec/reek/adapters/should_reek_only_of_spec.rb +0 -87
- data/spec/reek/block_context_spec.rb +0 -65
- data/spec/reek/class_context_spec.rb +0 -161
- data/spec/reek/code_context_spec.rb +0 -182
- data/spec/reek/configuration_spec.rb +0 -12
- data/spec/reek/if_context_spec.rb +0 -17
- data/spec/reek/masking_collection_spec.rb +0 -236
- data/spec/reek/module_context_spec.rb +0 -46
- data/spec/reek/name_spec.rb +0 -37
- data/spec/reek/object_source_spec.rb +0 -23
- data/spec/reek/reek_command_spec.rb +0 -45
- data/spec/reek/singleton_method_context_spec.rb +0 -16
- data/spec/reek/smells/smell_detector_spec.rb +0 -36
- data/spec/reek/smells/uncommunicative_name_spec.rb +0 -146
- data/spec/reek/sniffer_spec.rb +0 -11
- data/spec/reek/stop_context_spec.rb +0 -33
- 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
|
data/spec/reek/name_spec.rb
DELETED
|
@@ -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
|