reek 3.2.1 → 3.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Rakefile +0 -1
- data/config/defaults.reek +1 -1
- data/features/samples.feature +17 -16
- data/lib/reek.rb +0 -1
- data/lib/reek/ast/ast_node_class_map.rb +5 -1
- data/lib/reek/ast/node.rb +10 -3
- data/lib/reek/ast/object_refs.rb +11 -5
- data/lib/reek/ast/reference_collector.rb +6 -2
- data/lib/reek/ast/sexp_extensions.rb +42 -1
- data/lib/reek/ast/sexp_formatter.rb +2 -1
- data/lib/reek/cli/application.rb +12 -9
- data/lib/reek/cli/command.rb +6 -0
- data/lib/reek/cli/input.rb +4 -4
- data/lib/reek/cli/option_interpreter.rb +11 -7
- data/lib/reek/cli/options.rb +42 -40
- data/lib/reek/cli/reek_command.rb +3 -3
- data/lib/reek/cli/silencer.rb +12 -3
- data/lib/reek/cli/warning_collector.rb +8 -3
- data/lib/reek/code_comment.rb +6 -1
- data/lib/reek/configuration/app_configuration.rb +65 -100
- data/lib/reek/configuration/configuration_file_finder.rb +4 -13
- data/lib/reek/configuration/configuration_validator.rb +35 -0
- data/lib/reek/configuration/default_directive.rb +12 -0
- data/lib/reek/configuration/directory_directives.rb +54 -0
- data/lib/reek/configuration/excluded_paths.rb +18 -0
- data/lib/reek/context/code_context.rb +19 -17
- data/lib/reek/examiner.rb +9 -7
- data/lib/reek/rake/task.rb +12 -22
- data/lib/reek/report/formatter.rb +6 -1
- data/lib/reek/report/report.rb +22 -13
- data/lib/reek/smells/attribute.rb +6 -53
- data/lib/reek/smells/control_parameter.rb +21 -13
- data/lib/reek/smells/data_clump.rb +17 -9
- data/lib/reek/smells/duplicate_method_call.rb +12 -6
- data/lib/reek/smells/long_parameter_list.rb +2 -2
- data/lib/reek/smells/long_yield_list.rb +4 -4
- data/lib/reek/smells/nested_iterators.rb +4 -2
- data/lib/reek/smells/nil_check.rb +6 -2
- data/lib/reek/smells/repeated_conditional.rb +3 -3
- data/lib/reek/smells/smell_configuration.rb +17 -7
- data/lib/reek/smells/smell_detector.rb +24 -11
- data/lib/reek/smells/smell_repository.rb +1 -1
- data/lib/reek/smells/smell_warning.rb +6 -6
- data/lib/reek/smells/too_many_instance_variables.rb +2 -2
- data/lib/reek/smells/too_many_methods.rb +4 -4
- data/lib/reek/smells/too_many_statements.rb +4 -4
- data/lib/reek/smells/uncommunicative_method_name.rb +5 -5
- data/lib/reek/smells/uncommunicative_module_name.rb +6 -6
- data/lib/reek/smells/uncommunicative_parameter_name.rb +8 -4
- data/lib/reek/smells/uncommunicative_variable_name.rb +9 -5
- data/lib/reek/smells/utility_function.rb +1 -1
- data/lib/reek/source/source_code.rb +5 -1
- data/lib/reek/source/source_locator.rb +3 -2
- data/lib/reek/spec.rb +3 -3
- data/lib/reek/spec/should_reek.rb +10 -5
- data/lib/reek/spec/should_reek_of.rb +9 -6
- data/lib/reek/spec/should_reek_only_of.rb +13 -8
- data/lib/reek/tree_dresser.rb +6 -2
- data/lib/reek/tree_walker.rb +40 -32
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +1 -1
- data/spec/reek/ast/node_spec.rb +1 -2
- data/spec/reek/ast/object_refs_spec.rb +40 -42
- data/spec/reek/ast/sexp_extensions_spec.rb +98 -104
- data/spec/reek/cli/warning_collector_spec.rb +8 -12
- data/spec/reek/code_comment_spec.rb +3 -5
- data/spec/reek/configuration/app_configuration_spec.rb +43 -57
- data/spec/reek/configuration/configuration_file_finder_spec.rb +5 -7
- data/spec/reek/configuration/default_directive_spec.rb +13 -0
- data/spec/reek/configuration/directory_directives_spec.rb +89 -0
- data/spec/reek/configuration/excluded_paths_spec.rb +30 -0
- data/spec/reek/context/code_context_spec.rb +63 -62
- data/spec/reek/context/method_context_spec.rb +8 -12
- data/spec/reek/context/module_context_spec.rb +1 -1
- data/spec/reek/context/root_context_spec.rb +3 -7
- data/spec/reek/examiner_spec.rb +14 -25
- data/spec/reek/smells/attribute_spec.rb +2 -4
- data/spec/reek/smells/boolean_parameter_spec.rb +5 -7
- data/spec/reek/smells/class_variable_spec.rb +29 -44
- data/spec/reek/smells/control_parameter_spec.rb +7 -9
- data/spec/reek/smells/data_clump_spec.rb +25 -32
- data/spec/reek/smells/duplicate_method_call_spec.rb +8 -7
- data/spec/reek/smells/feature_envy_spec.rb +16 -17
- data/spec/reek/smells/irresponsible_module_spec.rb +2 -4
- data/spec/reek/smells/long_parameter_list_spec.rb +6 -9
- data/spec/reek/smells/long_yield_list_spec.rb +6 -9
- data/spec/reek/smells/nested_iterators_spec.rb +14 -16
- data/spec/reek/smells/repeated_conditional_spec.rb +25 -25
- data/spec/reek/smells/smell_configuration_spec.rb +32 -27
- data/spec/reek/smells/smell_detector_shared.rb +12 -13
- data/spec/reek/smells/smell_warning_spec.rb +54 -58
- data/spec/reek/smells/too_many_instance_variables_spec.rb +9 -9
- data/spec/reek/smells/too_many_methods_spec.rb +13 -14
- data/spec/reek/smells/too_many_statements_spec.rb +8 -10
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +8 -9
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +12 -13
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +7 -10
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +16 -20
- data/spec/reek/smells/utility_function_spec.rb +11 -15
- data/spec/reek/source/source_code_spec.rb +6 -11
- data/spec/reek/spec/should_reek_of_spec.rb +19 -30
- data/spec/reek/spec/should_reek_only_of_spec.rb +28 -34
- data/spec/reek/tree_walker_spec.rb +14 -2
- data/spec/spec_helper.rb +2 -3
- data/tasks/test.rake +0 -5
- metadata +10 -6
- data/docs/Configuration-Files.md +0 -49
- data/spec/gem/updates_spec.rb +0 -25
- data/spec/gem/yard_spec.rb +0 -11
- data/spec/reek/smells/behaves_like_variable_detector.rb +0 -39
@@ -3,39 +3,38 @@ require_relative '../../../lib/reek/smells/smell_configuration'
|
|
3
3
|
|
4
4
|
RSpec.shared_examples_for 'SmellDetector' do
|
5
5
|
context 'exception matching follows the context' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
6
|
+
let(:ctx) { double('context') }
|
7
|
+
|
8
|
+
before { allow(ctx).to receive(:config_for).and_return({}) }
|
10
9
|
|
11
10
|
it 'when false' do
|
12
|
-
expect(
|
13
|
-
expect(
|
11
|
+
expect(ctx).to receive(:matches?).at_least(:once).and_return(false)
|
12
|
+
expect(detector.exception?(ctx)).to eq(false)
|
14
13
|
end
|
15
14
|
|
16
15
|
it 'when true' do
|
17
|
-
expect(
|
18
|
-
expect(
|
16
|
+
expect(ctx).to receive(:matches?).at_least(:once).and_return(true)
|
17
|
+
expect(detector.exception?(ctx)).to eq(true)
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
21
|
context 'configuration' do
|
23
22
|
it 'becomes disabled when disabled' do
|
24
23
|
enabled_key = Reek::Smells::SmellConfiguration::ENABLED_KEY
|
25
|
-
|
26
|
-
expect(
|
24
|
+
detector.configure_with(enabled_key => false)
|
25
|
+
expect(detector).not_to be_enabled
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
30
|
RSpec.shared_examples_for 'common fields set correctly' do
|
32
31
|
it 'reports the source' do
|
33
|
-
expect(
|
32
|
+
expect(warning.source).to eq(source_name)
|
34
33
|
end
|
35
34
|
it 'reports the smell class' do
|
36
|
-
expect(
|
35
|
+
expect(warning.smell_category).to eq(detector.smell_category)
|
37
36
|
end
|
38
37
|
it 'reports the smell sub class' do
|
39
|
-
expect(
|
38
|
+
expect(warning.smell_type).to eq(detector.smell_type)
|
40
39
|
end
|
41
40
|
end
|
@@ -9,78 +9,77 @@ RSpec.describe Reek::Smells::SmellWarning do
|
|
9
9
|
context 'sort order' do
|
10
10
|
shared_examples_for 'first sorts ahead of second' do
|
11
11
|
it 'hash differently' do
|
12
|
-
expect(
|
12
|
+
expect(first.hash).not_to eq(second.hash)
|
13
13
|
end
|
14
14
|
it 'are not equal' do
|
15
|
-
expect(
|
15
|
+
expect(first).not_to eq(second)
|
16
16
|
end
|
17
17
|
it 'sort correctly' do
|
18
|
-
expect(
|
18
|
+
expect(first <=> second).to be < 0
|
19
19
|
end
|
20
20
|
it 'does not match using eql?' do
|
21
|
-
expect(
|
22
|
-
expect(
|
21
|
+
expect(first).not_to eql(second)
|
22
|
+
expect(second).not_to eql(first)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'smells differing only by detector' do
|
27
|
-
|
28
|
-
|
29
|
-
@second = build(:smell_warning, smell_detector: feature_envy_detector)
|
30
|
-
end
|
27
|
+
let(:first) { build(:smell_warning, smell_detector: duplication_detector) }
|
28
|
+
let(:second) { build(:smell_warning, smell_detector: feature_envy_detector) }
|
31
29
|
|
32
30
|
it_should_behave_like 'first sorts ahead of second'
|
33
31
|
end
|
34
32
|
|
35
33
|
context 'smells differing only by context' do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
@second = build(:smell_warning, smell_detector: duplication_detector,
|
40
|
-
context: 'second')
|
34
|
+
let(:first) { build(:smell_warning, smell_detector: duplication_detector, context: 'first') }
|
35
|
+
let(:second) do
|
36
|
+
build(:smell_warning, smell_detector: duplication_detector, context: 'second')
|
41
37
|
end
|
42
38
|
|
43
39
|
it_should_behave_like 'first sorts ahead of second'
|
44
40
|
end
|
45
41
|
|
46
42
|
context 'smells differing only by message' do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
43
|
+
let(:first) do
|
44
|
+
build(:smell_warning, smell_detector: duplication_detector,
|
45
|
+
context: 'ctx', message: 'first message')
|
46
|
+
end
|
47
|
+
let(:second) do
|
48
|
+
build(:smell_warning, smell_detector: duplication_detector,
|
49
|
+
context: 'ctx', message: 'second message')
|
54
50
|
end
|
55
51
|
|
56
52
|
it_should_behave_like 'first sorts ahead of second'
|
57
53
|
end
|
58
54
|
|
59
55
|
context 'message takes precedence over smell name' do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
56
|
+
let(:first) do
|
57
|
+
build(:smell_warning, smell_detector: utility_function_detector, message: 'first message')
|
58
|
+
end
|
59
|
+
let(:second) do
|
60
|
+
build(:smell_warning, smell_detector: feature_envy_detector, message: 'second message')
|
65
61
|
end
|
66
62
|
|
67
63
|
it_should_behave_like 'first sorts ahead of second'
|
68
64
|
end
|
69
65
|
|
70
66
|
context 'smells differing everywhere' do
|
71
|
-
|
67
|
+
let(:first) do
|
72
68
|
uncommunicative_name_detector = build(:smell_detector,
|
73
69
|
smell_type: 'UncommunicativeVariableName',
|
74
70
|
source: true)
|
71
|
+
build(:smell_warning, smell_detector: uncommunicative_name_detector,
|
72
|
+
context: 'Dirty',
|
73
|
+
message: "has the variable name '@s'")
|
74
|
+
end
|
75
|
+
|
76
|
+
let(:second) do
|
75
77
|
duplication_detector = build(:smell_detector,
|
76
78
|
smell_type: 'DuplicateMethodCall',
|
77
79
|
source: false)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
@second = build(:smell_warning, smell_detector: duplication_detector,
|
82
|
-
context: 'Dirty#a',
|
83
|
-
message: 'calls @s.title twice')
|
80
|
+
build(:smell_warning, smell_detector: duplication_detector,
|
81
|
+
context: 'Dirty#a',
|
82
|
+
message: 'calls @s.title twice')
|
84
83
|
end
|
85
84
|
|
86
85
|
it_should_behave_like 'first sorts ahead of second'
|
@@ -88,53 +87,50 @@ RSpec.describe Reek::Smells::SmellWarning do
|
|
88
87
|
end
|
89
88
|
|
90
89
|
context '#yaml_hash' do
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
@context_name = 'Module::Class#method/block'
|
96
|
-
# Use a random string and a random bool
|
97
|
-
end
|
90
|
+
let(:class) { 'FeatureEnvy' }
|
91
|
+
let(:context_name) { 'Module::Class#method/block' }
|
92
|
+
let(:lines) { [24, 513] }
|
93
|
+
let(:message) { 'test message' }
|
98
94
|
|
99
95
|
shared_examples_for 'common fields' do
|
100
96
|
it 'includes the smell type' do
|
101
|
-
expect(
|
97
|
+
expect(yaml['smell_type']).to eq 'FeatureEnvy'
|
102
98
|
end
|
103
99
|
it 'includes the context' do
|
104
|
-
expect(
|
100
|
+
expect(yaml['context']).to eq context_name
|
105
101
|
end
|
106
102
|
it 'includes the message' do
|
107
|
-
expect(
|
103
|
+
expect(yaml['message']).to eq message
|
108
104
|
end
|
109
105
|
it 'includes the line numbers' do
|
110
|
-
expect(
|
106
|
+
expect(yaml['lines']).to match_array lines
|
111
107
|
end
|
112
108
|
end
|
113
109
|
|
114
110
|
context 'with all details specified' do
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
111
|
+
let(:detector) { Reek::Smells::FeatureEnvy.new source }
|
112
|
+
let(:parameters) { { 'one' => 34, 'two' => 'second' } }
|
113
|
+
let(:smell_type) { 'FeatureEnvy' }
|
114
|
+
let(:source) { 'a/ruby/source/file.rb' }
|
115
|
+
let(:yaml) do
|
116
|
+
warning = Reek::Smells::SmellWarning.new(detector, context: context_name,
|
117
|
+
lines: lines,
|
118
|
+
message: message,
|
119
|
+
parameters: parameters)
|
120
|
+
warning.yaml_hash
|
125
121
|
end
|
126
122
|
|
127
123
|
it_should_behave_like 'common fields'
|
128
124
|
|
129
125
|
it 'includes the smell type' do
|
130
|
-
expect(
|
126
|
+
expect(yaml['smell_type']).to eq smell_type
|
131
127
|
end
|
132
128
|
it 'includes the source' do
|
133
|
-
expect(
|
129
|
+
expect(yaml['source']).to eq source
|
134
130
|
end
|
135
131
|
it 'includes the parameters' do
|
136
|
-
|
137
|
-
expect(
|
132
|
+
parameters.each do |key, value|
|
133
|
+
expect(yaml[key]).to eq value
|
138
134
|
end
|
139
135
|
end
|
140
136
|
end
|
@@ -3,9 +3,9 @@ require_relative '../../../lib/reek/smells/too_many_instance_variables'
|
|
3
3
|
require_relative 'smell_detector_shared'
|
4
4
|
|
5
5
|
RSpec.describe Reek::Smells::TooManyInstanceVariables do
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
let(:source_name) { 'dummy_source' }
|
7
|
+
let(:detector) do
|
8
|
+
build(:smell_detector, smell_type: :TooManyInstanceVariables, source: source_name)
|
9
9
|
end
|
10
10
|
|
11
11
|
it_should_behave_like 'SmellDetector'
|
@@ -87,11 +87,11 @@ RSpec.describe Reek::Smells::TooManyInstanceVariables do
|
|
87
87
|
end
|
88
88
|
EOS
|
89
89
|
ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
|
90
|
-
|
91
|
-
expect(
|
92
|
-
expect(
|
93
|
-
expect(
|
94
|
-
expect(
|
95
|
-
expect(
|
90
|
+
warning = detector.examine_context(ctx)[0]
|
91
|
+
expect(warning.source).to eq(source_name)
|
92
|
+
expect(warning.smell_category).to eq(Reek::Smells::TooManyInstanceVariables.smell_category)
|
93
|
+
expect(warning.smell_type).to eq(Reek::Smells::TooManyInstanceVariables.smell_type)
|
94
|
+
expect(warning.parameters[:count]).to eq(too_many_ivars)
|
95
|
+
expect(warning.lines).to eq([2])
|
96
96
|
end
|
97
97
|
end
|
@@ -3,11 +3,10 @@ require_relative '../../../lib/reek/smells/too_many_methods'
|
|
3
3
|
require_relative 'smell_detector_shared'
|
4
4
|
|
5
5
|
RSpec.describe Reek::Smells::TooManyMethods do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
6
|
+
let(:detector) { described_class.new(source_name) }
|
7
|
+
let(:source_name) { 'dummy_name' }
|
8
|
+
|
9
|
+
before(:each) { detector.configure_with 'max_methods' => 2 }
|
11
10
|
|
12
11
|
it_should_behave_like 'SmellDetector'
|
13
12
|
|
@@ -21,7 +20,7 @@ RSpec.describe Reek::Smells::TooManyMethods do
|
|
21
20
|
EOS
|
22
21
|
syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
|
23
22
|
ctx = Reek::Context::ModuleContext.new(nil, syntax_tree)
|
24
|
-
expect(
|
23
|
+
expect(detector.examine_context(ctx)).to be_empty
|
25
24
|
end
|
26
25
|
|
27
26
|
it 'should report if we exceed max_methods' do
|
@@ -34,7 +33,7 @@ RSpec.describe Reek::Smells::TooManyMethods do
|
|
34
33
|
EOS
|
35
34
|
syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
|
36
35
|
ctx = Reek::Context::ModuleContext.new(nil, syntax_tree)
|
37
|
-
smells =
|
36
|
+
smells = detector.examine_context(ctx)
|
38
37
|
expect(smells.length).to eq(1)
|
39
38
|
expect(smells[0].smell_type).to eq(described_class.smell_type)
|
40
39
|
expect(smells[0].parameters[:count]).to eq(3)
|
@@ -57,7 +56,7 @@ RSpec.describe Reek::Smells::TooManyMethods do
|
|
57
56
|
EOS
|
58
57
|
syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
|
59
58
|
ctx = Reek::Context::ModuleContext.new(nil, syntax_tree)
|
60
|
-
expect(
|
59
|
+
expect(detector.examine_context(ctx)).to be_empty
|
61
60
|
end
|
62
61
|
end
|
63
62
|
|
@@ -72,11 +71,11 @@ RSpec.describe Reek::Smells::TooManyMethods do
|
|
72
71
|
|
73
72
|
syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
|
74
73
|
ctx = Reek::Context::ModuleContext.new(nil, syntax_tree)
|
75
|
-
|
76
|
-
expect(
|
77
|
-
expect(
|
78
|
-
expect(
|
79
|
-
expect(
|
80
|
-
expect(
|
74
|
+
warning = detector.examine_context(ctx)[0]
|
75
|
+
expect(warning.source).to eq(source_name)
|
76
|
+
expect(warning.smell_category).to eq(described_class.smell_category)
|
77
|
+
expect(warning.smell_type).to eq(described_class.smell_type)
|
78
|
+
expect(warning.parameters[:count]).to eq(3)
|
79
|
+
expect(warning.lines).to eq([1])
|
81
80
|
end
|
82
81
|
end
|
@@ -41,31 +41,29 @@ RSpec.describe Reek::Smells::TooManyStatements do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
RSpec.describe Reek::Smells::TooManyStatements do
|
44
|
-
|
45
|
-
@detector = build(:smell_detector, smell_type: :TooManyStatements, source: 'source_name')
|
46
|
-
end
|
44
|
+
let(:detector) { build(:smell_detector, smell_type: :TooManyStatements, source: 'source_name') }
|
47
45
|
|
48
46
|
it_should_behave_like 'SmellDetector'
|
49
47
|
|
50
48
|
context 'when the method has 30 statements' do
|
51
|
-
|
52
|
-
|
49
|
+
let(:num_statements) { 30 }
|
50
|
+
let(:smells) do
|
53
51
|
ctx = double('method_context').as_null_object
|
54
|
-
expect(ctx).to receive(:num_statements).and_return(
|
52
|
+
expect(ctx).to receive(:num_statements).and_return(num_statements)
|
55
53
|
expect(ctx).to receive(:config_for).with(described_class).and_return({})
|
56
|
-
|
54
|
+
detector.examine_context(ctx)
|
57
55
|
end
|
58
56
|
|
59
57
|
it 'reports only 1 smell' do
|
60
|
-
expect(
|
58
|
+
expect(smells.length).to eq(1)
|
61
59
|
end
|
62
60
|
|
63
61
|
it 'reports the number of statements' do
|
64
|
-
expect(
|
62
|
+
expect(smells[0].parameters[:count]).to eq(num_statements)
|
65
63
|
end
|
66
64
|
|
67
65
|
it 'reports the correct smell sub class' do
|
68
|
-
expect(
|
66
|
+
expect(smells[0].smell_type).to eq(described_class.smell_type)
|
69
67
|
end
|
70
68
|
end
|
71
69
|
end
|
@@ -3,9 +3,9 @@ require_relative '../../../lib/reek/smells/uncommunicative_method_name'
|
|
3
3
|
require_relative 'smell_detector_shared'
|
4
4
|
|
5
5
|
RSpec.describe Reek::Smells::UncommunicativeMethodName do
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
let(:source_name) { 'dummy_source' }
|
7
|
+
let(:detector) do
|
8
|
+
build(:smell_detector, smell_type: :UncommunicativeMethodName, source: source_name)
|
9
9
|
end
|
10
10
|
|
11
11
|
it_should_behave_like 'SmellDetector'
|
@@ -19,19 +19,18 @@ RSpec.describe Reek::Smells::UncommunicativeMethodName do
|
|
19
19
|
|
20
20
|
['x', 'x2', 'method2'].each do |method_name|
|
21
21
|
context 'with a bad name' do
|
22
|
-
|
22
|
+
let(:warning) do
|
23
23
|
src = "def #{method_name}; end"
|
24
24
|
ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
|
25
|
-
|
26
|
-
@warning = smells[0]
|
25
|
+
detector.examine_context(ctx).first
|
27
26
|
end
|
28
27
|
|
29
28
|
it_should_behave_like 'common fields set correctly'
|
30
29
|
|
31
30
|
it 'reports the correct values' do
|
32
|
-
expect(
|
33
|
-
expect(
|
34
|
-
expect(
|
31
|
+
expect(warning.parameters[:name]).to eq(method_name)
|
32
|
+
expect(warning.lines).to eq([1])
|
33
|
+
expect(warning.context).to eq(method_name)
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
@@ -4,9 +4,9 @@ require_relative 'smell_detector_shared'
|
|
4
4
|
require_relative '../../../lib/reek/context/code_context'
|
5
5
|
|
6
6
|
RSpec.describe Reek::Smells::UncommunicativeModuleName do
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
let(:source_name) { 'dummy_source' }
|
8
|
+
let(:detector) do
|
9
|
+
build(:smell_detector, smell_type: :UncommunicativeModuleName, source: source_name)
|
10
10
|
end
|
11
11
|
|
12
12
|
it_should_behave_like 'SmellDetector'
|
@@ -17,21 +17,21 @@ RSpec.describe Reek::Smells::UncommunicativeModuleName do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'reports one-letter name' do
|
20
|
-
expect("#{type} X; end").to reek_of(:UncommunicativeModuleName,
|
20
|
+
expect("#{type} X; end").to reek_of(:UncommunicativeModuleName, name: 'X')
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'reports name of the form "x2"' do
|
24
|
-
expect("#{type} X2; end").to reek_of(:UncommunicativeModuleName,
|
24
|
+
expect("#{type} X2; end").to reek_of(:UncommunicativeModuleName, name: 'X2')
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'reports long name ending in a number' do
|
28
|
-
expect("#{type} Printer2; end").to reek_of(:UncommunicativeModuleName,
|
28
|
+
expect("#{type} Printer2; end").to reek_of(:UncommunicativeModuleName, name: 'Printer2')
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'reports a bad scoped name' do
|
32
32
|
src = "#{type} Foo::X; end"
|
33
33
|
ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
|
34
|
-
smells =
|
34
|
+
smells = detector.examine_context(ctx)
|
35
35
|
expect(smells.length).to eq(1)
|
36
36
|
expect(smells[0].smell_category).to eq(Reek::Smells::UncommunicativeModuleName.smell_category)
|
37
37
|
expect(smells[0].smell_type).to eq(Reek::Smells::UncommunicativeModuleName.smell_type)
|
@@ -44,23 +44,22 @@ RSpec.describe Reek::Smells::UncommunicativeModuleName do
|
|
44
44
|
it 'accepts Inline::C' do
|
45
45
|
src = 'module Inline::C; end'
|
46
46
|
ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
|
47
|
-
expect(
|
47
|
+
expect(detector.examine_context(ctx)).to be_empty
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
context 'looking at the YAML' do
|
52
|
-
|
52
|
+
let(:warning) do
|
53
53
|
src = 'module Printer2; end'
|
54
54
|
ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
|
55
|
-
|
56
|
-
@warning = smells[0]
|
55
|
+
detector.examine_context(ctx).first
|
57
56
|
end
|
58
57
|
|
59
58
|
it_should_behave_like 'common fields set correctly'
|
60
59
|
|
61
60
|
it 'reports the correct values' do
|
62
|
-
expect(
|
63
|
-
expect(
|
61
|
+
expect(warning.parameters[:name]).to eq('Printer2')
|
62
|
+
expect(warning.lines).to eq([1])
|
64
63
|
end
|
65
64
|
end
|
66
65
|
end
|