reek 1.2.7.1 → 1.2.7.2
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/History.txt +13 -1
- data/config/defaults.reek +4 -1
- data/features/masking_smells.feature +7 -7
- data/features/rake_task.feature +2 -2
- data/features/reports.feature +3 -3
- data/features/samples.feature +5 -2
- data/features/yaml.feature +0 -39
- data/lib/reek.rb +1 -1
- data/lib/reek/cli/command_line.rb +3 -3
- data/lib/reek/cli/reek_command.rb +5 -6
- data/lib/reek/cli/report.rb +9 -20
- data/lib/reek/cli/yaml_command.rb +1 -1
- data/lib/reek/core/class_context.rb +1 -2
- data/lib/reek/core/code_context.rb +10 -27
- data/lib/reek/core/code_parser.rb +1 -18
- data/lib/reek/core/detector_stack.rb +4 -0
- data/lib/reek/core/masking_collection.rb +6 -0
- data/lib/reek/core/method_context.rb +8 -56
- data/lib/reek/core/module_context.rb +6 -32
- data/lib/reek/core/object_refs.rb +36 -36
- data/lib/reek/core/singleton_method_context.rb +10 -21
- data/lib/reek/core/sniffer.rb +3 -2
- data/lib/reek/examiner.rb +39 -31
- data/lib/reek/smell_warning.rb +8 -0
- data/lib/reek/smells/attribute.rb +4 -2
- data/lib/reek/smells/class_variable.rb +3 -3
- data/lib/reek/smells/control_couple.rb +1 -2
- data/lib/reek/smells/data_clump.rb +86 -9
- data/lib/reek/smells/duplication.rb +2 -3
- data/lib/reek/smells/feature_envy.rb +9 -4
- data/lib/reek/smells/simulated_polymorphism.rb +1 -2
- data/lib/reek/smells/smell_detector.rb +0 -6
- data/lib/reek/smells/uncommunicative_method_name.rb +8 -2
- data/lib/reek/smells/uncommunicative_parameter_name.rb +1 -1
- data/lib/reek/smells/uncommunicative_variable_name.rb +1 -1
- data/lib/reek/smells/utility_function.rb +17 -5
- data/lib/reek/source/reference_collector.rb +21 -0
- data/lib/reek/source/sexp_formatter.rb +1 -0
- data/lib/reek/source/tree_dresser.rb +67 -9
- data/lib/reek/spec/should_reek.rb +1 -1
- data/lib/reek/spec/should_reek_of.rb +1 -1
- data/lib/reek/spec/should_reek_only_of.rb +1 -1
- data/reek.gemspec +3 -3
- data/spec/reek/cli/reek_command_spec.rb +3 -2
- data/spec/reek/cli/report_spec.rb +2 -2
- data/spec/reek/cli/yaml_command_spec.rb +2 -2
- data/spec/reek/core/code_context_spec.rb +39 -54
- data/spec/reek/core/method_context_spec.rb +7 -26
- data/spec/reek/core/module_context_spec.rb +0 -15
- data/spec/reek/core/singleton_method_context_spec.rb +0 -6
- data/spec/reek/examiner_spec.rb +6 -6
- data/spec/reek/smells/attribute_spec.rb +30 -32
- data/spec/reek/smells/class_variable_spec.rb +15 -18
- data/spec/reek/smells/data_clump_spec.rb +22 -6
- data/spec/reek/smells/duplication_spec.rb +33 -19
- data/spec/reek/smells/feature_envy_spec.rb +82 -88
- data/spec/reek/smells/large_class_spec.rb +1 -1
- data/spec/reek/smells/smell_detector_shared.rb +1 -1
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +37 -35
- data/spec/reek/smells/utility_function_spec.rb +7 -0
- data/spec/reek/source/reference_collector_spec.rb +53 -0
- data/spec/reek/source/tree_dresser_spec.rb +10 -0
- data/spec/reek/spec/should_reek_only_of_spec.rb +1 -1
- data/spec/spec_helper.rb +7 -0
- metadata +4 -5
- data/features/profile.feature +0 -34
- data/lib/reek/core/block_context.rb +0 -18
- data/spec/reek/core/block_context_spec.rb +0 -26
@@ -14,7 +14,7 @@ module Reek
|
|
14
14
|
end
|
15
15
|
def matches?(actual)
|
16
16
|
@examiner = Examiner.new(actual)
|
17
|
-
@all_smells = @examiner.
|
17
|
+
@all_smells = @examiner.smells
|
18
18
|
@all_smells.any? {|warning| warning.matches?(@klass, @patterns)}
|
19
19
|
end
|
20
20
|
def failure_message_for_should
|
@@ -13,7 +13,7 @@ module Reek
|
|
13
13
|
end
|
14
14
|
def matches_examiner?(examiner)
|
15
15
|
@examiner = examiner
|
16
|
-
@all_smells = @examiner.
|
16
|
+
@all_smells = @examiner.smells
|
17
17
|
@all_smells.length == 1 and @all_smells[0].matches?(@klass, @patterns)
|
18
18
|
end
|
19
19
|
def failure_message_for_should
|
data/reek.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{reek}
|
5
|
-
s.version = "1.2.7.
|
5
|
+
s.version = "1.2.7.2"
|
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{2010-
|
9
|
+
s.date = %q{2010-03-05}
|
10
10
|
s.default_executable = %q{reek}
|
11
11
|
s.description = %q{Reek is a tool that examines Ruby classes, modules and methods
|
12
12
|
and reports any code smells it finds.
|
@@ -14,7 +14,7 @@ and reports any code smells it finds.
|
|
14
14
|
s.email = ["kevin@rutherford-software.com"]
|
15
15
|
s.executables = ["reek"]
|
16
16
|
s.extra_rdoc_files = ["History.txt", "License.txt"]
|
17
|
-
s.files = [".yardopts", "History.txt", "License.txt", "README.md", "Rakefile", "bin/reek", "config/defaults.reek", "features/masking_smells.feature", "features/options.feature", "features/
|
17
|
+
s.files = [".yardopts", "History.txt", "License.txt", "README.md", "Rakefile", "bin/reek", "config/defaults.reek", "features/masking_smells.feature", "features/options.feature", "features/rake_task.feature", "features/reports.feature", "features/samples.feature", "features/stdin.feature", "features/step_definitions/reek_steps.rb", "features/support/env.rb", "features/yaml.feature", "lib/reek.rb", "lib/reek/cli/application.rb", "lib/reek/cli/command_line.rb", "lib/reek/cli/help_command.rb", "lib/reek/cli/reek_command.rb", "lib/reek/cli/report.rb", "lib/reek/cli/version_command.rb", "lib/reek/cli/yaml_command.rb", "lib/reek/core/class_context.rb", "lib/reek/core/code_context.rb", "lib/reek/core/code_parser.rb", "lib/reek/core/detector_stack.rb", "lib/reek/core/masking_collection.rb", "lib/reek/core/method_context.rb", "lib/reek/core/module_context.rb", "lib/reek/core/object_refs.rb", "lib/reek/core/singleton_method_context.rb", "lib/reek/core/smell_configuration.rb", "lib/reek/core/sniffer.rb", "lib/reek/core/stop_context.rb", "lib/reek/examiner.rb", "lib/reek/rake/task.rb", "lib/reek/smell_warning.rb", "lib/reek/smells.rb", "lib/reek/smells/attribute.rb", "lib/reek/smells/boolean_parameter.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/irresponsible_module.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_method_name.rb", "lib/reek/smells/uncommunicative_module_name.rb", "lib/reek/smells/uncommunicative_parameter_name.rb", "lib/reek/smells/uncommunicative_variable_name.rb", "lib/reek/smells/utility_function.rb", "lib/reek/source.rb", "lib/reek/source/code_comment.rb", "lib/reek/source/config_file.rb", "lib/reek/source/core_extras.rb", "lib/reek/source/reference_collector.rb", "lib/reek/source/sexp_formatter.rb", "lib/reek/source/source_code.rb", "lib/reek/source/source_file.rb", "lib/reek/source/source_locator.rb", "lib/reek/source/tree_dresser.rb", "lib/reek/spec.rb", "lib/reek/spec/should_reek.rb", "lib/reek/spec/should_reek_of.rb", "lib/reek/spec/should_reek_only_of.rb", "reek.gemspec", "spec/reek/cli/help_command_spec.rb", "spec/reek/cli/reek_command_spec.rb", "spec/reek/cli/report_spec.rb", "spec/reek/cli/version_command_spec.rb", "spec/reek/cli/yaml_command_spec.rb", "spec/reek/core/class_context_spec.rb", "spec/reek/core/code_context_spec.rb", "spec/reek/core/code_parser_spec.rb", "spec/reek/core/config_spec.rb", "spec/reek/core/masking_collection_spec.rb", "spec/reek/core/method_context_spec.rb", "spec/reek/core/module_context_spec.rb", "spec/reek/core/object_refs_spec.rb", "spec/reek/core/singleton_method_context_spec.rb", "spec/reek/core/smell_configuration_spec.rb", "spec/reek/core/stop_context_spec.rb", "spec/reek/examiner_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/boolean_parameter_spec.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/irresponsible_module_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/long_yield_list_spec.rb", "spec/reek/smells/nested_iterators_spec.rb", "spec/reek/smells/simulated_polymorphism_spec.rb", "spec/reek/smells/smell_detector_shared.rb", "spec/reek/smells/uncommunicative_method_name_spec.rb", "spec/reek/smells/uncommunicative_module_name_spec.rb", "spec/reek/smells/uncommunicative_parameter_name_spec.rb", "spec/reek/smells/uncommunicative_variable_name_spec.rb", "spec/reek/smells/utility_function_spec.rb", "spec/reek/source/code_comment_spec.rb", "spec/reek/source/object_source_spec.rb", "spec/reek/source/reference_collector_spec.rb", "spec/reek/source/source_code_spec.rb", "spec/reek/source/tree_dresser_spec.rb", "spec/reek/spec/should_reek_of_spec.rb", "spec/reek/spec/should_reek_only_of_spec.rb", "spec/reek/spec/should_reek_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"]
|
18
18
|
s.homepage = %q{http://wiki.github.com/kevinrutherford/reek}
|
19
19
|
s.post_install_message = %q{
|
20
20
|
For more information on reek, see http://wiki.github.com/kevinrutherford/reek
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
|
2
2
|
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'cli', 'reek_command')
|
3
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'cli', 'report')
|
3
4
|
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'examiner')
|
4
5
|
|
5
6
|
include Reek
|
@@ -13,7 +14,7 @@ describe ReekCommand do
|
|
13
14
|
context 'with smells' do
|
14
15
|
before :each do
|
15
16
|
examiner = Examiner.new('def x(); end')
|
16
|
-
@cmd = ReekCommand.new([examiner], QuietReport
|
17
|
+
@cmd = ReekCommand.new([examiner], QuietReport)
|
17
18
|
end
|
18
19
|
|
19
20
|
it 'displays the correct text on the view' do
|
@@ -30,7 +31,7 @@ describe ReekCommand do
|
|
30
31
|
context 'with no smells' do
|
31
32
|
before :each do
|
32
33
|
examiner = Examiner.new('def clean(); end')
|
33
|
-
@cmd = ReekCommand.new([examiner], QuietReport
|
34
|
+
@cmd = ReekCommand.new([examiner], QuietReport)
|
34
35
|
end
|
35
36
|
|
36
37
|
it 'displays nothing on the view' do
|
@@ -9,14 +9,14 @@ describe ReportSection, " when empty" do
|
|
9
9
|
context 'empty source' do
|
10
10
|
it 'has an empty quiet_report' do
|
11
11
|
examiner = Examiner.new('')
|
12
|
-
ReportSection.new(examiner
|
12
|
+
ReportSection.new(examiner).quiet_report.should == ''
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'with a couple of smells' do
|
17
17
|
it 'should mention every smell name' do
|
18
18
|
examiner = Examiner.new('def simple(a) a[3] end')
|
19
|
-
rpt = ReportSection.new(examiner
|
19
|
+
rpt = ReportSection.new(examiner)
|
20
20
|
@lines = rpt.smell_list.split("\n")
|
21
21
|
@lines.should have_at_least(2).lines
|
22
22
|
@lines[0].should match('[Utility Function]')
|
@@ -12,7 +12,7 @@ describe YamlCommand do
|
|
12
12
|
|
13
13
|
context 'with no smells' do
|
14
14
|
before :each do
|
15
|
-
@examiner.should_receive(:
|
15
|
+
@examiner.should_receive(:smells).and_return([])
|
16
16
|
@cmd = YamlCommand.new([@examiner])
|
17
17
|
end
|
18
18
|
|
@@ -30,7 +30,7 @@ describe YamlCommand do
|
|
30
30
|
context 'with smells' do
|
31
31
|
before :each do
|
32
32
|
@smell = SmellWarning.new('UncommunicativeName', "self", 27, "self", true)
|
33
|
-
@examiner.should_receive(:
|
33
|
+
@examiner.should_receive(:smells).and_return([@smell])
|
34
34
|
@cmd = YamlCommand.new([@examiner])
|
35
35
|
end
|
36
36
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
|
2
|
-
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'block_context')
|
3
2
|
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'class_context')
|
4
3
|
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'method_context')
|
5
4
|
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'module_context')
|
@@ -8,30 +7,47 @@ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expan
|
|
8
7
|
include Reek::Core
|
9
8
|
|
10
9
|
describe CodeContext do
|
11
|
-
context '
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
element.full_name.should match(/klass/)
|
20
|
-
element.full_name.should match(/mod/)
|
10
|
+
context 'name recognition' do
|
11
|
+
before :each do
|
12
|
+
@exp_name = 'random_name' # SMELL: could use a String.random here
|
13
|
+
@full_name = "::::::::::::::::::::#{@exp_name}"
|
14
|
+
@exp = mock('exp')
|
15
|
+
@exp.should_receive(:name).any_number_of_times.and_return(@exp_name)
|
16
|
+
@exp.should_receive(:full_name).any_number_of_times.and_return(@full_name)
|
17
|
+
@ctx = CodeContext.new(nil, @exp)
|
21
18
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
it 'gets its short name from the exp' do
|
20
|
+
@ctx.name.should == @exp_name
|
21
|
+
end
|
22
|
+
it 'does not match an empty list' do
|
23
|
+
@ctx.matches?([]).should == false
|
24
|
+
end
|
25
|
+
it 'does not match when its own short name is not given' do
|
26
|
+
@ctx.matches?(['banana']).should == false
|
27
|
+
end
|
28
|
+
it 'recognises its own short name' do
|
29
|
+
@ctx.matches?(['banana', @exp_name]).should == true
|
30
|
+
end
|
31
|
+
it 'recognises its short name as a regex' do
|
32
|
+
@ctx.matches?([/banana/, /#{@exp_name}/]).should == true
|
28
33
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
|
35
|
+
context 'when there is an outer' do
|
36
|
+
before :each do
|
37
|
+
@outer_name = 'another_random sting'
|
38
|
+
outer = mock('outer')
|
39
|
+
outer.should_receive(:full_name).at_least(:once).and_return(@outer_name)
|
40
|
+
@ctx = CodeContext.new(outer, @exp)
|
41
|
+
end
|
42
|
+
it 'creates the correct full name' do
|
43
|
+
@ctx.full_name.should == "#{@full_name}"
|
44
|
+
end
|
45
|
+
it 'recognises its own full name' do
|
46
|
+
@ctx.matches?(['banana', @full_name]).should == true
|
47
|
+
end
|
48
|
+
it 'recognises its full name as a regex' do
|
49
|
+
@ctx.matches?([/banana/, /#{@full_name}/]).should == true
|
50
|
+
end
|
35
51
|
end
|
36
52
|
end
|
37
53
|
|
@@ -42,41 +58,10 @@ describe CodeContext do
|
|
42
58
|
element = ModuleContext.new(stop, 'mod', s(:module, :mod, nil))
|
43
59
|
class_element = ClassContext.new(element, [0, :klass], s())
|
44
60
|
element = MethodContext.new(class_element, [0, :bad])
|
45
|
-
element = BlockContext.new(element, s(nil, nil))
|
46
61
|
element.bananas(17, -5).should == 55
|
47
62
|
end
|
48
63
|
end
|
49
64
|
|
50
|
-
context 'name matching' do
|
51
|
-
it 'should recognise itself in a collection of names' do
|
52
|
-
element = StopContext.new
|
53
|
-
element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
|
54
|
-
element.matches?(['banana', 'mod']).should == true
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'should recognise itself in a collection of REs' do
|
58
|
-
element = StopContext.new
|
59
|
-
element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
|
60
|
-
element.matches?([/banana/, /mod/]).should == true
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should recognise its fq name in a collection of names' do
|
64
|
-
element = StopContext.new
|
65
|
-
element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
|
66
|
-
element = ClassContext.create(element, s(:class, :klass))
|
67
|
-
element.matches?(['banana', 'mod']).should == true
|
68
|
-
element.matches?(['banana', 'mod::klass']).should == true
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should recognise its fq name in a collection of names' do
|
72
|
-
element = StopContext.new
|
73
|
-
element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
|
74
|
-
element = ClassContext.create(element, s(:class, :klass))
|
75
|
-
element.matches?([/banana/, /mod/]).should == true
|
76
|
-
element.matches?([/banana/, /mod::klass/]).should == true
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
65
|
context 'enumerating syntax elements' do
|
81
66
|
context 'in an empty module' do
|
82
67
|
before :each do
|
@@ -6,7 +6,9 @@ include Reek::Core
|
|
6
6
|
|
7
7
|
describe MethodContext, 'matching' do
|
8
8
|
before :each do
|
9
|
-
|
9
|
+
exp = mock('exp', :null_object => true)
|
10
|
+
exp.should_receive(:full_name).at_least(:once).and_return('mod')
|
11
|
+
@element = MethodContext.new(StopContext.new, exp)
|
10
12
|
end
|
11
13
|
|
12
14
|
it 'should recognise itself in a collection of names' do
|
@@ -20,46 +22,25 @@ describe MethodContext, 'matching' do
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
describe MethodContext, 'matching fq names' do
|
24
|
-
before :each do
|
25
|
-
element = StopContext.new
|
26
|
-
element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
|
27
|
-
element = ClassContext.new(element, 'klass', s())
|
28
|
-
@element = MethodContext.new(element, s(0, :meth))
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should recognise itself in a collection of names' do
|
32
|
-
@element.matches?(['banana', 'meth']).should == true
|
33
|
-
@element.matches?(['banana', 'klass#meth']).should == true
|
34
|
-
@element.matches?(['banana']).should == false
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should recognise itself in a collection of names' do
|
38
|
-
@element.matches?([/banana/, /meth/]).should == true
|
39
|
-
@element.matches?([/banana/, /klass#meth/]).should == true
|
40
|
-
@element.matches?([/banana/]).should == false
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
25
|
describe MethodContext do
|
45
26
|
it 'should record ivars as refs to self' do
|
46
27
|
mctx = MethodContext.new(StopContext.new, [:defn, :feed])
|
47
28
|
mctx.envious_receivers.should == []
|
48
|
-
mctx.record_call_to(
|
29
|
+
mctx.record_call_to(ast(:call, s(:ivar, :@cow), :feed_to))
|
49
30
|
mctx.envious_receivers.should == []
|
50
31
|
end
|
51
32
|
|
52
33
|
it 'should count calls to self' do
|
53
34
|
mctx = MethodContext.new(StopContext.new, [:defn, :equals])
|
54
35
|
mctx.refs.record_ref([:lvar, :other])
|
55
|
-
mctx.record_call_to(
|
36
|
+
mctx.record_call_to(ast(:call, s(:self), :thing))
|
56
37
|
mctx.envious_receivers.should be_empty
|
57
38
|
end
|
58
39
|
|
59
40
|
it 'should recognise a call on self' do
|
60
41
|
mc = MethodContext.new(StopContext.new, s(:defn, :deep))
|
61
|
-
mc.record_call_to(
|
62
|
-
mc.record_call_to(
|
42
|
+
mc.record_call_to(ast(:call, s(:lvar, :text), :each, s(:arglist)))
|
43
|
+
mc.record_call_to(ast(:call, nil, :shelve, s(:arglist)))
|
63
44
|
mc.envious_receivers.should be_empty
|
64
45
|
end
|
65
46
|
end
|
@@ -24,19 +24,4 @@ module ::Global
|
|
24
24
|
# module for test
|
25
25
|
class Inside; end; end'.should_not reek
|
26
26
|
end
|
27
|
-
|
28
|
-
context 'full_name' do
|
29
|
-
it "reports full context" do
|
30
|
-
element = StopContext.new
|
31
|
-
element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
|
32
|
-
element.full_name.should == 'mod'
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'finds fq loaded class' do
|
37
|
-
exp = [:class, :"Reek::Smells::LargeClass", nil]
|
38
|
-
ctx = StopContext.new
|
39
|
-
res = ModuleContext.resolve(exp[1], ctx)
|
40
|
-
res[1].should == "LargeClass"
|
41
|
-
end
|
42
27
|
end
|
@@ -6,10 +6,4 @@ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expan
|
|
6
6
|
include Reek::Core
|
7
7
|
|
8
8
|
describe SingletonMethodContext do
|
9
|
-
it "reports full context" do
|
10
|
-
element = StopContext.new
|
11
|
-
element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
|
12
|
-
element = SingletonMethodContext.new(element, s(:defs, s(:call, nil, :a, s(:arglist)), :b, s(:args)))
|
13
|
-
element.full_name.should match(/mod#a\.b/)
|
14
|
-
end
|
15
9
|
end
|
data/spec/reek/examiner_spec.rb
CHANGED
@@ -10,32 +10,32 @@ describe Examiner do
|
|
10
10
|
end
|
11
11
|
it 'doesnt match a fragrant String' do
|
12
12
|
examiner = Examiner.new('def good() true; end')
|
13
|
-
examiner.
|
13
|
+
examiner.smells.should == []
|
14
14
|
end
|
15
15
|
it 'matches a smelly String' do
|
16
|
-
Examiner.new('def fine() y = 4; end').
|
16
|
+
Examiner.new('def fine() y = 4; end').smells.length.should == 1
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'checking code in a Dir' do
|
20
20
|
it 'matches a smelly Dir' do
|
21
21
|
smelly_dir = Dir['spec/samples/all_but_one_masked/*.rb']
|
22
|
-
Examiner.new(smelly_dir).
|
22
|
+
Examiner.new(smelly_dir).smells.length.should == 1
|
23
23
|
end
|
24
24
|
it 'doesnt match a fragrant Dir' do
|
25
25
|
clean_dir = Dir['spec/samples/three_clean_files/*.rb']
|
26
|
-
Examiner.new(clean_dir).
|
26
|
+
Examiner.new(clean_dir).smells.length.should == 0
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'checking code in a File' do
|
31
31
|
it 'matches a smelly File' do
|
32
32
|
smelly_file = File.new(Dir['spec/samples/all_but_one_masked/d*.rb'][0])
|
33
|
-
Examiner.new(smelly_file).
|
33
|
+
Examiner.new(smelly_file).smells.length.should == 1
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'doesnt match a fragrant File' do
|
37
37
|
clean_file = File.new(Dir['spec/samples/three_clean_files/*.rb'][0])
|
38
|
-
Examiner.new(clean_file).
|
38
|
+
Examiner.new(clean_file).smells.length.should == 0
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -27,18 +27,37 @@ describe Attribute do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'with one attribute' do
|
30
|
+
before :each do
|
31
|
+
@attr_name = 'super_thing'
|
32
|
+
end
|
33
|
+
|
30
34
|
shared_examples_for 'one attribute found' do
|
31
|
-
|
32
|
-
|
35
|
+
before :each do
|
36
|
+
ctx = CodeContext.new(nil, @src.to_reek_source.syntax_tree)
|
37
|
+
@detector.examine_context(ctx)
|
38
|
+
@smells = @detector.smells_found.to_a
|
33
39
|
end
|
40
|
+
|
34
41
|
it 'records only that attribute' do
|
35
|
-
@
|
42
|
+
@smells.length.should == 1
|
43
|
+
end
|
44
|
+
it 'reports the attribute name' do
|
45
|
+
@smells[0].smell[Attribute::ATTRIBUTE_KEY].should == @attr_name
|
46
|
+
end
|
47
|
+
it 'reports the declaration line number' do
|
48
|
+
@smells[0].lines.should == [1]
|
49
|
+
end
|
50
|
+
it 'reports the correct smell class' do
|
51
|
+
@smells[0].smell_class.should == Attribute::SMELL_CLASS
|
52
|
+
end
|
53
|
+
it 'reports the context fq name' do
|
54
|
+
@smells[0].context.should == 'Fred'
|
36
55
|
end
|
37
56
|
end
|
38
57
|
|
39
58
|
context 'declared in a class' do
|
40
59
|
before :each do
|
41
|
-
@
|
60
|
+
@src = "class Fred; attr :#{@attr_name}; end"
|
42
61
|
end
|
43
62
|
|
44
63
|
it_should_behave_like 'one attribute found'
|
@@ -46,7 +65,7 @@ describe Attribute do
|
|
46
65
|
|
47
66
|
context 'reader in a class' do
|
48
67
|
before :each do
|
49
|
-
@
|
68
|
+
@src = "class Fred; attr_reader :#{@attr_name}; end"
|
50
69
|
end
|
51
70
|
|
52
71
|
it_should_behave_like 'one attribute found'
|
@@ -54,7 +73,7 @@ describe Attribute do
|
|
54
73
|
|
55
74
|
context 'writer in a class' do
|
56
75
|
before :each do
|
57
|
-
@
|
76
|
+
@src = "class Fred; attr_writer :#{@attr_name}; end"
|
58
77
|
end
|
59
78
|
|
60
79
|
it_should_behave_like 'one attribute found'
|
@@ -62,7 +81,7 @@ describe Attribute do
|
|
62
81
|
|
63
82
|
context 'accessor in a class' do
|
64
83
|
before :each do
|
65
|
-
@
|
84
|
+
@src = "class Fred; attr_accessor :#{@attr_name}; end"
|
66
85
|
end
|
67
86
|
|
68
87
|
it_should_behave_like 'one attribute found'
|
@@ -70,7 +89,7 @@ describe Attribute do
|
|
70
89
|
|
71
90
|
context 'declared in a module' do
|
72
91
|
before :each do
|
73
|
-
@
|
92
|
+
@src = "module Fred; attr :#{@attr_name}; end"
|
74
93
|
end
|
75
94
|
|
76
95
|
it_should_behave_like 'one attribute found'
|
@@ -78,7 +97,7 @@ describe Attribute do
|
|
78
97
|
|
79
98
|
context 'reader in a module' do
|
80
99
|
before :each do
|
81
|
-
@
|
100
|
+
@src = "module Fred; attr_reader :#{@attr_name}; end"
|
82
101
|
end
|
83
102
|
|
84
103
|
it_should_behave_like 'one attribute found'
|
@@ -86,7 +105,7 @@ describe Attribute do
|
|
86
105
|
|
87
106
|
context 'writer in a module' do
|
88
107
|
before :each do
|
89
|
-
@
|
108
|
+
@src = "module Fred; attr_writer :#{@attr_name}; end"
|
90
109
|
end
|
91
110
|
|
92
111
|
it_should_behave_like 'one attribute found'
|
@@ -94,31 +113,10 @@ describe Attribute do
|
|
94
113
|
|
95
114
|
context 'accessor in a module' do
|
96
115
|
before :each do
|
97
|
-
@
|
116
|
+
@src = "module Fred; attr_accessor :#{@attr_name}; end"
|
98
117
|
end
|
99
118
|
|
100
119
|
it_should_behave_like 'one attribute found'
|
101
120
|
end
|
102
121
|
end
|
103
|
-
|
104
|
-
context 'looking at the YAML' do
|
105
|
-
before :each do
|
106
|
-
@attr = 'prop'
|
107
|
-
src = <<EOS
|
108
|
-
module Fred
|
109
|
-
attr_writer :#{@attr}
|
110
|
-
end
|
111
|
-
EOS
|
112
|
-
@ctx = ModuleContext.from_s(src)
|
113
|
-
@detector.examine_context(@ctx)
|
114
|
-
warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
|
115
|
-
@yaml = warning.to_yaml
|
116
|
-
end
|
117
|
-
it 'reports the attribute' do
|
118
|
-
@yaml.should match(/attribute:\s*#{@attr}/)
|
119
|
-
end
|
120
|
-
it 'reports the declaration line number' do
|
121
|
-
@yaml.should match(/lines:[\s-]*3/)
|
122
|
-
end
|
123
|
-
end
|
124
122
|
end
|