reek 1.3.8 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +11 -0
- data/README.md +22 -14
- data/Rakefile +2 -15
- data/assets/html_output.html.erb +103 -0
- data/features/command_line_interface/options.feature +3 -0
- data/features/command_line_interface/smell_selection.feature +19 -0
- data/features/rake_task/rake_task.feature +1 -1
- data/features/reports/reports.feature +16 -0
- data/features/reports/yaml.feature +26 -23
- data/features/samples.feature +2 -1
- data/features/step_definitions/reek_steps.rb +15 -15
- data/features/support/env.rb +7 -9
- data/lib/reek/cli/application.rb +2 -4
- data/lib/reek/cli/command.rb +12 -0
- data/lib/reek/cli/help_command.rb +3 -6
- data/lib/reek/cli/options.rb +147 -0
- data/lib/reek/cli/reek_command.rb +18 -14
- data/lib/reek/cli/report/formatter.rb +56 -0
- data/lib/reek/cli/report/report.rb +106 -0
- data/lib/reek/cli/report/strategy.rb +63 -0
- data/lib/reek/cli/version_command.rb +3 -6
- data/lib/reek/config_file_exception.rb +0 -1
- data/lib/reek/core/code_context.rb +1 -3
- data/lib/reek/core/code_parser.rb +13 -12
- data/lib/reek/core/method_context.rb +13 -2
- data/lib/reek/core/module_context.rb +0 -4
- data/lib/reek/core/object_refs.rb +2 -3
- data/lib/reek/core/singleton_method_context.rb +0 -2
- data/lib/reek/core/smell_configuration.rb +3 -5
- data/lib/reek/core/smell_repository.rb +7 -8
- data/lib/reek/core/sniffer.rb +4 -10
- data/lib/reek/core/stop_context.rb +2 -4
- data/lib/reek/core/warning_collector.rb +0 -1
- data/lib/reek/examiner.rb +19 -17
- data/lib/reek/rake/task.rb +7 -10
- data/lib/reek/smell_warning.rb +4 -8
- data/lib/reek/smells.rb +0 -1
- data/lib/reek/smells/attribute.rb +8 -11
- data/lib/reek/smells/boolean_parameter.rb +5 -7
- data/lib/reek/smells/class_variable.rb +6 -7
- data/lib/reek/smells/control_parameter.rb +78 -45
- data/lib/reek/smells/data_clump.rb +13 -16
- data/lib/reek/smells/duplicate_method_call.rb +13 -11
- data/lib/reek/smells/feature_envy.rb +6 -7
- data/lib/reek/smells/irresponsible_module.rb +4 -6
- data/lib/reek/smells/long_parameter_list.rb +5 -7
- data/lib/reek/smells/long_yield_list.rb +2 -4
- data/lib/reek/smells/nested_iterators.rb +12 -22
- data/lib/reek/smells/nil_check.rb +35 -46
- data/lib/reek/smells/prima_donna_method.rb +24 -16
- data/lib/reek/smells/repeated_conditional.rb +8 -10
- data/lib/reek/smells/smell_detector.rb +9 -7
- data/lib/reek/smells/too_many_instance_variables.rb +7 -9
- data/lib/reek/smells/too_many_methods.rb +6 -8
- data/lib/reek/smells/too_many_statements.rb +4 -6
- data/lib/reek/smells/uncommunicative_method_name.rb +5 -7
- data/lib/reek/smells/uncommunicative_module_name.rb +5 -7
- data/lib/reek/smells/uncommunicative_parameter_name.rb +7 -9
- data/lib/reek/smells/uncommunicative_variable_name.rb +15 -18
- data/lib/reek/smells/unused_parameters.rb +5 -45
- data/lib/reek/smells/utility_function.rb +9 -10
- data/lib/reek/source.rb +0 -1
- data/lib/reek/source/code_comment.rb +7 -8
- data/lib/reek/source/config_file.rb +2 -4
- data/lib/reek/source/core_extras.rb +1 -1
- data/lib/reek/source/reference_collector.rb +1 -2
- data/lib/reek/source/sexp_extensions.rb +93 -10
- data/lib/reek/source/sexp_formatter.rb +2 -3
- data/lib/reek/source/sexp_node.rb +19 -15
- data/lib/reek/source/source_code.rb +4 -14
- data/lib/reek/source/source_file.rb +3 -5
- data/lib/reek/source/source_locator.rb +5 -6
- data/lib/reek/source/source_repository.rb +3 -3
- data/lib/reek/source/tree_dresser.rb +2 -2
- data/lib/reek/spec.rb +1 -2
- data/lib/reek/spec/should_reek.rb +8 -5
- data/lib/reek/spec/should_reek_of.rb +6 -4
- data/lib/reek/spec/should_reek_only_of.rb +10 -6
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +34 -30
- data/spec/gem/updates_spec.rb +3 -4
- data/spec/gem/yard_spec.rb +1 -2
- data/spec/matchers/smell_of_matcher.rb +12 -14
- data/spec/quality/reek_source_spec.rb +42 -0
- data/spec/reek/cli/help_command_spec.rb +7 -5
- data/spec/reek/cli/report_spec.rb +89 -22
- data/spec/reek/cli/version_command_spec.rb +8 -6
- data/spec/reek/core/code_context_spec.rb +25 -26
- data/spec/reek/core/code_parser_spec.rb +6 -6
- data/spec/reek/core/method_context_spec.rb +18 -18
- data/spec/reek/core/module_context_spec.rb +5 -5
- data/spec/reek/core/object_refs_spec.rb +21 -22
- data/spec/reek/core/smell_configuration_spec.rb +22 -21
- data/spec/reek/core/stop_context_spec.rb +2 -2
- data/spec/reek/core/warning_collector_spec.rb +3 -3
- data/spec/reek/examiner_spec.rb +9 -9
- data/spec/reek/smell_warning_spec.rb +29 -29
- data/spec/reek/smells/attribute_spec.rb +6 -6
- data/spec/reek/smells/behaves_like_variable_detector.rb +6 -6
- data/spec/reek/smells/boolean_parameter_spec.rb +17 -17
- data/spec/reek/smells/class_variable_spec.rb +9 -9
- data/spec/reek/smells/control_parameter_spec.rb +161 -137
- data/spec/reek/smells/data_clump_spec.rb +22 -19
- data/spec/reek/smells/duplicate_method_call_spec.rb +71 -27
- data/spec/reek/smells/feature_envy_spec.rb +32 -32
- data/spec/reek/smells/irresponsible_module_spec.rb +21 -21
- data/spec/reek/smells/long_parameter_list_spec.rb +14 -14
- data/spec/reek/smells/long_yield_list_spec.rb +6 -6
- data/spec/reek/smells/nested_iterators_spec.rb +21 -21
- data/spec/reek/smells/nil_check_spec.rb +23 -15
- data/spec/reek/smells/prima_donna_method_spec.rb +5 -5
- data/spec/reek/smells/repeated_conditional_spec.rb +14 -14
- data/spec/reek/smells/smell_detector_shared.rb +9 -9
- data/spec/reek/smells/too_many_instance_variables_spec.rb +12 -12
- data/spec/reek/smells/too_many_methods_spec.rb +10 -10
- data/spec/reek/smells/too_many_statements_spec.rb +41 -41
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +4 -4
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +12 -12
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +21 -21
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +49 -49
- data/spec/reek/smells/unused_parameters_spec.rb +26 -16
- data/spec/reek/smells/utility_function_spec.rb +20 -20
- data/spec/reek/source/code_comment_spec.rb +37 -37
- data/spec/reek/source/object_source_spec.rb +5 -5
- data/spec/reek/source/reference_collector_spec.rb +9 -9
- data/spec/reek/source/sexp_extensions_spec.rb +73 -52
- data/spec/reek/source/sexp_formatter_spec.rb +3 -4
- data/spec/reek/source/sexp_node_spec.rb +3 -3
- data/spec/reek/source/source_code_spec.rb +16 -15
- data/spec/reek/source/tree_dresser_spec.rb +2 -2
- data/spec/reek/spec/should_reek_of_spec.rb +11 -11
- data/spec/reek/spec/should_reek_only_of_spec.rb +11 -11
- data/spec/reek/spec/should_reek_spec.rb +11 -11
- data/spec/samples/one_smelly_file/dirty.rb +3 -0
- data/spec/spec_helper.rb +0 -6
- data/tasks/develop.rake +8 -16
- data/tasks/reek.rake +5 -13
- data/tasks/test.rake +5 -22
- metadata +56 -34
- data/lib/reek/cli/command_line.rb +0 -126
- data/lib/reek/cli/report.rb +0 -138
@@ -6,22 +6,22 @@ include Reek::Core
|
|
6
6
|
|
7
7
|
describe ModuleContext do
|
8
8
|
it 'should report module name for smell in method' do
|
9
|
-
'module Fred; def simple(x) x + 1; end; end'.
|
9
|
+
expect('module Fred; def simple(x) x + 1; end; end').to reek_of(:UncommunicativeParameterName, /x/, /simple/)
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should not report module with empty class' do
|
13
|
-
'# module for test
|
13
|
+
expect('# module for test
|
14
14
|
module Fred
|
15
15
|
# module for test
|
16
|
-
class Jim; end; end'.
|
16
|
+
class Jim; end; end').not_to reek
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe ModuleContext do
|
21
21
|
it 'should recognise global constant' do
|
22
|
-
'# module for test
|
22
|
+
expect('# module for test
|
23
23
|
module ::Global
|
24
24
|
# module for test
|
25
|
-
class Inside; end; end'.
|
25
|
+
class Inside; end; end').not_to reek
|
26
26
|
end
|
27
27
|
end
|
@@ -10,11 +10,11 @@ describe ObjectRefs do
|
|
10
10
|
|
11
11
|
context 'when empty' do
|
12
12
|
it 'should report no refs to self' do
|
13
|
-
@refs.references_to(:self).
|
13
|
+
expect(@refs.references_to(:self)).to eq(0)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
context
|
17
|
+
context 'with references to a, b, and a' do
|
18
18
|
context 'with no refs to self' do
|
19
19
|
before(:each) do
|
20
20
|
@refs.record_reference_to('a')
|
@@ -23,33 +23,33 @@ describe ObjectRefs do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should report no refs to self' do
|
26
|
-
@refs.references_to(:self).
|
26
|
+
expect(@refs.references_to(:self)).to eq(0)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'should report :a as the max' do
|
30
|
-
@refs.max_keys.
|
30
|
+
expect(@refs.max_keys).to eq('a' => 2)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should not report self as the max' do
|
34
|
-
@refs.self_is_max
|
34
|
+
expect(@refs.self_is_max?).to eq(false)
|
35
35
|
end
|
36
36
|
|
37
|
-
context
|
37
|
+
context 'with one reference to self' do
|
38
38
|
before(:each) do
|
39
39
|
@refs.record_reference_to(:self)
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should report 1 ref to self' do
|
43
|
-
@refs.references_to(:self).
|
43
|
+
expect(@refs.references_to(:self)).to eq(1)
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should not report self among the max' do
|
47
|
-
@refs.max_keys.
|
48
|
-
@refs.max_keys.
|
47
|
+
expect(@refs.max_keys).to include('a')
|
48
|
+
expect(@refs.max_keys).not_to include(:self)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should not report self as the max' do
|
52
|
-
@refs.self_is_max
|
52
|
+
expect(@refs.self_is_max?).to eq(false)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -67,15 +67,15 @@ describe ObjectRefs do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'should report all refs to self' do
|
70
|
-
@refs.references_to(:self).
|
70
|
+
expect(@refs.references_to(:self)).to eq(4)
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'should report self among the max' do
|
74
|
-
@refs.max_keys.
|
74
|
+
expect(@refs.max_keys).to eq(self: 4)
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'should report self as the max' do
|
78
|
-
@refs.self_is_max
|
78
|
+
expect(@refs.self_is_max?).to eq(true)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -89,16 +89,16 @@ describe ObjectRefs do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'should report all refs to self' do
|
92
|
-
@refs.references_to(:self).
|
92
|
+
expect(@refs.references_to(:self)).to eq(2)
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'should report self among the max' do
|
96
|
-
@refs.max_keys.
|
97
|
-
@refs.max_keys.
|
96
|
+
expect(@refs.max_keys).to include('a')
|
97
|
+
expect(@refs.max_keys).to include(:self)
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'should report self as the max' do
|
101
|
-
@refs.self_is_max
|
101
|
+
expect(@refs.self_is_max?).to eq(true)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -111,17 +111,16 @@ describe ObjectRefs do
|
|
111
111
|
end
|
112
112
|
|
113
113
|
it 'should report all refs to self' do
|
114
|
-
@refs.references_to(:self).
|
114
|
+
expect(@refs.references_to(:self)).to eq(0)
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'should not report self among the max' do
|
118
|
-
@refs.max_keys.
|
119
|
-
@refs.max_keys.
|
118
|
+
expect(@refs.max_keys).to include('a')
|
119
|
+
expect(@refs.max_keys).to include('b')
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'should not report self as the max' do
|
123
|
-
@refs.self_is_max
|
123
|
+
expect(@refs.self_is_max?).to eq(false)
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
127
|
-
|
@@ -6,42 +6,43 @@ include Reek::Core
|
|
6
6
|
describe SmellConfiguration do
|
7
7
|
it 'returns the default value when key not found' do
|
8
8
|
cf = SmellConfiguration.new({})
|
9
|
-
cf.value('fred', nil, 27).
|
9
|
+
expect(cf.value('fred', nil, 27)).to eq(27)
|
10
10
|
end
|
11
11
|
|
12
12
|
context 'when overriding default configs' do
|
13
13
|
before(:each) do
|
14
|
-
@base_config = {
|
15
|
-
|
16
|
-
|
14
|
+
@base_config = { 'enabled' => true, 'exclude' => [],
|
15
|
+
'reject' => [/^.$/, /[0-9]$/, /[A-Z]/],
|
16
|
+
'accept' => ['_'] }
|
17
17
|
@smell_config = SmellConfiguration.new(@base_config)
|
18
18
|
end
|
19
19
|
|
20
|
-
it { @smell_config.merge!({}).
|
21
|
-
it { @smell_config.merge!(
|
22
|
-
it { @smell_config.merge!(
|
23
|
-
it { @smell_config.merge!(
|
24
|
-
it { @smell_config.merge!(
|
25
|
-
it { @smell_config.merge!(
|
20
|
+
it { expect(@smell_config.merge!({})).to eq(@base_config) }
|
21
|
+
it { expect(@smell_config.merge!('enabled' => true)).to eq(@base_config) }
|
22
|
+
it { expect(@smell_config.merge!('exclude' => [])).to eq(@base_config) }
|
23
|
+
it { expect(@smell_config.merge!('accept' => ['_'])).to eq(@base_config) }
|
24
|
+
it { expect(@smell_config.merge!('reject' => [/^.$/, /[0-9]$/, /[A-Z]/])).to eq(@base_config) }
|
25
|
+
it { expect(@smell_config.merge!('enabled' => true, 'accept' => ['_'])).to eq(@base_config) }
|
26
26
|
|
27
27
|
it 'should override single values' do
|
28
|
-
@smell_config.merge!(
|
29
|
-
|
30
|
-
|
28
|
+
expect(@smell_config.merge!('enabled' => false)).to eq('enabled' => false, 'exclude' => [],
|
29
|
+
'reject' => [/^.$/, /[0-9]$/, /[A-Z]/],
|
30
|
+
'accept' => ['_'])
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should override arrays of values' do
|
34
|
-
@smell_config.merge!(
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
expect(@smell_config.merge!('reject' => [/^.$/, /[3-9]$/])).to eq('enabled' => true,
|
35
|
+
'exclude' => [],
|
36
|
+
'reject' => [/^.$/, /[3-9]$/],
|
37
|
+
'accept' => ['_'])
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'should override multiple values' do
|
41
|
-
@smell_config.merge!(
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
expect(@smell_config.merge!('enabled' => false, 'accept' => [/[A-Z]$/])).to eq(
|
42
|
+
'enabled' => false, 'exclude' => [],
|
43
|
+
'reject' => [/^.$/, /[0-9]$/, /[A-Z]/],
|
44
|
+
'accept' => [/[A-Z]$/]
|
45
|
+
)
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
@@ -11,17 +11,17 @@ describe WarningCollector do
|
|
11
11
|
|
12
12
|
context 'when empty' do
|
13
13
|
it 'reports no warnings' do
|
14
|
-
@collector.warnings.
|
14
|
+
expect(@collector.warnings).to eq([])
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'with one warning' do
|
19
19
|
before :each do
|
20
|
-
@warning = Reek::SmellWarning.new('ControlCouple', 'fred', [1,2,3], 'hello')
|
20
|
+
@warning = Reek::SmellWarning.new('ControlCouple', 'fred', [1, 2, 3], 'hello')
|
21
21
|
@collector.found_smell(@warning)
|
22
22
|
end
|
23
23
|
it 'reports that warning' do
|
24
|
-
@collector.warnings.
|
24
|
+
expect(@collector.warnings).to eq([@warning])
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/spec/reek/examiner_spec.rb
CHANGED
@@ -5,25 +5,25 @@ include Reek
|
|
5
5
|
|
6
6
|
shared_examples_for 'supports the deprecated api' do
|
7
7
|
it 'returns all smells as active' do
|
8
|
-
@examiner.all_active_smells.
|
8
|
+
expect(@examiner.all_active_smells).to eq(@examiner.smells)
|
9
9
|
end
|
10
10
|
it 'returns all smells as active' do
|
11
|
-
@examiner.all_smells.
|
11
|
+
expect(@examiner.all_smells).to eq(@examiner.smells)
|
12
12
|
end
|
13
13
|
it 'counts all smells as active smells' do
|
14
|
-
@examiner.num_active_smells.
|
14
|
+
expect(@examiner.num_active_smells).to eq(@examiner.smells.length)
|
15
15
|
end
|
16
16
|
it 'never reports masked smells' do
|
17
|
-
@examiner.num_masked_smells.
|
17
|
+
expect(@examiner.num_masked_smells).to eq(0)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
shared_examples_for 'no smells found' do
|
22
22
|
it 'is not smelly' do
|
23
|
-
@examiner.
|
23
|
+
expect(@examiner).not_to be_smelly
|
24
24
|
end
|
25
25
|
it 'finds no smells' do
|
26
|
-
@examiner.smells.length.
|
26
|
+
expect(@examiner.smells.length).to eq(0)
|
27
27
|
end
|
28
28
|
|
29
29
|
it_should_behave_like 'supports the deprecated api'
|
@@ -31,13 +31,13 @@ end
|
|
31
31
|
|
32
32
|
shared_examples_for 'one smell found' do
|
33
33
|
it 'is smelly' do
|
34
|
-
@examiner.
|
34
|
+
expect(@examiner).to be_smelly
|
35
35
|
end
|
36
36
|
it 'reports the smell' do
|
37
|
-
@examiner.smells.length.
|
37
|
+
expect(@examiner.smells.length).to eq(1)
|
38
38
|
end
|
39
39
|
it 'reports the correct smell' do
|
40
|
-
@examiner.smells[0].smell_class.
|
40
|
+
expect(@examiner.smells[0].smell_class).to eq(@expected_first_smell)
|
41
41
|
end
|
42
42
|
|
43
43
|
it_should_behave_like 'supports the deprecated api'
|
@@ -7,24 +7,24 @@ describe SmellWarning do
|
|
7
7
|
context 'sort order' do
|
8
8
|
shared_examples_for 'first sorts ahead of second' do
|
9
9
|
it 'hash differently' do
|
10
|
-
@first.hash.
|
10
|
+
expect(@first.hash).not_to eq(@second.hash)
|
11
11
|
end
|
12
12
|
it 'are not equal' do
|
13
|
-
@first.
|
13
|
+
expect(@first).not_to eq(@second)
|
14
14
|
end
|
15
15
|
it 'sort correctly' do
|
16
|
-
(@first <=> @second).
|
16
|
+
expect(@first <=> @second).to be < 0
|
17
17
|
end
|
18
18
|
it 'does not match using eql?' do
|
19
|
-
@first.
|
20
|
-
@second.
|
19
|
+
expect(@first).not_to eql(@second)
|
20
|
+
expect(@second).not_to eql(@first)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'smells differing only by detector' do
|
25
25
|
before :each do
|
26
|
-
@first = SmellWarning.new('Duplication',
|
27
|
-
@second = SmellWarning.new('FeatureEnvy',
|
26
|
+
@first = SmellWarning.new('Duplication', 'self', 27, 'self', false)
|
27
|
+
@second = SmellWarning.new('FeatureEnvy', 'self', 27, 'self', true)
|
28
28
|
end
|
29
29
|
|
30
30
|
it_should_behave_like 'first sorts ahead of second'
|
@@ -32,8 +32,8 @@ describe SmellWarning do
|
|
32
32
|
|
33
33
|
context 'smells differing only by context' do
|
34
34
|
before :each do
|
35
|
-
@first = SmellWarning.new('FeatureEnvy',
|
36
|
-
@second = SmellWarning.new('FeatureEnvy',
|
35
|
+
@first = SmellWarning.new('FeatureEnvy', 'first', 27, 'self', true)
|
36
|
+
@second = SmellWarning.new('FeatureEnvy', 'second', 27, 'self', false)
|
37
37
|
end
|
38
38
|
|
39
39
|
it_should_behave_like 'first sorts ahead of second'
|
@@ -41,8 +41,8 @@ describe SmellWarning do
|
|
41
41
|
|
42
42
|
context 'smells differing only by message' do
|
43
43
|
before :each do
|
44
|
-
@first = SmellWarning.new('FeatureEnvy',
|
45
|
-
@second = SmellWarning.new('FeatureEnvy',
|
44
|
+
@first = SmellWarning.new('FeatureEnvy', 'context', 27, 'first', true)
|
45
|
+
@second = SmellWarning.new('FeatureEnvy', 'context', 27, 'second', false)
|
46
46
|
end
|
47
47
|
|
48
48
|
it_should_behave_like 'first sorts ahead of second'
|
@@ -50,8 +50,8 @@ describe SmellWarning do
|
|
50
50
|
|
51
51
|
context 'message takes precedence over smell name' do
|
52
52
|
before :each do
|
53
|
-
@first = SmellWarning.new('UtilityFunction',
|
54
|
-
@second = SmellWarning.new('FeatureEnvy',
|
53
|
+
@first = SmellWarning.new('UtilityFunction', 'context', 27, 'first', true)
|
54
|
+
@second = SmellWarning.new('FeatureEnvy', 'context', 27, 'second', false)
|
55
55
|
end
|
56
56
|
|
57
57
|
it_should_behave_like 'first sorts ahead of second'
|
@@ -59,8 +59,8 @@ describe SmellWarning do
|
|
59
59
|
|
60
60
|
context 'smells differing everywhere' do
|
61
61
|
before :each do
|
62
|
-
@first = SmellWarning.new('UncommunicativeName',
|
63
|
-
@second = SmellWarning.new('Duplication', 'Dirty#a', 27,
|
62
|
+
@first = SmellWarning.new('UncommunicativeName', 'Dirty', 27, "has the variable name '@s'", true)
|
63
|
+
@second = SmellWarning.new('Duplication', 'Dirty#a', 27, 'calls @s.title twice', false)
|
64
64
|
end
|
65
65
|
|
66
66
|
it_should_behave_like 'first sorts ahead of second'
|
@@ -78,20 +78,20 @@ describe SmellWarning do
|
|
78
78
|
|
79
79
|
shared_examples_for 'common fields' do
|
80
80
|
it 'includes the smell class' do
|
81
|
-
@yaml.
|
81
|
+
expect(@yaml).to match(/class:\s*FeatureEnvy/)
|
82
82
|
end
|
83
83
|
it 'includes the context' do
|
84
|
-
@yaml.
|
84
|
+
expect(@yaml).to match(/context:\s*#{@context_name}/)
|
85
85
|
end
|
86
86
|
it 'includes the message' do
|
87
|
-
@yaml.
|
87
|
+
expect(@yaml).to match(/message:\s*#{@message}/)
|
88
88
|
end
|
89
89
|
it 'indicates the masking' do
|
90
|
-
@yaml.
|
90
|
+
expect(@yaml).to match(/is_active:\s*true/)
|
91
91
|
end
|
92
92
|
it 'includes the line numbers' do
|
93
93
|
@lines.each do |line|
|
94
|
-
@yaml.
|
94
|
+
expect(@yaml).to match(/lines:[\s\d-]*- #{line}/)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -100,23 +100,23 @@ describe SmellWarning do
|
|
100
100
|
before :each do
|
101
101
|
@source = 'a/ruby/source/file.rb'
|
102
102
|
@subclass = 'TooManyParties'
|
103
|
-
@parameters = {'one' => 34, 'two' => 'second'}
|
103
|
+
@parameters = { 'one' => 34, 'two' => 'second' }
|
104
104
|
@warning = SmellWarning.new(@class, @context_name, @lines, @message,
|
105
|
-
|
105
|
+
@source, @subclass, @parameters)
|
106
106
|
@yaml = @warning.to_yaml
|
107
107
|
end
|
108
108
|
|
109
109
|
it_should_behave_like 'common fields'
|
110
110
|
|
111
111
|
it 'includes the subclass' do
|
112
|
-
@yaml.
|
112
|
+
expect(@yaml).to match(/subclass:\s*#{@subclass}/)
|
113
113
|
end
|
114
114
|
it 'includes the source' do
|
115
|
-
@yaml.
|
115
|
+
expect(@yaml).to match(/source:\s*#{@source}/)
|
116
116
|
end
|
117
117
|
it 'includes the parameters' do
|
118
|
-
@parameters.each do |key,value|
|
119
|
-
@yaml.
|
118
|
+
@parameters.each do |key, value|
|
119
|
+
expect(@yaml).to match(/#{key}:\s*#{value}/)
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
@@ -130,13 +130,13 @@ describe SmellWarning do
|
|
130
130
|
it_should_behave_like 'common fields'
|
131
131
|
|
132
132
|
it 'includes no subclass' do
|
133
|
-
@yaml.
|
133
|
+
expect(@yaml).to match(/subclass: ["']{2}/)
|
134
134
|
end
|
135
135
|
it 'includes no source' do
|
136
|
-
@yaml.
|
136
|
+
expect(@yaml).to match(/source: ["']{2}/)
|
137
137
|
end
|
138
138
|
it 'includes empty parameters' do
|
139
|
-
@yaml.
|
139
|
+
expect(@yaml).not_to match(/parameter/)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
end
|
@@ -18,7 +18,7 @@ describe Attribute do
|
|
18
18
|
it 'records nothing in the module' do
|
19
19
|
src = 'module Fred; end'
|
20
20
|
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
21
|
-
@detector.examine_context(ctx).
|
21
|
+
expect(@detector.examine_context(ctx)).to be_empty
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -34,19 +34,19 @@ describe Attribute do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'records only that attribute' do
|
37
|
-
@smells.length.
|
37
|
+
expect(@smells.length).to eq(1)
|
38
38
|
end
|
39
39
|
it 'reports the attribute name' do
|
40
|
-
@smells[0].smell[Attribute::ATTRIBUTE_KEY].
|
40
|
+
expect(@smells[0].smell[Attribute::ATTRIBUTE_KEY]).to eq(@attr_name)
|
41
41
|
end
|
42
42
|
it 'reports the declaration line number' do
|
43
|
-
@smells[0].lines.
|
43
|
+
expect(@smells[0].lines).to eq([1])
|
44
44
|
end
|
45
45
|
it 'reports the correct smell class' do
|
46
|
-
@smells[0].smell_class.
|
46
|
+
expect(@smells[0].smell_class).to eq(Attribute::SMELL_CLASS)
|
47
47
|
end
|
48
48
|
it 'reports the context fq name' do
|
49
|
-
@smells[0].context.
|
49
|
+
expect(@smells[0].context).to eq('Fred')
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|