reek 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -1
- data/features/options.feature +1 -9
- data/features/samples.feature +7 -2
- data/features/step_definitions/reek_steps.rb +3 -3
- data/lib/reek.rb +1 -1
- data/lib/reek/adapters/application.rb +22 -27
- data/lib/reek/adapters/command_line.rb +41 -42
- data/lib/reek/adapters/report.rb +30 -23
- data/lib/reek/adapters/spec.rb +1 -1
- data/lib/reek/code_context.rb +6 -2
- data/lib/reek/code_parser.rb +3 -7
- data/lib/reek/detector_stack.rb +2 -4
- data/lib/reek/help_command.rb +14 -0
- data/lib/reek/masking_collection.rb +33 -0
- data/lib/reek/method_context.rb +18 -6
- data/lib/reek/module_context.rb +0 -13
- data/lib/reek/reek_command.rb +28 -0
- data/lib/reek/singleton_method_context.rb +1 -1
- data/lib/reek/smell_warning.rb +5 -3
- data/lib/reek/smells/attribute.rb +17 -1
- data/lib/reek/smells/class_variable.rb +1 -1
- data/lib/reek/smells/control_couple.rb +13 -10
- data/lib/reek/smells/large_class.rb +1 -1
- data/lib/reek/smells/long_method.rb +0 -2
- data/lib/reek/smells/simulated_polymorphism.rb +2 -2
- data/lib/reek/sniffer.rb +1 -3
- data/lib/reek/tree_dresser.rb +35 -23
- data/lib/reek/version_command.rb +14 -0
- data/reek.gemspec +3 -3
- data/spec/reek/adapters/report_spec.rb +8 -8
- data/spec/reek/adapters/should_reek_of_spec.rb +1 -1
- data/spec/reek/adapters/should_reek_only_of_spec.rb +2 -2
- data/spec/reek/adapters/should_reek_spec.rb +3 -3
- data/spec/reek/code_context_spec.rb +11 -11
- data/spec/reek/code_parser_spec.rb +0 -88
- data/spec/reek/help_command_spec.rb +24 -0
- data/spec/reek/masking_collection_spec.rb +236 -0
- data/spec/reek/method_context_spec.rb +43 -1
- data/spec/reek/reek_command_spec.rb +45 -0
- data/spec/reek/smell_warning_spec.rb +12 -4
- data/spec/reek/smells/attribute_spec.rb +79 -7
- data/spec/reek/smells/control_couple_spec.rb +40 -11
- data/spec/reek/smells/long_parameter_list_spec.rb +1 -1
- data/spec/reek/smells/smell_detector_spec.rb +0 -17
- data/spec/reek/tree_dresser_spec.rb +20 -0
- data/spec/reek/version_command_spec.rb +29 -0
- metadata +11 -2
data/reek.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{reek}
|
5
|
-
s.version = "1.2.
|
5
|
+
s.version = "1.2.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Kevin Rutherford"]
|
9
|
-
s.date = %q{2009-11-
|
9
|
+
s.date = %q{2009-11-17}
|
10
10
|
s.default_executable = %q{reek}
|
11
11
|
s.description = %q{Code smell detector for Ruby}
|
12
12
|
s.email = ["kevin@rutherford-software.com"]
|
13
13
|
s.executables = ["reek"]
|
14
14
|
s.extra_rdoc_files = ["History.txt", "License.txt", "README.rdoc"]
|
15
|
-
s.files = ["History.txt", "License.txt", "README.rdoc", "Rakefile", "bin/reek", "config/defaults.reek", "features/masking_smells.feature", "features/options.feature", "features/profile.feature", "features/rake_task.feature", "features/reports.feature", "features/samples.feature", "features/stdin.feature", "features/step_definitions/reek_steps.rb", "features/support/env.rb", "lib/reek.rb", "lib/reek/adapters/application.rb", "lib/reek/adapters/command_line.rb", "lib/reek/adapters/config_file.rb", "lib/reek/adapters/core_extras.rb", "lib/reek/adapters/rake_task.rb", "lib/reek/adapters/report.rb", "lib/reek/adapters/source.rb", "lib/reek/adapters/spec.rb", "lib/reek/block_context.rb", "lib/reek/class_context.rb", "lib/reek/code_context.rb", "lib/reek/code_parser.rb", "lib/reek/configuration.rb", "lib/reek/detector_stack.rb", "lib/reek/if_context.rb", "lib/reek/method_context.rb", "lib/reek/module_context.rb", "lib/reek/name.rb", "lib/reek/object_refs.rb", "lib/reek/sexp_formatter.rb", "lib/reek/singleton_method_context.rb", "lib/reek/smell_warning.rb", "lib/reek/smells/attribute.rb", "lib/reek/smells/class_variable.rb", "lib/reek/smells/control_couple.rb", "lib/reek/smells/data_clump.rb", "lib/reek/smells/duplication.rb", "lib/reek/smells/feature_envy.rb", "lib/reek/smells/large_class.rb", "lib/reek/smells/long_method.rb", "lib/reek/smells/long_parameter_list.rb", "lib/reek/smells/long_yield_list.rb", "lib/reek/smells/nested_iterators.rb", "lib/reek/smells/simulated_polymorphism.rb", "lib/reek/smells/smell_detector.rb", "lib/reek/smells/uncommunicative_name.rb", "lib/reek/smells/utility_function.rb", "lib/reek/sniffer.rb", "lib/reek/stop_context.rb", "lib/reek/tree_dresser.rb", "lib/reek/yield_call_context.rb", "reek.gemspec", "spec/reek/adapters/report_spec.rb", "spec/reek/adapters/should_reek_of_spec.rb", "spec/reek/adapters/should_reek_only_of_spec.rb", "spec/reek/adapters/should_reek_spec.rb", "spec/reek/block_context_spec.rb", "spec/reek/class_context_spec.rb", "spec/reek/code_context_spec.rb", "spec/reek/code_parser_spec.rb", "spec/reek/config_spec.rb", "spec/reek/configuration_spec.rb", "spec/reek/if_context_spec.rb", "spec/reek/method_context_spec.rb", "spec/reek/module_context_spec.rb", "spec/reek/name_spec.rb", "spec/reek/object_refs_spec.rb", "spec/reek/object_source_spec.rb", "spec/reek/singleton_method_context_spec.rb", "spec/reek/smell_warning_spec.rb", "spec/reek/smells/attribute_spec.rb", "spec/reek/smells/behaves_like_variable_detector.rb", "spec/reek/smells/class_variable_spec.rb", "spec/reek/smells/control_couple_spec.rb", "spec/reek/smells/data_clump_spec.rb", "spec/reek/smells/duplication_spec.rb", "spec/reek/smells/feature_envy_spec.rb", "spec/reek/smells/large_class_spec.rb", "spec/reek/smells/long_method_spec.rb", "spec/reek/smells/long_parameter_list_spec.rb", "spec/reek/smells/nested_iterators_spec.rb", "spec/reek/smells/simulated_polymorphism_spec.rb", "spec/reek/smells/smell_detector_spec.rb", "spec/reek/smells/uncommunicative_name_spec.rb", "spec/reek/smells/utility_function_spec.rb", "spec/reek/sniffer_spec.rb", "spec/reek/stop_context_spec.rb", "spec/samples/all_but_one_masked/clean_one.rb", "spec/samples/all_but_one_masked/dirty.rb", "spec/samples/all_but_one_masked/masked.reek", "spec/samples/clean_due_to_masking/clean_one.rb", "spec/samples/clean_due_to_masking/clean_three.rb", "spec/samples/clean_due_to_masking/clean_two.rb", "spec/samples/clean_due_to_masking/dirty_one.rb", "spec/samples/clean_due_to_masking/dirty_two.rb", "spec/samples/clean_due_to_masking/masked.reek", "spec/samples/corrupt_config_file/corrupt.reek", "spec/samples/corrupt_config_file/dirty.rb", "spec/samples/empty_config_file/dirty.rb", "spec/samples/empty_config_file/empty.reek", "spec/samples/exceptions.reek", "spec/samples/inline.rb", "spec/samples/masked/dirty.rb", "spec/samples/masked/masked.reek", "spec/samples/mixed_results/clean_one.rb", "spec/samples/mixed_results/clean_three.rb", "spec/samples/mixed_results/clean_two.rb", "spec/samples/mixed_results/dirty_one.rb", "spec/samples/mixed_results/dirty_two.rb", "spec/samples/not_quite_masked/dirty.rb", "spec/samples/not_quite_masked/masked.reek", "spec/samples/optparse.rb", "spec/samples/overrides/masked/dirty.rb", "spec/samples/overrides/masked/lower.reek", "spec/samples/overrides/upper.reek", "spec/samples/redcloth.rb", "spec/samples/three_clean_files/clean_one.rb", "spec/samples/three_clean_files/clean_three.rb", "spec/samples/three_clean_files/clean_two.rb", "spec/samples/two_smelly_files/dirty_one.rb", "spec/samples/two_smelly_files/dirty_two.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/reek.rake", "tasks/test.rake"]
|
15
|
+
s.files = ["History.txt", "License.txt", "README.rdoc", "Rakefile", "bin/reek", "config/defaults.reek", "features/masking_smells.feature", "features/options.feature", "features/profile.feature", "features/rake_task.feature", "features/reports.feature", "features/samples.feature", "features/stdin.feature", "features/step_definitions/reek_steps.rb", "features/support/env.rb", "lib/reek.rb", "lib/reek/adapters/application.rb", "lib/reek/adapters/command_line.rb", "lib/reek/adapters/config_file.rb", "lib/reek/adapters/core_extras.rb", "lib/reek/adapters/rake_task.rb", "lib/reek/adapters/report.rb", "lib/reek/adapters/source.rb", "lib/reek/adapters/spec.rb", "lib/reek/block_context.rb", "lib/reek/class_context.rb", "lib/reek/code_context.rb", "lib/reek/code_parser.rb", "lib/reek/configuration.rb", "lib/reek/detector_stack.rb", "lib/reek/help_command.rb", "lib/reek/if_context.rb", "lib/reek/masking_collection.rb", "lib/reek/method_context.rb", "lib/reek/module_context.rb", "lib/reek/name.rb", "lib/reek/object_refs.rb", "lib/reek/reek_command.rb", "lib/reek/sexp_formatter.rb", "lib/reek/singleton_method_context.rb", "lib/reek/smell_warning.rb", "lib/reek/smells/attribute.rb", "lib/reek/smells/class_variable.rb", "lib/reek/smells/control_couple.rb", "lib/reek/smells/data_clump.rb", "lib/reek/smells/duplication.rb", "lib/reek/smells/feature_envy.rb", "lib/reek/smells/large_class.rb", "lib/reek/smells/long_method.rb", "lib/reek/smells/long_parameter_list.rb", "lib/reek/smells/long_yield_list.rb", "lib/reek/smells/nested_iterators.rb", "lib/reek/smells/simulated_polymorphism.rb", "lib/reek/smells/smell_detector.rb", "lib/reek/smells/uncommunicative_name.rb", "lib/reek/smells/utility_function.rb", "lib/reek/sniffer.rb", "lib/reek/stop_context.rb", "lib/reek/tree_dresser.rb", "lib/reek/version_command.rb", "lib/reek/yield_call_context.rb", "reek.gemspec", "spec/reek/adapters/report_spec.rb", "spec/reek/adapters/should_reek_of_spec.rb", "spec/reek/adapters/should_reek_only_of_spec.rb", "spec/reek/adapters/should_reek_spec.rb", "spec/reek/block_context_spec.rb", "spec/reek/class_context_spec.rb", "spec/reek/code_context_spec.rb", "spec/reek/code_parser_spec.rb", "spec/reek/config_spec.rb", "spec/reek/configuration_spec.rb", "spec/reek/help_command_spec.rb", "spec/reek/if_context_spec.rb", "spec/reek/masking_collection_spec.rb", "spec/reek/method_context_spec.rb", "spec/reek/module_context_spec.rb", "spec/reek/name_spec.rb", "spec/reek/object_refs_spec.rb", "spec/reek/object_source_spec.rb", "spec/reek/reek_command_spec.rb", "spec/reek/singleton_method_context_spec.rb", "spec/reek/smell_warning_spec.rb", "spec/reek/smells/attribute_spec.rb", "spec/reek/smells/behaves_like_variable_detector.rb", "spec/reek/smells/class_variable_spec.rb", "spec/reek/smells/control_couple_spec.rb", "spec/reek/smells/data_clump_spec.rb", "spec/reek/smells/duplication_spec.rb", "spec/reek/smells/feature_envy_spec.rb", "spec/reek/smells/large_class_spec.rb", "spec/reek/smells/long_method_spec.rb", "spec/reek/smells/long_parameter_list_spec.rb", "spec/reek/smells/nested_iterators_spec.rb", "spec/reek/smells/simulated_polymorphism_spec.rb", "spec/reek/smells/smell_detector_spec.rb", "spec/reek/smells/uncommunicative_name_spec.rb", "spec/reek/smells/utility_function_spec.rb", "spec/reek/sniffer_spec.rb", "spec/reek/stop_context_spec.rb", "spec/reek/tree_dresser_spec.rb", "spec/reek/version_command_spec.rb", "spec/samples/all_but_one_masked/clean_one.rb", "spec/samples/all_but_one_masked/dirty.rb", "spec/samples/all_but_one_masked/masked.reek", "spec/samples/clean_due_to_masking/clean_one.rb", "spec/samples/clean_due_to_masking/clean_three.rb", "spec/samples/clean_due_to_masking/clean_two.rb", "spec/samples/clean_due_to_masking/dirty_one.rb", "spec/samples/clean_due_to_masking/dirty_two.rb", "spec/samples/clean_due_to_masking/masked.reek", "spec/samples/corrupt_config_file/corrupt.reek", "spec/samples/corrupt_config_file/dirty.rb", "spec/samples/empty_config_file/dirty.rb", "spec/samples/empty_config_file/empty.reek", "spec/samples/exceptions.reek", "spec/samples/inline.rb", "spec/samples/masked/dirty.rb", "spec/samples/masked/masked.reek", "spec/samples/mixed_results/clean_one.rb", "spec/samples/mixed_results/clean_three.rb", "spec/samples/mixed_results/clean_two.rb", "spec/samples/mixed_results/dirty_one.rb", "spec/samples/mixed_results/dirty_two.rb", "spec/samples/not_quite_masked/dirty.rb", "spec/samples/not_quite_masked/masked.reek", "spec/samples/optparse.rb", "spec/samples/overrides/masked/dirty.rb", "spec/samples/overrides/masked/lower.reek", "spec/samples/overrides/upper.reek", "spec/samples/redcloth.rb", "spec/samples/three_clean_files/clean_one.rb", "spec/samples/three_clean_files/clean_three.rb", "spec/samples/three_clean_files/clean_two.rb", "spec/samples/two_smelly_files/dirty_one.rb", "spec/samples/two_smelly_files/dirty_two.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/reek.rake", "tasks/test.rake"]
|
16
16
|
s.homepage = %q{http://wiki.github.com/kevinrutherford/reek}
|
17
17
|
s.post_install_message = %q{
|
18
18
|
For more information on reek, see http://wiki.github.com/kevinrutherford/reek
|
@@ -9,7 +9,7 @@ include Reek
|
|
9
9
|
|
10
10
|
describe ReportSection, " when empty" do
|
11
11
|
before(:each) do
|
12
|
-
@rpt = ReportSection.new(''.sniff,
|
12
|
+
@rpt = ReportSection.new(''.sniff, false)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'has an empty quiet_report' do
|
@@ -19,7 +19,7 @@ end
|
|
19
19
|
|
20
20
|
describe ReportSection, "smell_list" do
|
21
21
|
before(:each) do
|
22
|
-
rpt = ReportSection.new('def simple(a) a[3] end'.sniff, false
|
22
|
+
rpt = ReportSection.new('def simple(a) a[3] end'.sniff, false)
|
23
23
|
@lines = rpt.smell_list.split("\n")
|
24
24
|
end
|
25
25
|
|
@@ -32,18 +32,18 @@ end
|
|
32
32
|
|
33
33
|
describe ReportSection, " as a SortedSet" do
|
34
34
|
it 'should only add a smell once' do
|
35
|
-
rpt = ReportSection.new(''.sniff, false
|
36
|
-
rpt
|
37
|
-
rpt
|
35
|
+
rpt = ReportSection.new(''.sniff, false)
|
36
|
+
rpt.found_smell SmellWarning.new(Smells::FeatureEnvy.new, "self", 'too many!', false)
|
37
|
+
rpt.found_smell SmellWarning.new(Smells::FeatureEnvy.new, "self", 'too many!', false)
|
38
38
|
lines = rpt.smell_list.split("\n")
|
39
39
|
lines.should have(1).lines
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should not count an identical masked smell' do
|
43
|
-
rpt = ReportSection.new(''.sniff, false
|
43
|
+
rpt = ReportSection.new(''.sniff, false)
|
44
44
|
# SMELL: Duplication -- the SmellWarning knows whether to call << or record_masked_smell
|
45
|
-
rpt
|
46
|
-
rpt.
|
45
|
+
rpt.found_smell SmellWarning.new(Smells::FeatureEnvy.new, "self", 'too many!', false)
|
46
|
+
rpt.found_masked_smell(SmellWarning.new(Smells::FeatureEnvy.new, "self", 'too many!', true))
|
47
47
|
rpt.header.should == 'string -- 1 warning'
|
48
48
|
end
|
49
49
|
end
|
@@ -11,7 +11,7 @@ describe ReekMatcher do
|
|
11
11
|
before :each do
|
12
12
|
smelly_code = Dir['spec/samples/two_smelly_files/*.rb']
|
13
13
|
@sniffers = smelly_code.sniff.sniffers
|
14
|
-
@full =
|
14
|
+
@full = VerboseReport.new(@sniffers, false).report
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'reports quietly' do
|
@@ -44,7 +44,7 @@ describe ShouldReekOnlyOf, 'checking code in a Dir' do
|
|
44
44
|
|
45
45
|
it 'reports the smells when should_not fails' do
|
46
46
|
@matcher.matches?(@smelly_dir).should be_true
|
47
|
-
@matcher.failure_message_for_should.should include(QuietReport.new(@smelly_dir.sniff.sniffers
|
47
|
+
@matcher.failure_message_for_should.should include(QuietReport.new(@smelly_dir.sniff.sniffers).report)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -65,7 +65,7 @@ describe ShouldReekOnlyOf, 'checking code in a File' do
|
|
65
65
|
|
66
66
|
it 'reports the smells when should_not fails' do
|
67
67
|
@matcher.matches?(@smelly_file).should be_true
|
68
|
-
@matcher.failure_message_for_should.should include(QuietReport.new(@smelly_file.sniff
|
68
|
+
@matcher.failure_message_for_should.should include(QuietReport.new(@smelly_file.sniff).report)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -23,7 +23,7 @@ describe ShouldReek, 'checking code in a string' do
|
|
23
23
|
|
24
24
|
it 'reports the smells when should_not fails' do
|
25
25
|
@matcher.matches?(@smelly_code).should be_true
|
26
|
-
@matcher.failure_message_for_should_not.should include(QuietReport.new(@smelly_code.sniff
|
26
|
+
@matcher.failure_message_for_should_not.should include(QuietReport.new(@smelly_code.sniff).report)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -44,7 +44,7 @@ describe ShouldReek, 'checking code in a Dir' do
|
|
44
44
|
|
45
45
|
it 'reports the smells when should_not fails' do
|
46
46
|
@matcher.matches?(@smelly_dir).should be_true
|
47
|
-
@matcher.failure_message_for_should_not.should include(QuietReport.new(@smelly_dir.sniff.sniffers
|
47
|
+
@matcher.failure_message_for_should_not.should include(QuietReport.new(@smelly_dir.sniff.sniffers).report)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -65,7 +65,7 @@ describe ShouldReek, 'checking code in a File' do
|
|
65
65
|
|
66
66
|
it 'reports the smells when should_not fails' do
|
67
67
|
@matcher.matches?(@smelly_file).should be_true
|
68
|
-
@matcher.failure_message_for_should_not.should include(QuietReport.new(@smelly_file.sniff
|
68
|
+
@matcher.failure_message_for_should_not.should include(QuietReport.new(@smelly_file.sniff).report)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -101,20 +101,20 @@ describe CodeContext do
|
|
101
101
|
@ctx = CodeContext.new(nil, ast)
|
102
102
|
end
|
103
103
|
it 'yields no calls' do
|
104
|
-
@ctx.
|
104
|
+
@ctx.each_node(:call, []) {|exp| raise "#{exp} yielded by empty module!"}
|
105
105
|
end
|
106
106
|
it 'yields one module' do
|
107
107
|
mods = 0
|
108
|
-
@ctx.
|
108
|
+
@ctx.each_node(:module, []) {|exp| mods += 1}
|
109
109
|
mods.should == 1
|
110
110
|
end
|
111
111
|
it "yields the module's full AST" do
|
112
|
-
@ctx.
|
112
|
+
@ctx.each_node(:module, []) {|exp| exp[1].should == @module_name.to_sym}
|
113
113
|
end
|
114
114
|
|
115
115
|
context 'with no block' do
|
116
116
|
it 'returns an empty array of ifs' do
|
117
|
-
@ctx.
|
117
|
+
@ctx.each_node(:if, []).should be_empty
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
@@ -128,24 +128,24 @@ describe CodeContext do
|
|
128
128
|
@ctx = CodeContext.new(nil, ast)
|
129
129
|
end
|
130
130
|
it 'yields no ifs' do
|
131
|
-
@ctx.
|
131
|
+
@ctx.each_node(:if, []) {|exp| raise "#{exp} yielded by empty module!"}
|
132
132
|
end
|
133
133
|
it 'yields one module' do
|
134
|
-
@ctx.
|
134
|
+
@ctx.each_node(:module, []).length.should == 1
|
135
135
|
end
|
136
136
|
it "yields the module's full AST" do
|
137
|
-
@ctx.
|
137
|
+
@ctx.each_node(:module, []) {|exp| exp[1].should == @module_name.to_sym}
|
138
138
|
end
|
139
139
|
it 'yields one method' do
|
140
|
-
@ctx.
|
140
|
+
@ctx.each_node(:defn, []).length.should == 1
|
141
141
|
end
|
142
142
|
it "yields the method's full AST" do
|
143
|
-
@ctx.
|
143
|
+
@ctx.each_node(:defn, []) {|exp| exp[1].should == @method_name.to_sym}
|
144
144
|
end
|
145
145
|
|
146
146
|
context 'pruning the traversal' do
|
147
147
|
it 'ignores the call inside the method' do
|
148
|
-
@ctx.
|
148
|
+
@ctx.each_node(:call, [:defn]).should be_empty
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
@@ -169,7 +169,7 @@ EOS
|
|
169
169
|
|
170
170
|
ast = src.to_reek_source.syntax_tree
|
171
171
|
ctx = CodeContext.new(nil, ast)
|
172
|
-
ctx.
|
172
|
+
ctx.each_node(:if, []).length.should == 3
|
173
173
|
end
|
174
174
|
end
|
175
175
|
end
|
@@ -37,91 +37,3 @@ describe CodeParser do
|
|
37
37
|
'def options() ozz.on { |@list| @prompt = !@list } end'.should_not reek
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
41
|
-
describe CodeParser do
|
42
|
-
context 'with no attributes' do
|
43
|
-
it 'records nothing in the class' do
|
44
|
-
klass = ClassContext.from_s('class Fred; end')
|
45
|
-
klass.attributes.should be_empty
|
46
|
-
end
|
47
|
-
it 'records nothing in the module' do
|
48
|
-
ctx = ModuleContext.from_s('module Fred; end')
|
49
|
-
ctx.attributes.should be_empty
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'with one attribute' do
|
54
|
-
shared_examples_for 'one attribute found' do
|
55
|
-
it 'records the attribute' do
|
56
|
-
@ctx.attributes.should include(Name.new(:property))
|
57
|
-
end
|
58
|
-
it 'records only that attribute' do
|
59
|
-
@ctx.attributes.length.should == 1
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'declared in a class' do
|
64
|
-
before :each do
|
65
|
-
@ctx = ClassContext.from_s('class Fred; attr :property; end')
|
66
|
-
end
|
67
|
-
|
68
|
-
it_should_behave_like 'one attribute found'
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'reader in a class' do
|
72
|
-
before :each do
|
73
|
-
@ctx = ClassContext.from_s('class Fred; attr_reader :property; end')
|
74
|
-
end
|
75
|
-
|
76
|
-
it_should_behave_like 'one attribute found'
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'writer in a class' do
|
80
|
-
before :each do
|
81
|
-
@ctx = ClassContext.from_s('class Fred; attr_writer :property; end')
|
82
|
-
end
|
83
|
-
|
84
|
-
it_should_behave_like 'one attribute found'
|
85
|
-
end
|
86
|
-
|
87
|
-
context 'accessor in a class' do
|
88
|
-
before :each do
|
89
|
-
@ctx = ClassContext.from_s('class Fred; attr_accessor :property; end')
|
90
|
-
end
|
91
|
-
|
92
|
-
it_should_behave_like 'one attribute found'
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'declared in a module' do
|
96
|
-
before :each do
|
97
|
-
@ctx = ModuleContext.from_s('module Fred; attr :property; end')
|
98
|
-
end
|
99
|
-
|
100
|
-
it_should_behave_like 'one attribute found'
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'reader in a module' do
|
104
|
-
before :each do
|
105
|
-
@ctx = ModuleContext.from_s('module Fred; attr_reader :property; end')
|
106
|
-
end
|
107
|
-
|
108
|
-
it_should_behave_like 'one attribute found'
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'writer in a module' do
|
112
|
-
before :each do
|
113
|
-
@ctx = ModuleContext.from_s('module Fred; attr_writer :property; end')
|
114
|
-
end
|
115
|
-
|
116
|
-
it_should_behave_like 'one attribute found'
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'accessor in a module' do
|
120
|
-
before :each do
|
121
|
-
@ctx = ModuleContext.from_s('module Fred; attr_accessor :property; end')
|
122
|
-
end
|
123
|
-
|
124
|
-
it_should_behave_like 'one attribute found'
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
require 'reek/help_command'
|
4
|
+
|
5
|
+
include Reek
|
6
|
+
|
7
|
+
describe HelpCommand do
|
8
|
+
before :each do
|
9
|
+
@text = 'Piece of interesting text'
|
10
|
+
@cmd = HelpCommand.new(@text)
|
11
|
+
@view = mock('view', :null_object => true)
|
12
|
+
@view.should_not_receive(:report_smells)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'displays the correct text on the view' do
|
16
|
+
@view.should_receive(:output).with(@text)
|
17
|
+
@cmd.execute(@view)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'tells the view it succeeded' do
|
21
|
+
@view.should_receive(:report_success)
|
22
|
+
@cmd.execute(@view)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,236 @@
|
|
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.add(@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.add_masked(@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.add_masked(@masked)
|
99
|
+
@collection.add(@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.add(@item)
|
135
|
+
@collection.add(@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.add_masked(@item)
|
144
|
+
@collection.add_masked(@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.add(@first_item)
|
154
|
+
@collection.add(@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.add_masked(@first_item)
|
190
|
+
@collection.add_masked(@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.add_masked(@item)
|
223
|
+
@collection.add(@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.add(@item)
|
232
|
+
@collection.add_masked(@item)
|
233
|
+
end
|
234
|
+
it_should_behave_like 'one visible item'
|
235
|
+
end
|
236
|
+
end
|