reek 1.2.6 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +10 -0
- data/History.txt +20 -0
- data/README.md +90 -0
- data/bin/reek +2 -2
- data/config/defaults.reek +34 -4
- data/features/masking_smells.feature +35 -15
- data/features/options.feature +2 -0
- data/features/rake_task.feature +11 -18
- data/features/reports.feature +13 -15
- data/features/samples.feature +90 -105
- data/features/stdin.feature +3 -6
- data/features/step_definitions/reek_steps.rb +8 -4
- data/features/support/env.rb +2 -3
- data/features/yaml.feature +124 -0
- data/lib/reek.rb +8 -4
- data/lib/reek/cli/application.rb +46 -0
- data/lib/reek/cli/command_line.rb +106 -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 +91 -0
- data/lib/reek/cli/version_command.rb +19 -0
- data/lib/reek/cli/yaml_command.rb +32 -0
- data/lib/reek/core/block_context.rb +18 -0
- data/lib/reek/core/class_context.rb +23 -0
- data/lib/reek/core/code_context.rb +72 -0
- data/lib/reek/core/code_parser.rb +192 -0
- data/lib/reek/core/detector_stack.rb +29 -0
- data/lib/reek/core/masking_collection.rb +46 -0
- data/lib/reek/core/method_context.rb +132 -0
- data/lib/reek/core/module_context.rb +64 -0
- data/lib/reek/{object_refs.rb → core/object_refs.rb} +8 -6
- data/lib/reek/{singleton_method_context.rb → core/singleton_method_context.rb} +10 -5
- data/lib/reek/core/smell_configuration.rb +66 -0
- data/lib/reek/core/sniffer.rb +110 -0
- data/lib/reek/core/stop_context.rb +26 -0
- data/lib/reek/examiner.rb +88 -0
- data/lib/reek/rake/task.rb +124 -0
- data/lib/reek/smell_warning.rb +69 -13
- data/lib/reek/smells.rb +29 -0
- data/lib/reek/smells/attribute.rb +13 -14
- data/lib/reek/smells/boolean_parameter.rb +33 -0
- data/lib/reek/smells/class_variable.rb +8 -6
- data/lib/reek/smells/control_couple.rb +33 -17
- data/lib/reek/smells/data_clump.rb +10 -6
- data/lib/reek/smells/duplication.rb +24 -14
- data/lib/reek/smells/feature_envy.rb +11 -6
- data/lib/reek/smells/irresponsible_module.rb +28 -0
- data/lib/reek/smells/large_class.rb +9 -7
- data/lib/reek/smells/long_method.rb +6 -5
- data/lib/reek/smells/long_parameter_list.rb +11 -9
- data/lib/reek/smells/long_yield_list.rb +37 -7
- data/lib/reek/smells/nested_iterators.rb +34 -9
- data/lib/reek/smells/simulated_polymorphism.rb +15 -11
- data/lib/reek/smells/smell_detector.rb +24 -12
- data/lib/reek/smells/uncommunicative_method_name.rb +76 -0
- data/lib/reek/smells/uncommunicative_module_name.rb +76 -0
- data/lib/reek/smells/{uncommunicative_name.rb → uncommunicative_parameter_name.rb} +14 -26
- data/lib/reek/smells/uncommunicative_variable_name.rb +90 -0
- data/lib/reek/smells/utility_function.rb +33 -9
- data/lib/reek/source.rb +18 -0
- data/lib/reek/source/code_comment.rb +19 -0
- data/lib/reek/source/config_file.rb +72 -0
- data/lib/reek/source/core_extras.rb +46 -0
- data/lib/reek/source/sexp_formatter.rb +16 -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 +36 -0
- data/lib/reek/source/tree_dresser.rb +128 -0
- data/lib/reek/spec.rb +51 -0
- data/lib/reek/spec/should_reek.rb +34 -0
- data/lib/reek/spec/should_reek_of.rb +37 -0
- data/lib/reek/spec/should_reek_only_of.rb +36 -0
- data/reek.gemspec +5 -5
- data/spec/reek/{help_command_spec.rb → cli/help_command_spec.rb} +3 -4
- data/spec/reek/{reek_command_spec.rb → cli/reek_command_spec.rb} +8 -7
- data/spec/reek/cli/report_spec.rb +26 -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/block_context_spec.rb +26 -0
- data/spec/reek/core/class_context_spec.rb +53 -0
- data/spec/reek/{code_context_spec.rb → core/code_context_spec.rb} +15 -37
- data/spec/reek/{code_parser_spec.rb → core/code_parser_spec.rb} +5 -5
- data/spec/reek/{config_spec.rb → core/config_spec.rb} +2 -6
- data/spec/reek/{masking_collection_spec.rb → core/masking_collection_spec.rb} +3 -4
- data/spec/reek/{method_context_spec.rb → core/method_context_spec.rb} +6 -7
- data/spec/reek/core/module_context_spec.rb +42 -0
- data/spec/reek/{object_refs_spec.rb → core/object_refs_spec.rb} +5 -6
- data/spec/reek/core/singleton_method_context_spec.rb +15 -0
- data/spec/reek/core/smell_configuration_spec.rb +11 -0
- data/spec/reek/core/stop_context_spec.rb +17 -0
- data/spec/reek/examiner_spec.rb +42 -0
- data/spec/reek/smell_warning_spec.rb +82 -33
- data/spec/reek/smells/attribute_spec.rb +33 -7
- data/spec/reek/smells/boolean_parameter_spec.rb +76 -0
- data/spec/reek/smells/class_variable_spec.rb +15 -6
- data/spec/reek/smells/control_couple_spec.rb +40 -29
- data/spec/reek/smells/data_clump_spec.rb +28 -7
- data/spec/reek/smells/duplication_spec.rb +47 -41
- data/spec/reek/smells/feature_envy_spec.rb +76 -18
- data/spec/reek/smells/irresponsible_module_spec.rb +37 -0
- data/spec/reek/smells/large_class_spec.rb +91 -56
- data/spec/reek/smells/long_method_spec.rb +32 -7
- data/spec/reek/smells/long_parameter_list_spec.rb +42 -13
- data/spec/reek/smells/long_yield_list_spec.rb +65 -0
- data/spec/reek/smells/nested_iterators_spec.rb +94 -3
- data/spec/reek/smells/simulated_polymorphism_spec.rb +48 -20
- data/spec/reek/smells/smell_detector_shared.rb +28 -0
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +57 -0
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +67 -0
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +61 -0
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +124 -0
- data/spec/reek/smells/utility_function_spec.rb +45 -3
- data/spec/reek/source/code_comment_spec.rb +24 -0
- data/spec/reek/source/object_source_spec.rb +20 -0
- data/spec/reek/{adapters/source_spec.rb → source/source_code_spec.rb} +7 -8
- data/spec/reek/source/tree_dresser_spec.rb +165 -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/corrupt_config_file/dirty.rb +1 -1
- data/spec/samples/empty_config_file/dirty.rb +2 -1
- data/spec/samples/exceptions.reek +1 -1
- 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 +1 -2
- data/tasks/reek.rake +2 -2
- data/tasks/test.rake +12 -3
- metadata +81 -62
- data/README.rdoc +0 -84
- 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/reek_command.rb +0 -28
- data/lib/reek/sexp_formatter.rb +0 -10
- 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/configuration_spec.rb +0 -12
- data/spec/reek/if_context_spec.rb +0 -17
- 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/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,8 +1,7 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
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', 'cli', 'help_command')
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
include Reek
|
4
|
+
include Reek::Cli
|
6
5
|
|
7
6
|
describe HelpCommand do
|
8
7
|
before :each do
|
@@ -1,8 +1,9 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require 'reek
|
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', 'cli', 'reek_command')
|
3
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'examiner')
|
4
4
|
|
5
5
|
include Reek
|
6
|
+
include Reek::Cli
|
6
7
|
|
7
8
|
describe ReekCommand do
|
8
9
|
before :each do
|
@@ -11,8 +12,8 @@ describe ReekCommand do
|
|
11
12
|
|
12
13
|
context 'with smells' do
|
13
14
|
before :each do
|
14
|
-
|
15
|
-
@cmd = ReekCommand.new(
|
15
|
+
examiner = Examiner.new('def x(); end')
|
16
|
+
@cmd = ReekCommand.new([examiner], QuietReport, false)
|
16
17
|
end
|
17
18
|
|
18
19
|
it 'displays the correct text on the view' do
|
@@ -28,8 +29,8 @@ describe ReekCommand do
|
|
28
29
|
|
29
30
|
context 'with no smells' do
|
30
31
|
before :each do
|
31
|
-
|
32
|
-
@cmd = ReekCommand.new(
|
32
|
+
examiner = Examiner.new('def clean(); end')
|
33
|
+
@cmd = ReekCommand.new([examiner], QuietReport, false)
|
33
34
|
end
|
34
35
|
|
35
36
|
it 'displays nothing on the view' do
|
@@ -0,0 +1,26 @@
|
|
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', 'examiner')
|
3
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'cli', 'report')
|
4
|
+
|
5
|
+
include Reek
|
6
|
+
include Reek::Cli
|
7
|
+
|
8
|
+
describe ReportSection, " when empty" do
|
9
|
+
context 'empty source' do
|
10
|
+
it 'has an empty quiet_report' do
|
11
|
+
examiner = Examiner.new('')
|
12
|
+
ReportSection.new(examiner, false).quiet_report.should == ''
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with a couple of smells' do
|
17
|
+
it 'should mention every smell name' do
|
18
|
+
examiner = Examiner.new('def simple(a) a[3] end')
|
19
|
+
rpt = ReportSection.new(examiner, false)
|
20
|
+
@lines = rpt.smell_list.split("\n")
|
21
|
+
@lines.should have_at_least(2).lines
|
22
|
+
@lines[0].should match('[Utility Function]')
|
23
|
+
@lines[1].should match('[Feature Envy]')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require 'reek/version_command'
|
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', 'cli', 'version_command')
|
4
3
|
|
5
4
|
include Reek
|
5
|
+
include Reek::Cli
|
6
6
|
|
7
7
|
describe VersionCommand do
|
8
8
|
before :each do
|
@@ -0,0 +1,47 @@
|
|
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', 'cli', 'yaml_command')
|
3
|
+
|
4
|
+
include Reek
|
5
|
+
include Reek::Cli
|
6
|
+
|
7
|
+
describe YamlCommand do
|
8
|
+
before :each do
|
9
|
+
@view = mock('view', :null_object => true)
|
10
|
+
@examiner = mock('examiner')
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with no smells' do
|
14
|
+
before :each do
|
15
|
+
@examiner.should_receive(:all_smells).and_return([])
|
16
|
+
@cmd = YamlCommand.new([@examiner])
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'displays nothing on the view' do
|
20
|
+
@view.should_not_receive(:output)
|
21
|
+
@cmd.execute(@view)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'tells the view it succeeded' do
|
25
|
+
@view.should_receive(:report_success)
|
26
|
+
@cmd.execute(@view)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with smells' do
|
31
|
+
before :each do
|
32
|
+
@smell = SmellWarning.new('UncommunicativeName', "self", 27, "self", true)
|
33
|
+
@examiner.should_receive(:all_smells).and_return([@smell])
|
34
|
+
@cmd = YamlCommand.new([@examiner])
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'displays the correct text on the view' do
|
38
|
+
@view.should_receive(:output).with(/UncommunicativeName/)
|
39
|
+
@cmd.execute(@view)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'tells the view it found smells' do
|
43
|
+
@view.should_receive(:report_smells)
|
44
|
+
@cmd.execute(@view)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'method_context')
|
4
|
+
|
5
|
+
include Reek::Core
|
6
|
+
|
7
|
+
describe BlockContext do
|
8
|
+
context 'full_name' do
|
9
|
+
it "reports full context" do
|
10
|
+
bctx = BlockContext.new(StopContext.new, s(nil, nil))
|
11
|
+
bctx.full_name.should == 'block'
|
12
|
+
end
|
13
|
+
it 'uses / to connect to the class name' do
|
14
|
+
element = StopContext.new
|
15
|
+
element = ClassContext.new(element, :Fred, s(:class, :Fred))
|
16
|
+
element = BlockContext.new(element, s(:iter, nil, s(:lasgn, :x), nil))
|
17
|
+
element.full_name.should == 'Fred/block'
|
18
|
+
end
|
19
|
+
it 'uses / to connect to the module name' do
|
20
|
+
element = StopContext.new
|
21
|
+
element = ModuleContext.new(element, :Fred, s(:module, :Fred))
|
22
|
+
element = BlockContext.new(element, s(:iter, nil, s(:lasgn, :x), nil))
|
23
|
+
element.full_name.should == 'Fred/block'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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', 'class_context')
|
3
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'stop_context')
|
4
|
+
|
5
|
+
include Reek::Core
|
6
|
+
|
7
|
+
describe ClassContext do
|
8
|
+
it 'should report Long Parameter List' do
|
9
|
+
ruby = 'class Inner; def simple(arga, argb, argc, argd) f(3);true end end'
|
10
|
+
ruby.should reek_of(:LongParameterList, /Inner/, /simple/, /4 parameters/)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should report two different methods' do
|
14
|
+
src = <<EOEX
|
15
|
+
# module for test
|
16
|
+
class Fred
|
17
|
+
def simple(arga, argb, argc, argd) f(3);true end
|
18
|
+
def simply(arga, argb, argc, argd) f(3);false end
|
19
|
+
end
|
20
|
+
EOEX
|
21
|
+
|
22
|
+
src.should reek_of(:LongParameterList, /Fred/, /simple/)
|
23
|
+
src.should reek_of(:LongParameterList, /Fred/, /simply/)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should report many different methods' do
|
27
|
+
src = <<EOEX
|
28
|
+
# module for test
|
29
|
+
class Fred
|
30
|
+
def textile_bq(tag, atts, cite, content) f(3);end
|
31
|
+
def textile_p(tag, atts, cite, content) f(3);end
|
32
|
+
def textile_fn_(tag, num, atts, cite, content) f(3);end
|
33
|
+
def textile_popup_help(name, windowW, windowH) f(3);end
|
34
|
+
end
|
35
|
+
EOEX
|
36
|
+
|
37
|
+
src.should reek_of(:LongParameterList, /Fred/, /textile_bq/)
|
38
|
+
src.should reek_of(:LongParameterList, /Fred/, /textile_fn_/)
|
39
|
+
src.should reek_of(:LongParameterList, /Fred/, /textile_p/)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ClassContext do
|
44
|
+
it 'does not report empty class in another module' do
|
45
|
+
'# module for test
|
46
|
+
class Treetop::Runtime::SyntaxNode; end'.should_not reek
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'deals with :: scoped names' do
|
50
|
+
element = ClassContext.create(StopContext.new, [:colon2, [:colon2, [:const, :Treetop], :Runtime], :SyntaxNode])
|
51
|
+
element.num_methods.should == 0
|
52
|
+
end
|
53
|
+
end
|
@@ -1,19 +1,17 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
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
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'class_context')
|
4
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'method_context')
|
5
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'module_context')
|
6
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'stop_context')
|
2
7
|
|
3
|
-
|
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
|
8
|
+
include Reek::Core
|
11
9
|
|
12
10
|
describe CodeContext do
|
13
11
|
context 'full_name' do
|
14
12
|
it "reports the full context" do
|
15
13
|
element = StopContext.new
|
16
|
-
element = ModuleContext.new(element,
|
14
|
+
element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
|
17
15
|
element = ClassContext.new(element, [0, :klass], s())
|
18
16
|
element = MethodContext.new(element, [0, :bad])
|
19
17
|
element = BlockContext.new(element, s(nil, nil))
|
@@ -22,13 +20,6 @@ describe CodeContext do
|
|
22
20
|
element.full_name.should match(/mod/)
|
23
21
|
end
|
24
22
|
|
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
23
|
it 'reports the method name via nested blocks' do
|
33
24
|
element1 = StopContext.new
|
34
25
|
element2 = MethodContext.new(element1, [0, :bad])
|
@@ -39,21 +30,8 @@ describe CodeContext do
|
|
39
30
|
outer_name = 'randomstring'
|
40
31
|
outer = mock('outer')
|
41
32
|
outer.should_receive(:full_name).and_return(outer_name)
|
42
|
-
ifc =
|
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))
|
33
|
+
ifc = BlockContext.new(outer, s(:if, s()))
|
34
|
+
ifc.full_name.should == "#{outer_name}/block"
|
57
35
|
end
|
58
36
|
end
|
59
37
|
|
@@ -61,7 +39,7 @@ describe CodeContext do
|
|
61
39
|
it 'should pass unknown method calls down the stack' do
|
62
40
|
stop = StopContext.new
|
63
41
|
def stop.bananas(arg1, arg2) arg1 + arg2 + 43 end
|
64
|
-
element = ModuleContext.new(stop,
|
42
|
+
element = ModuleContext.new(stop, 'mod', s(:module, :mod, nil))
|
65
43
|
class_element = ClassContext.new(element, [0, :klass], s())
|
66
44
|
element = MethodContext.new(class_element, [0, :bad])
|
67
45
|
element = BlockContext.new(element, s(nil, nil))
|
@@ -72,19 +50,19 @@ describe CodeContext do
|
|
72
50
|
context 'name matching' do
|
73
51
|
it 'should recognise itself in a collection of names' do
|
74
52
|
element = StopContext.new
|
75
|
-
element = ModuleContext.new(element,
|
53
|
+
element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
|
76
54
|
element.matches?(['banana', 'mod']).should == true
|
77
55
|
end
|
78
56
|
|
79
57
|
it 'should recognise itself in a collection of REs' do
|
80
58
|
element = StopContext.new
|
81
|
-
element = ModuleContext.new(element,
|
59
|
+
element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
|
82
60
|
element.matches?([/banana/, /mod/]).should == true
|
83
61
|
end
|
84
62
|
|
85
63
|
it 'should recognise its fq name in a collection of names' do
|
86
64
|
element = StopContext.new
|
87
|
-
element = ModuleContext.new(element,
|
65
|
+
element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
|
88
66
|
element = ClassContext.create(element, s(:class, :klass))
|
89
67
|
element.matches?(['banana', 'mod']).should == true
|
90
68
|
element.matches?(['banana', 'mod::klass']).should == true
|
@@ -92,7 +70,7 @@ describe CodeContext do
|
|
92
70
|
|
93
71
|
it 'should recognise its fq name in a collection of names' do
|
94
72
|
element = StopContext.new
|
95
|
-
element = ModuleContext.new(element,
|
73
|
+
element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
|
96
74
|
element = ClassContext.create(element, s(:class, :klass))
|
97
75
|
element.matches?([/banana/, /mod/]).should == true
|
98
76
|
element.matches?([/banana/, /mod::klass/]).should == true
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
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', 'code_parser')
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
include Reek
|
4
|
+
include Reek::Core
|
6
5
|
|
7
6
|
describe CodeParser, "with no method definitions" do
|
8
7
|
it 'reports no problems for empty source code' do
|
9
8
|
''.should_not reek
|
10
9
|
end
|
11
10
|
it 'reports no problems for empty class' do
|
12
|
-
'class
|
11
|
+
'# clean class for testing purposes
|
12
|
+
class Fred; end'.should_not reek
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -1,9 +1,5 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require 'reek/sniffer'
|
4
|
-
require 'yaml'
|
5
|
-
|
6
|
-
include Reek
|
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', 'sniffer')
|
7
3
|
|
8
4
|
describe Hash do
|
9
5
|
before :each do
|
@@ -1,8 +1,7 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
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', 'masking_collection')
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
include Reek
|
4
|
+
include Reek::Core
|
6
5
|
|
7
6
|
describe MaskingCollection do
|
8
7
|
before(:each) do
|
@@ -1,9 +1,8 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
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', 'method_context')
|
3
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'stop_context')
|
2
4
|
|
3
|
-
|
4
|
-
require 'reek/stop_context'
|
5
|
-
|
6
|
-
include Reek
|
5
|
+
include Reek::Core
|
7
6
|
|
8
7
|
describe MethodContext, 'matching' do
|
9
8
|
before :each do
|
@@ -24,8 +23,8 @@ end
|
|
24
23
|
describe MethodContext, 'matching fq names' do
|
25
24
|
before :each do
|
26
25
|
element = StopContext.new
|
27
|
-
element = ModuleContext.new(element,
|
28
|
-
element = ClassContext.new(element,
|
26
|
+
element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
|
27
|
+
element = ClassContext.new(element, 'klass', s())
|
29
28
|
@element = MethodContext.new(element, s(0, :meth))
|
30
29
|
end
|
31
30
|
|
@@ -0,0 +1,42 @@
|
|
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', 'module_context')
|
3
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'stop_context')
|
4
|
+
|
5
|
+
include Reek::Core
|
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(:UncommunicativeParameterName, /x/, /simple/, /Fred/)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should not report module with empty class' do
|
13
|
+
'# module for test
|
14
|
+
module Fred
|
15
|
+
# module for test
|
16
|
+
class Jim; end; end'.should_not reek
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ModuleContext do
|
21
|
+
it 'should recognise global constant' do
|
22
|
+
'# module for test
|
23
|
+
module ::Global
|
24
|
+
# module for test
|
25
|
+
class Inside; end; end'.should_not reek
|
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
|
+
end
|
@@ -1,8 +1,7 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
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', 'object_refs')
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
include Reek
|
4
|
+
include Reek::Core
|
6
5
|
|
7
6
|
describe ObjectRefs, 'when empty' do
|
8
7
|
before(:each) do
|
@@ -27,7 +26,7 @@ describe ObjectRefs, 'with no refs to self' do
|
|
27
26
|
end
|
28
27
|
|
29
28
|
it 'should report :a as the max' do
|
30
|
-
@refs.max_keys.should ==
|
29
|
+
@refs.max_keys.should == {'a' => 2}
|
31
30
|
end
|
32
31
|
|
33
32
|
it 'should not report self as the max' do
|
@@ -75,7 +74,7 @@ describe ObjectRefs, 'with many refs to self' do
|
|
75
74
|
end
|
76
75
|
|
77
76
|
it 'should report self among the max' do
|
78
|
-
@refs.max_keys.should ==
|
77
|
+
@refs.max_keys.should == {Sexp.from_array([:lit, :self]) => 4}
|
79
78
|
end
|
80
79
|
|
81
80
|
it 'should report self as the max' do
|