reek 2.0.4 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +13 -0
- data/.rubocop.yml +66 -0
- data/.ruby-gemset +1 -0
- data/.travis.yml +25 -0
- data/CHANGELOG +6 -0
- data/CONTRIBUTING.md +106 -0
- data/Gemfile +14 -0
- data/README.md +16 -21
- data/bin/reek +2 -2
- data/config/cucumber.yml +3 -0
- data/config/defaults.reek +1 -1
- data/features/command_line_interface/smell_selection.feature +4 -8
- data/features/command_line_interface/smells_count.feature +25 -32
- data/features/command_line_interface/stdin.feature +2 -2
- data/features/configuration_files/masking_smells.feature +30 -41
- data/features/configuration_files/overrides_defaults.feature +5 -3
- data/features/configuration_loading.feature +26 -23
- data/features/programmatic_access.feature +24 -0
- data/features/rake_task/rake_task.feature +25 -22
- data/features/reports/json.feature +24 -26
- data/features/reports/reports.feature +77 -103
- data/features/reports/yaml.feature +26 -20
- data/features/ruby_api/api.feature +4 -3
- data/features/samples.feature +21 -20
- data/features/step_definitions/.rubocop.yml +5 -0
- data/features/step_definitions/reek_steps.rb +16 -28
- data/features/step_definitions/sample_file_steps.rb +158 -0
- data/features/support/env.rb +16 -27
- data/lib/reek.rb +3 -3
- data/lib/reek/cli/application.rb +4 -4
- data/lib/reek/cli/command.rb +1 -1
- data/lib/reek/cli/input.rb +2 -4
- data/lib/reek/cli/option_interpreter.rb +9 -9
- data/lib/reek/cli/options.rb +5 -4
- data/lib/reek/cli/reek_command.rb +3 -3
- data/lib/reek/cli/report/formatter.rb +2 -2
- data/lib/reek/cli/report/heading_formatter.rb +1 -1
- data/lib/reek/cli/report/location_formatter.rb +1 -1
- data/lib/reek/cli/report/report.rb +4 -4
- data/lib/reek/configuration/app_configuration.rb +1 -1
- data/lib/reek/configuration/configuration_file_finder.rb +17 -32
- data/lib/reek/core/code_context.rb +1 -1
- data/lib/reek/core/method_context.rb +6 -2
- data/lib/reek/core/module_context.rb +2 -2
- data/lib/reek/core/singleton_method_context.rb +1 -1
- data/lib/reek/core/smell_repository.rb +3 -2
- data/lib/reek/core/tree_walker.rb +4 -4
- data/lib/reek/examiner.rb +4 -4
- data/lib/reek/smells/attribute.rb +3 -3
- data/lib/reek/smells/boolean_parameter.rb +2 -2
- data/lib/reek/smells/class_variable.rb +2 -2
- data/lib/reek/smells/control_parameter.rb +2 -2
- data/lib/reek/smells/data_clump.rb +2 -3
- data/lib/reek/smells/duplicate_method_call.rb +2 -2
- data/lib/reek/smells/feature_envy.rb +6 -2
- data/lib/reek/smells/irresponsible_module.rb +3 -3
- data/lib/reek/smells/long_parameter_list.rb +3 -3
- data/lib/reek/smells/long_yield_list.rb +2 -2
- data/lib/reek/smells/module_initialize.rb +2 -2
- data/lib/reek/smells/nested_iterators.rb +2 -2
- data/lib/reek/smells/nil_check.rb +2 -2
- data/lib/reek/smells/prima_donna_method.rb +2 -2
- data/lib/reek/smells/repeated_conditional.rb +3 -2
- data/lib/reek/smells/smell_detector.rb +2 -2
- data/lib/reek/smells/too_many_instance_variables.rb +2 -2
- data/lib/reek/smells/too_many_methods.rb +2 -2
- data/lib/reek/smells/too_many_statements.rb +2 -2
- data/lib/reek/smells/uncommunicative_method_name.rb +2 -2
- data/lib/reek/smells/uncommunicative_module_name.rb +2 -2
- data/lib/reek/smells/uncommunicative_parameter_name.rb +2 -2
- data/lib/reek/smells/uncommunicative_variable_name.rb +2 -2
- data/lib/reek/smells/unused_parameters.rb +2 -2
- data/lib/reek/smells/utility_function.rb +8 -9
- data/lib/reek/source/ast_node.rb +1 -1
- data/lib/reek/source/ast_node_class_map.rb +6 -6
- data/lib/reek/source/sexp_extensions.rb +11 -2
- data/lib/reek/source/source_code.rb +10 -2
- data/lib/reek/source/source_locator.rb +1 -3
- data/lib/reek/source/source_repository.rb +3 -4
- data/lib/reek/source/tree_dresser.rb +2 -2
- data/lib/reek/spec.rb +3 -3
- data/lib/reek/spec/should_reek.rb +3 -3
- data/lib/reek/spec/should_reek_of.rb +1 -1
- data/lib/reek/spec/should_reek_only_of.rb +3 -3
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +18 -24
- data/spec/factories/factories.rb +1 -1
- data/spec/gem/updates_spec.rb +1 -1
- data/spec/gem/yard_spec.rb +1 -1
- data/spec/quality/reek_source_spec.rb +1 -1
- data/spec/reek/cli/html_report_spec.rb +6 -9
- data/spec/reek/cli/json_report_spec.rb +6 -6
- data/spec/reek/cli/option_interperter_spec.rb +5 -5
- data/spec/reek/cli/text_report_spec.rb +16 -19
- data/spec/reek/cli/yaml_report_spec.rb +7 -10
- data/spec/reek/configuration/app_configuration_spec.rb +23 -25
- data/spec/reek/configuration/configuration_file_finder_spec.rb +46 -21
- data/spec/reek/core/code_context_spec.rb +17 -19
- data/spec/reek/core/method_context_spec.rb +15 -14
- data/spec/reek/core/module_context_spec.rb +5 -7
- data/spec/reek/core/object_refs_spec.rb +4 -6
- data/spec/reek/core/singleton_method_context_spec.rb +5 -7
- data/spec/reek/core/smell_configuration_spec.rb +5 -7
- data/spec/reek/core/smell_repository_spec.rb +8 -8
- data/spec/reek/core/stop_context_spec.rb +4 -7
- data/spec/reek/core/tree_walker_spec.rb +5 -7
- data/spec/reek/core/warning_collector_spec.rb +5 -7
- data/spec/reek/examiner_spec.rb +10 -12
- data/spec/reek/smell_warning_spec.rb +7 -9
- data/spec/reek/smells/attribute_spec.rb +6 -6
- data/spec/reek/smells/boolean_parameter_spec.rb +4 -4
- data/spec/reek/smells/class_variable_spec.rb +6 -6
- data/spec/reek/smells/control_parameter_spec.rb +4 -4
- data/spec/reek/smells/data_clump_spec.rb +4 -4
- data/spec/reek/smells/duplicate_method_call_spec.rb +6 -6
- data/spec/reek/smells/feature_envy_spec.rb +9 -10
- data/spec/reek/smells/irresponsible_module_spec.rb +7 -7
- data/spec/reek/smells/long_parameter_list_spec.rb +5 -5
- data/spec/reek/smells/long_yield_list_spec.rb +5 -5
- data/spec/reek/smells/module_initialize_spec.rb +3 -3
- data/spec/reek/smells/nested_iterators_spec.rb +4 -4
- data/spec/reek/smells/nil_check_spec.rb +5 -5
- data/spec/reek/smells/prima_donna_method_spec.rb +7 -4
- data/spec/reek/smells/repeated_conditional_spec.rb +12 -11
- data/spec/reek/smells/smell_detector_shared.rb +4 -5
- data/spec/reek/smells/too_many_instance_variables_spec.rb +4 -4
- data/spec/reek/smells/too_many_methods_spec.rb +11 -7
- data/spec/reek/smells/too_many_statements_spec.rb +6 -5
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +4 -4
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +7 -7
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +5 -5
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +9 -6
- data/spec/reek/smells/unused_parameters_spec.rb +3 -3
- data/spec/reek/smells/utility_function_spec.rb +41 -37
- data/spec/reek/source/code_comment_spec.rb +19 -17
- data/spec/reek/source/object_source_spec.rb +1 -3
- data/spec/reek/source/reference_collector_spec.rb +5 -6
- data/spec/reek/source/sexp_extensions_spec.rb +9 -11
- data/spec/reek/source/sexp_formatter_spec.rb +7 -8
- data/spec/reek/source/sexp_node_spec.rb +3 -5
- data/spec/reek/source/source_code_spec.rb +9 -9
- data/spec/reek/source/tree_dresser_spec.rb +4 -6
- data/spec/reek/spec/should_reek_of_spec.rb +11 -10
- data/spec/reek/spec/should_reek_only_of_spec.rb +4 -7
- data/spec/reek/spec/should_reek_spec.rb +4 -7
- data/spec/samples/{overrides/masked/lower.reek → masked_by_dotfile/.reek} +3 -1
- data/spec/spec_helper.rb +4 -4
- data/tasks/develop.rake +1 -1
- data/tasks/reek.rake +1 -1
- metadata +72 -86
- data/features/support/hooks.rb +0 -15
- data/lib/reek/source.rb +0 -16
- data/lib/reek/source/core_extras.rb +0 -46
- data/lib/reek/source/source_file.rb +0 -16
- data/spec/samples/config/allow_duplication.reek +0 -3
- data/spec/samples/config/deeper_nested_iterators.reek +0 -3
- data/spec/samples/configuration_loading/minimal_dirty.rb +0 -4
- data/spec/samples/configuration_loading/reek-test-run-disable_smells.reek +0 -7
- data/spec/samples/configuration_loading/reek-test-run-enable_smells.reek +0 -7
- data/spec/samples/corrupt_config_file/corrupt.reek +0 -1
- data/spec/samples/corrupt_config_file/dirty.rb +0 -8
- data/spec/samples/demo/demo.rb +0 -8
- data/spec/samples/empty_config_file/dirty.rb +0 -8
- data/spec/samples/empty_config_file/empty.reek +0 -0
- data/spec/samples/inline_config/dirty.rb +0 -16
- data/spec/samples/inline_config/masked.reek +0 -7
- data/spec/samples/mask_some/dirty.rb +0 -8
- data/spec/samples/mask_some/some.reek +0 -8
- data/spec/samples/masked/dirty.rb +0 -8
- data/spec/samples/masked/masked.reek +0 -5
- data/spec/samples/minimal_smelly_and_masked/config.reek +0 -7
- data/spec/samples/minimal_smelly_and_masked/minimal_dirty.rb +0 -4
- data/spec/samples/mixed_results/clean_one.rb +0 -7
- data/spec/samples/mixed_results/clean_three.rb +0 -7
- data/spec/samples/mixed_results/clean_two.rb +0 -7
- data/spec/samples/mixed_results/dirty_one.rb +0 -8
- data/spec/samples/mixed_results/dirty_two.rb +0 -8
- data/spec/samples/not_quite_masked/dirty.rb +0 -8
- data/spec/samples/not_quite_masked/masked.reek +0 -5
- data/spec/samples/not_quite_masked/smelly.rb +0 -3
- data/spec/samples/one_smelly_file/dirty.rb +0 -3
- data/spec/samples/overrides/masked/dirty.rb +0 -8
- data/spec/samples/overrides/upper.reek +0 -5
- data/spec/samples/overrides_defaults/camel_case.rb +0 -14
- data/spec/samples/overrides_defaults/config.reek +0 -6
- data/spec/samples/standard_smelly/dirty.rb +0 -8
- data/spec/samples/standard_smelly/minimal_dirty.rb +0 -4
- data/spec/samples/three_smelly_files/dirty_one.rb +0 -3
- data/spec/samples/three_smelly_files/dirty_three.rb +0 -5
- data/spec/samples/three_smelly_files/dirty_two.rb +0 -4
@@ -3,7 +3,8 @@ Feature: Report smells using simple YAML layout
|
|
3
3
|
output a list of smells in Yaml.
|
4
4
|
|
5
5
|
Scenario: output is empty when there are no smells
|
6
|
-
|
6
|
+
Given a directory called 'clean_files' containing some clean files
|
7
|
+
When I run reek --format yaml clean_files
|
7
8
|
Then it succeeds
|
8
9
|
And it reports this yaml:
|
9
10
|
"""
|
@@ -11,33 +12,38 @@ Feature: Report smells using simple YAML layout
|
|
11
12
|
"""
|
12
13
|
|
13
14
|
Scenario: Indicate smells and print them as yaml when using files
|
14
|
-
|
15
|
+
Given a smelly file called 'smelly.rb'
|
16
|
+
When I run reek --format yaml smelly.rb
|
15
17
|
Then the exit status indicates smells
|
16
18
|
And it reports this yaml:
|
17
19
|
"""
|
18
20
|
---
|
19
|
-
- smell_category:
|
20
|
-
smell_type:
|
21
|
-
source:
|
22
|
-
context:
|
21
|
+
- smell_category: Duplication
|
22
|
+
smell_type: DuplicateMethodCall
|
23
|
+
source: smelly.rb
|
24
|
+
context: Smelly#m
|
23
25
|
lines:
|
24
|
-
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
- 4
|
27
|
+
- 5
|
28
|
+
message: calls @foo.bar 2 times
|
29
|
+
name: "@foo.bar"
|
30
|
+
count: 2
|
31
|
+
- smell_category: Duplication
|
32
|
+
smell_type: DuplicateMethodCall
|
33
|
+
source: smelly.rb
|
34
|
+
context: Smelly#m
|
31
35
|
lines:
|
32
|
-
-
|
33
|
-
|
34
|
-
|
36
|
+
- 4
|
37
|
+
- 5
|
38
|
+
message: calls puts(@foo.bar) 2 times
|
39
|
+
name: puts(@foo.bar)
|
40
|
+
count: 2
|
35
41
|
- smell_category: UncommunicativeName
|
36
42
|
smell_type: UncommunicativeMethodName
|
37
|
-
source:
|
38
|
-
context:
|
43
|
+
source: smelly.rb
|
44
|
+
context: Smelly#m
|
39
45
|
lines:
|
40
|
-
-
|
46
|
+
- 3
|
41
47
|
message: has the name 'm'
|
42
48
|
name: m
|
43
49
|
"""
|
@@ -50,7 +56,7 @@ Feature: Report smells using simple YAML layout
|
|
50
56
|
---
|
51
57
|
- smell_category: IrresponsibleModule
|
52
58
|
smell_type: IrresponsibleModule
|
53
|
-
source: "
|
59
|
+
source: "STDIN"
|
54
60
|
context: Turn
|
55
61
|
lines:
|
56
62
|
- 1
|
@@ -4,17 +4,18 @@ Feature: The Reek API maintains backwards compatibility
|
|
4
4
|
I want to have a stable API
|
5
5
|
|
6
6
|
Scenario: the demo example reports as expected
|
7
|
-
|
7
|
+
Given the smelly file 'demo.rb' from the example in the README
|
8
|
+
When I run reek demo.rb
|
8
9
|
Then the exit status indicates smells
|
9
10
|
And it reports:
|
10
11
|
"""
|
11
|
-
|
12
|
+
demo.rb -- 8 warnings:
|
12
13
|
[1]:Dirty has no descriptive comment (IrresponsibleModule)
|
13
14
|
[3]:Dirty#awful has 4 parameters (LongParameterList)
|
14
15
|
[3]:Dirty#awful has boolean parameter 'log' (BooleanParameter)
|
16
|
+
[3]:Dirty#awful has the parameter name 'x' (UncommunicativeParameterName)
|
15
17
|
[5]:Dirty#awful has the variable name 'w' (UncommunicativeVariableName)
|
16
18
|
[3]:Dirty#awful has unused parameter 'log' (UnusedParameters)
|
17
19
|
[3]:Dirty#awful has unused parameter 'offset' (UnusedParameters)
|
18
|
-
[3]:Dirty#awful has unused parameter 'x' (UnusedParameters)
|
19
20
|
[3]:Dirty#awful has unused parameter 'y' (UnusedParameters)
|
20
21
|
"""
|
data/features/samples.feature
CHANGED
@@ -4,11 +4,12 @@ Feature: Basic smell detection
|
|
4
4
|
I want to detect the smells in my Ruby code
|
5
5
|
|
6
6
|
Scenario: Correct smells from inline.rb
|
7
|
-
|
7
|
+
Given the "inline.rb" sample file exists
|
8
|
+
When I run reek --no-line-numbers inline.rb
|
8
9
|
Then the exit status indicates smells
|
9
10
|
And it reports:
|
10
11
|
"""
|
11
|
-
|
12
|
+
inline.rb -- 43 warnings:
|
12
13
|
CompilationError has no descriptive comment (IrresponsibleModule)
|
13
14
|
File has no descriptive comment (IrresponsibleModule)
|
14
15
|
File#self.write_with_backup has approx 6 statements (TooManyStatements)
|
@@ -49,18 +50,18 @@ Feature: Basic smell detection
|
|
49
50
|
Inline::C#parse_signature has the variable name 'x' (UncommunicativeVariableName)
|
50
51
|
Inline::C#parse_signature is controlled by argument raw (ControlParameter)
|
51
52
|
Inline::C#strip_comments doesn't depend on instance state (UtilityFunction)
|
52
|
-
Inline::C#strip_comments refers to src more than self (FeatureEnvy)
|
53
53
|
Module#inline calls Inline.const_get(lang) 2 times (DuplicateMethodCall)
|
54
54
|
Module#inline calls options[:testing] 2 times (DuplicateMethodCall)
|
55
55
|
Module#inline has approx 12 statements (TooManyStatements)
|
56
56
|
"""
|
57
57
|
|
58
58
|
Scenario: Correct smells from optparse.rb
|
59
|
-
|
59
|
+
Given the "optparse.rb" sample file exists
|
60
|
+
When I run reek --no-line-numbers optparse.rb
|
60
61
|
Then the exit status indicates smells
|
61
62
|
And it reports:
|
62
63
|
"""
|
63
|
-
|
64
|
+
optparse.rb -- 111 warnings:
|
64
65
|
OptionParser has at least 42 methods (TooManyMethods)
|
65
66
|
OptionParser has the variable name 'f' (UncommunicativeVariableName)
|
66
67
|
OptionParser has the variable name 'k' (UncommunicativeVariableName)
|
@@ -175,11 +176,12 @@ Feature: Basic smell detection
|
|
175
176
|
"""
|
176
177
|
|
177
178
|
Scenario: Correct smells from redcloth.rb
|
178
|
-
|
179
|
+
Given the "redcloth.rb" sample file exists
|
180
|
+
When I run reek --no-line-numbers redcloth.rb
|
179
181
|
Then the exit status indicates smells
|
180
182
|
And it reports:
|
181
183
|
"""
|
182
|
-
|
184
|
+
redcloth.rb -- 95 warnings:
|
183
185
|
RedCloth has at least 44 methods (TooManyMethods)
|
184
186
|
RedCloth has the variable name 'a' (UncommunicativeVariableName)
|
185
187
|
RedCloth has the variable name 'b' (UncommunicativeVariableName)
|
@@ -191,7 +193,7 @@ Feature: Basic smell detection
|
|
191
193
|
RedCloth#block_markdown_atx refers to text more than self (FeatureEnvy)
|
192
194
|
RedCloth#block_markdown_bq has approx 6 statements (TooManyStatements)
|
193
195
|
RedCloth#block_markdown_lists has unused parameter 'text' (UnusedParameters)
|
194
|
-
RedCloth#block_markdown_rule
|
196
|
+
RedCloth#block_markdown_rule doesn't depend on instance state (UtilityFunction)
|
195
197
|
RedCloth#block_markdown_setext refers to text more than self (FeatureEnvy)
|
196
198
|
RedCloth#block_textile_lists calls depth.last 5 times (DuplicateMethodCall)
|
197
199
|
RedCloth#block_textile_lists calls depth.last.length 2 times (DuplicateMethodCall)
|
@@ -218,18 +220,15 @@ Feature: Basic smell detection
|
|
218
220
|
RedCloth#clean_html has approx 15 statements (TooManyStatements)
|
219
221
|
RedCloth#clean_html has the variable name 'q' (UncommunicativeVariableName)
|
220
222
|
RedCloth#clean_html has the variable name 'q2' (UncommunicativeVariableName)
|
221
|
-
RedCloth#clean_html refers to raw more than self (FeatureEnvy)
|
222
|
-
RedCloth#clean_html refers to tags more than self (FeatureEnvy)
|
223
223
|
RedCloth#clean_white_space has approx 7 statements (TooManyStatements)
|
224
224
|
RedCloth#clean_white_space refers to text more than self (FeatureEnvy)
|
225
225
|
RedCloth#flush_left doesn't depend on instance state (UtilityFunction)
|
226
|
-
RedCloth#
|
227
|
-
RedCloth#footnote_ref refers to text more than self (FeatureEnvy)
|
226
|
+
RedCloth#footnote_ref doesn't depend on instance state (UtilityFunction)
|
228
227
|
RedCloth#glyphs_textile has approx 10 statements (TooManyStatements)
|
228
|
+
RedCloth#h_align doesn't depend on instance state (UtilityFunction)
|
229
229
|
RedCloth#htmlesc doesn't depend on instance state (UtilityFunction)
|
230
230
|
RedCloth#htmlesc is controlled by argument mode (ControlParameter)
|
231
|
-
RedCloth#
|
232
|
-
RedCloth#incoming_entities refers to text more than self (FeatureEnvy)
|
231
|
+
RedCloth#incoming_entities doesn't depend on instance state (UtilityFunction)
|
233
232
|
RedCloth#initialize has the variable name 'r' (UncommunicativeVariableName)
|
234
233
|
RedCloth#inline contains iterators nested 2 deep (NestedIterators)
|
235
234
|
RedCloth#inline_markdown_link has approx 6 statements (TooManyStatements)
|
@@ -246,11 +245,10 @@ Feature: Basic smell detection
|
|
246
245
|
RedCloth#inline_textile_span contains iterators nested 2 deep (NestedIterators)
|
247
246
|
RedCloth#inline_textile_span has approx 9 statements (TooManyStatements)
|
248
247
|
RedCloth#inline_textile_span has the variable name 'm' (UncommunicativeVariableName)
|
248
|
+
RedCloth#lT doesn't depend on instance state (UtilityFunction)
|
249
249
|
RedCloth#lT has the name 'lT' (UncommunicativeMethodName)
|
250
250
|
RedCloth#lT is controlled by argument text (ControlParameter)
|
251
|
-
RedCloth#lT refers to text more than self (FeatureEnvy)
|
252
251
|
RedCloth#no_textile doesn't depend on instance state (UtilityFunction)
|
253
|
-
RedCloth#no_textile refers to text more than self (FeatureEnvy)
|
254
252
|
RedCloth#pba calls $1.length 2 times (DuplicateMethodCall)
|
255
253
|
RedCloth#pba has approx 21 statements (TooManyStatements)
|
256
254
|
RedCloth#pba is controlled by argument element (ControlParameter)
|
@@ -278,22 +276,25 @@ Feature: Basic smell detection
|
|
278
276
|
RedCloth#textile_popup_help has the parameter name 'windowH' (UncommunicativeParameterName)
|
279
277
|
RedCloth#textile_popup_help has the parameter name 'windowW' (UncommunicativeParameterName)
|
280
278
|
RedCloth#to_html has approx 26 statements (TooManyStatements)
|
279
|
+
RedCloth#v_align doesn't depend on instance state (UtilityFunction)
|
281
280
|
"""
|
282
281
|
|
283
282
|
Scenario: Correct smells from a source file with Ruby 2.0 specific syntax
|
284
|
-
|
283
|
+
Given the "ruby20_syntax.rb" sample file exists
|
284
|
+
When I run reek ruby20_syntax.rb
|
285
285
|
Then the exit status indicates smells
|
286
286
|
And it reports:
|
287
287
|
"""
|
288
|
-
|
288
|
+
ruby20_syntax.rb -- 1 warning:
|
289
289
|
[1]:SomeClass has no descriptive comment (IrresponsibleModule)
|
290
290
|
"""
|
291
291
|
|
292
292
|
Scenario: Correct smells from a source file with Ruby 2.1 specific syntax
|
293
|
-
|
293
|
+
Given the "ruby21_syntax.rb" sample file exists
|
294
|
+
When I run reek ruby21_syntax.rb
|
294
295
|
Then the exit status indicates smells
|
295
296
|
And it reports:
|
296
297
|
"""
|
297
|
-
|
298
|
+
ruby21_syntax.rb -- 1 warning:
|
298
299
|
[1]:SomeClass has no descriptive comment (IrresponsibleModule)
|
299
300
|
"""
|
@@ -11,81 +11,69 @@ When /^I run rake (\w*) with:$/ do |name, task_def|
|
|
11
11
|
end
|
12
12
|
|
13
13
|
Then /^it reports nothing$/ do
|
14
|
-
|
14
|
+
assert_exact_output '', all_stdout
|
15
15
|
end
|
16
16
|
|
17
17
|
Then /^there is no output on stdout$/ do
|
18
|
-
|
18
|
+
assert_exact_output '', all_stdout
|
19
19
|
end
|
20
20
|
|
21
21
|
Then /^stdout includes "(.*)"$/ do |text|
|
22
|
-
|
22
|
+
assert_partial_output(text, all_stdout)
|
23
23
|
end
|
24
24
|
|
25
25
|
Then /^it succeeds$/ do
|
26
|
-
|
26
|
+
assert_exit_status Reek::CLI::Application::STATUS_SUCCESS
|
27
27
|
end
|
28
28
|
|
29
29
|
Then /^the exit status indicates an error$/ do
|
30
|
-
|
30
|
+
assert_exit_status Reek::CLI::Application::STATUS_ERROR
|
31
31
|
end
|
32
32
|
|
33
33
|
Then /^the exit status indicates smells$/ do
|
34
|
-
|
34
|
+
assert_exit_status Reek::CLI::Application::STATUS_SMELLS
|
35
35
|
end
|
36
36
|
|
37
37
|
Then /^it reports:$/ do |report|
|
38
|
-
|
38
|
+
assert_exact_output "#{report}\n", all_stdout
|
39
39
|
end
|
40
40
|
|
41
41
|
Then /^it reports this yaml:$/ do |expected_yaml|
|
42
42
|
expected_warnings = YAML.load(expected_yaml.chomp)
|
43
|
-
actual_warnings = YAML.load(
|
43
|
+
actual_warnings = YAML.load(all_stdout)
|
44
44
|
expect(actual_warnings).to eq expected_warnings
|
45
45
|
end
|
46
46
|
|
47
47
|
Then /^it reports this JSON:$/ do |expected_json|
|
48
48
|
expected_warnings = JSON.parse(expected_json.chomp)
|
49
|
-
actual_warnings = JSON.parse(
|
49
|
+
actual_warnings = JSON.parse(all_stdout)
|
50
50
|
expect(actual_warnings).to eq expected_warnings
|
51
51
|
end
|
52
52
|
|
53
53
|
Then /^stderr reports:$/ do |report|
|
54
|
-
|
54
|
+
assert_exact_output report, all_stderr
|
55
55
|
end
|
56
56
|
|
57
57
|
Then /^it reports no errors$/ do
|
58
|
-
|
58
|
+
assert_exact_output '', all_stderr
|
59
59
|
end
|
60
60
|
|
61
61
|
Then /^it reports an error$/ do
|
62
|
-
expect(
|
62
|
+
expect(all_stderr).to_not be_empty
|
63
63
|
end
|
64
64
|
|
65
65
|
Then /^it reports the error ['"](.*)['"]$/ do |string|
|
66
|
-
|
66
|
+
assert_partial_output string, all_stderr
|
67
67
|
end
|
68
68
|
|
69
69
|
Then /^it reports a parsing error$/ do
|
70
|
-
|
70
|
+
assert_partial_output 'Parser::SyntaxError', all_stderr
|
71
71
|
end
|
72
72
|
|
73
73
|
Then /^it should indicate the line numbers of those smells$/ do
|
74
|
-
|
74
|
+
assert_matching_output /\[.*\]:/, all_stdout
|
75
75
|
end
|
76
76
|
|
77
77
|
Then /^it reports the current version$/ do
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
Given(/^"(.*?)" exists in the working directory$/) do |path|
|
82
|
-
FileUtils.cp path, Pathname.pwd
|
83
|
-
end
|
84
|
-
|
85
|
-
Given(/^"(.*?)" exists in the parent directory of the working directory$/) do |path|
|
86
|
-
FileUtils.cp path, Pathname.pwd.parent
|
87
|
-
end
|
88
|
-
|
89
|
-
Given(/^"(.*?)" exists in the HOME directory$/) do |path|
|
90
|
-
FileUtils.cp path, Pathname.new(Dir.home)
|
78
|
+
assert_exact_output "reek #{Reek::Version::STRING}\n", all_stdout
|
91
79
|
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
Given(/^the smelly file 'demo.rb' from the example in the README$/) do
|
2
|
+
contents = <<-EOS.strip_heredoc
|
3
|
+
class Dirty
|
4
|
+
# This method smells of :reek:NestedIterators but ignores them
|
5
|
+
def awful(x, y, offset = 0, log = false)
|
6
|
+
puts @screen.title
|
7
|
+
@screen = widgets.map {|w| w.each {|key| key += 3 * x}}
|
8
|
+
puts @screen.contents
|
9
|
+
end
|
10
|
+
end
|
11
|
+
EOS
|
12
|
+
write_file('demo.rb', contents)
|
13
|
+
end
|
14
|
+
|
15
|
+
Given(/^a smelly file with inline masking called 'inline.rb'$/) do
|
16
|
+
write_file 'inline.rb', <<-EOS.strip_heredoc
|
17
|
+
# smells of :reek:NestedIterators but ignores them
|
18
|
+
class Dirty
|
19
|
+
def a
|
20
|
+
puts @s.title
|
21
|
+
@s = foo.map {|x| x.each {|key| key += 3}}
|
22
|
+
puts @s.title
|
23
|
+
end
|
24
|
+
end
|
25
|
+
EOS
|
26
|
+
end
|
27
|
+
|
28
|
+
Given(/^the "(.*?)" sample file exists$/) do |file_name|
|
29
|
+
full_path = File.expand_path file_name, 'spec/samples'
|
30
|
+
in_current_dir { FileUtils.cp full_path, file_name }
|
31
|
+
end
|
32
|
+
|
33
|
+
Given(/^a directory called 'clean_files' containing some clean files$/) do
|
34
|
+
contents = <<-EOS.strip_heredoc
|
35
|
+
# clean class for testing purposes
|
36
|
+
class Clean
|
37
|
+
def assign
|
38
|
+
puts @sub.title
|
39
|
+
@sub.map {|para| para.name }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
EOS
|
43
|
+
write_file 'clean_files/clean_one.rb', contents
|
44
|
+
write_file 'clean_files/clean_two.rb', contents
|
45
|
+
write_file 'clean_files/clean_three.rb', contents
|
46
|
+
end
|
47
|
+
|
48
|
+
Given(/^a directory called 'smelly' containing two smelly files$/) do
|
49
|
+
write_file('smelly/dirty_one.rb', <<-EOS.strip_heredoc)
|
50
|
+
class Dirty
|
51
|
+
def a; end
|
52
|
+
end
|
53
|
+
EOS
|
54
|
+
write_file('smelly/dirty_two.rb', <<-EOS.strip_heredoc)
|
55
|
+
class Dirty
|
56
|
+
def a; end
|
57
|
+
def b; end
|
58
|
+
end
|
59
|
+
EOS
|
60
|
+
end
|
61
|
+
|
62
|
+
Given(/^a smelly file called 'smelly.rb'( in a subdirectory)?$/) do |in_subdir|
|
63
|
+
file_name = in_subdir ? 'subdir/smelly.rb' : 'smelly.rb'
|
64
|
+
write_file file_name, <<-EOS.strip_heredoc
|
65
|
+
# smelly class for testing purposes
|
66
|
+
class Smelly
|
67
|
+
def m
|
68
|
+
puts @foo.bar
|
69
|
+
puts @foo.bar
|
70
|
+
end
|
71
|
+
end
|
72
|
+
EOS
|
73
|
+
end
|
74
|
+
|
75
|
+
Given(/^a file with smelly variable names called 'camel_case.rb'$/) do
|
76
|
+
write_file('camel_case.rb', <<-EOS.strip_heredoc)
|
77
|
+
# Class containing camelCase variable which would normally smell
|
78
|
+
class CamelCase
|
79
|
+
def initialize
|
80
|
+
# These next two would normally smell if it weren't for overridden config values
|
81
|
+
camelCaseVariable = []
|
82
|
+
anotherOne = 1
|
83
|
+
|
84
|
+
# this next one should still smell
|
85
|
+
x1 = 0
|
86
|
+
|
87
|
+
# this next one should not smell
|
88
|
+
should_not_smell = true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
EOS
|
92
|
+
end
|
93
|
+
|
94
|
+
Given(/^an empty configuration file called 'empty.reek'$/) do
|
95
|
+
write_file('empty.reek', '')
|
96
|
+
end
|
97
|
+
|
98
|
+
Given(/^a corrupt configuration file called 'corrupt.reek'$/) do
|
99
|
+
write_file('corrupt.reek', 'This is not a configuration file')
|
100
|
+
end
|
101
|
+
|
102
|
+
Given(/^a masking configuration file called 'config.reek'$/) do
|
103
|
+
write_file('config.reek', <<-EOS.strip_heredoc)
|
104
|
+
---
|
105
|
+
DuplicateMethodCall:
|
106
|
+
enabled: false
|
107
|
+
UncommunicativeMethodName:
|
108
|
+
enabled: false
|
109
|
+
EOS
|
110
|
+
end
|
111
|
+
|
112
|
+
Given(/^a configuration file masking some duplication smells called 'config.reek'$/) do
|
113
|
+
write_file('config.reek', <<-EOS.strip_heredoc)
|
114
|
+
---
|
115
|
+
DuplicateMethodCall:
|
116
|
+
allow_calls:
|
117
|
+
- puts\\(@foo.bar\\)
|
118
|
+
EOS
|
119
|
+
end
|
120
|
+
|
121
|
+
Given(/^a configuration file allowing camel case variables$/) do
|
122
|
+
write_file('config.reek', <<-EOS.strip_heredoc)
|
123
|
+
---
|
124
|
+
UncommunicativeVariableName:
|
125
|
+
enabled: true
|
126
|
+
reject:
|
127
|
+
- !ruby/regexp /^.$/
|
128
|
+
- !ruby/regexp /[0-9]$/
|
129
|
+
EOS
|
130
|
+
end
|
131
|
+
|
132
|
+
When(/^I run "reek (.*?)" in the subdirectory$/) do |args|
|
133
|
+
cd 'subdir'
|
134
|
+
reek(args)
|
135
|
+
end
|
136
|
+
|
137
|
+
Given(/^a masking configuration file in the HOME directory$/) do
|
138
|
+
set_env('HOME', File.expand_path(File.join(current_dir, 'home')))
|
139
|
+
write_file('home/config.reek', <<-EOS.strip_heredoc)
|
140
|
+
---
|
141
|
+
DuplicateMethodCall:
|
142
|
+
enabled: false
|
143
|
+
UncommunicativeMethodName:
|
144
|
+
enabled: false
|
145
|
+
EOS
|
146
|
+
end
|
147
|
+
|
148
|
+
Given(/^an enabling configuration file in the subdirectory$/) do
|
149
|
+
write_file('subdir/config.reek', <<-EOS.strip_heredoc)
|
150
|
+
---
|
151
|
+
IrresponsibleModule:
|
152
|
+
enabled: true
|
153
|
+
UncommunicativeModuleName:
|
154
|
+
enabled: true
|
155
|
+
UncommunicativeMethodName:
|
156
|
+
enabled: true
|
157
|
+
EOS
|
158
|
+
end
|