reek 6.0.1 → 6.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/ruby.yml +52 -0
  4. data/.rubocop.yml +2 -20
  5. data/.rubocop_todo.yml +27 -20
  6. data/CHANGELOG.md +22 -0
  7. data/CONTRIBUTING.md +3 -0
  8. data/Dockerfile +1 -1
  9. data/Gemfile +6 -6
  10. data/README.md +1 -1
  11. data/bin/code_climate_reek +2 -3
  12. data/lib/reek.rb +1 -0
  13. data/lib/reek/ast/ast_node_class_map.rb +1 -1
  14. data/lib/reek/ast/node.rb +1 -1
  15. data/lib/reek/cli/options.rb +1 -1
  16. data/lib/reek/configuration/app_configuration.rb +4 -3
  17. data/lib/reek/configuration/directory_directives.rb +2 -2
  18. data/lib/reek/configuration/excluded_paths.rb +2 -1
  19. data/lib/reek/context/code_context.rb +1 -1
  20. data/lib/reek/context/module_context.rb +3 -1
  21. data/lib/reek/context/refinement_context.rb +16 -0
  22. data/lib/reek/context_builder.rb +16 -2
  23. data/lib/reek/report/code_climate/code_climate_configuration.yml +1 -1
  24. data/lib/reek/report/code_climate/code_climate_formatter.rb +1 -3
  25. data/lib/reek/smell_detectors/base_detector.rb +1 -1
  26. data/lib/reek/smell_detectors/boolean_parameter.rb +3 -1
  27. data/lib/reek/smell_detectors/uncommunicative_variable_name.rb +1 -1
  28. data/lib/reek/smell_warning.rb +2 -3
  29. data/lib/reek/source/source_locator.rb +14 -13
  30. data/lib/reek/version.rb +1 -1
  31. data/reek.gemspec +14 -3
  32. metadata +29 -232
  33. data/.travis.yml +0 -36
  34. data/docs/API.md +0 -174
  35. data/docs/Attribute.md +0 -39
  36. data/docs/Basic-Smell-Options.md +0 -85
  37. data/docs/Boolean-Parameter.md +0 -54
  38. data/docs/Class-Variable.md +0 -40
  39. data/docs/Code-Smells.md +0 -39
  40. data/docs/Command-Line-Options.md +0 -119
  41. data/docs/Control-Couple.md +0 -26
  42. data/docs/Control-Parameter.md +0 -32
  43. data/docs/Data-Clump.md +0 -46
  44. data/docs/Duplicate-Method-Call.md +0 -264
  45. data/docs/Feature-Envy.md +0 -93
  46. data/docs/How-To-Write-New-Detectors.md +0 -132
  47. data/docs/How-reek-works-internally.md +0 -114
  48. data/docs/Instance-Variable-Assumption.md +0 -163
  49. data/docs/Irresponsible-Module.md +0 -47
  50. data/docs/Large-Class.md +0 -16
  51. data/docs/Long-Parameter-List.md +0 -39
  52. data/docs/Long-Yield-List.md +0 -37
  53. data/docs/Manual-Dispatch.md +0 -30
  54. data/docs/Missing-Safe-Method.md +0 -92
  55. data/docs/Module-Initialize.md +0 -62
  56. data/docs/Nested-Iterators.md +0 -59
  57. data/docs/Nil-Check.md +0 -47
  58. data/docs/RSpec-matchers.md +0 -129
  59. data/docs/Rake-Task.md +0 -66
  60. data/docs/Reek-4-to-Reek-5-migration.md +0 -188
  61. data/docs/Reek-Driven-Development.md +0 -46
  62. data/docs/Repeated-Conditional.md +0 -47
  63. data/docs/Simulated-Polymorphism.md +0 -16
  64. data/docs/Smell-Suppression.md +0 -96
  65. data/docs/Style-Guide.md +0 -19
  66. data/docs/Subclassed-From-Core-Class.md +0 -79
  67. data/docs/Too-Many-Constants.md +0 -37
  68. data/docs/Too-Many-Instance-Variables.md +0 -43
  69. data/docs/Too-Many-Methods.md +0 -56
  70. data/docs/Too-Many-Statements.md +0 -54
  71. data/docs/Uncommunicative-Method-Name.md +0 -94
  72. data/docs/Uncommunicative-Module-Name.md +0 -92
  73. data/docs/Uncommunicative-Name.md +0 -18
  74. data/docs/Uncommunicative-Parameter-Name.md +0 -90
  75. data/docs/Uncommunicative-Variable-Name.md +0 -96
  76. data/docs/Unused-Parameters.md +0 -28
  77. data/docs/Unused-Private-Method.md +0 -101
  78. data/docs/Utility-Function.md +0 -56
  79. data/docs/Versioning-Policy.md +0 -7
  80. data/docs/YAML-Reports.md +0 -93
  81. data/docs/defaults.reek.yml +0 -129
  82. data/docs/templates/default/docstring/html/public_api_marker.erb +0 -3
  83. data/docs/templates/default/docstring/setup.rb +0 -37
  84. data/docs/templates/default/fulldoc/html/css/common.css +0 -1
  85. data/docs/yard_plugin.rb +0 -17
  86. data/features/command_line_interface/basic_usage.feature +0 -15
  87. data/features/command_line_interface/options.feature +0 -123
  88. data/features/command_line_interface/show_progress.feature +0 -33
  89. data/features/command_line_interface/smell_selection.feature +0 -15
  90. data/features/command_line_interface/smells_count.feature +0 -38
  91. data/features/command_line_interface/stdin.feature +0 -65
  92. data/features/configuration_files/accept_setting.feature +0 -87
  93. data/features/configuration_files/directory_specific_directives.feature +0 -274
  94. data/features/configuration_files/exclude_directives.feature +0 -35
  95. data/features/configuration_files/exclude_paths_directives.feature +0 -42
  96. data/features/configuration_files/masking_smells.feature +0 -94
  97. data/features/configuration_files/mix_accept_reject_setting.feature +0 -84
  98. data/features/configuration_files/reject_setting.feature +0 -89
  99. data/features/configuration_files/schema_validation.feature +0 -59
  100. data/features/configuration_files/show_configuration_file.feature +0 -44
  101. data/features/configuration_files/unused_private_method.feature +0 -68
  102. data/features/configuration_loading.feature +0 -91
  103. data/features/configuration_via_source_comments/erroneous_source_comments.feature +0 -68
  104. data/features/configuration_via_source_comments/well_formed_source_comments.feature +0 -116
  105. data/features/locales.feature +0 -32
  106. data/features/programmatic_access.feature +0 -41
  107. data/features/rake_task/rake_task.feature +0 -138
  108. data/features/reports/codeclimate.feature +0 -59
  109. data/features/reports/json.feature +0 -59
  110. data/features/reports/reports.feature +0 -219
  111. data/features/reports/yaml.feature +0 -52
  112. data/features/rspec_matcher.feature +0 -41
  113. data/features/samples.feature +0 -305
  114. data/features/step_definitions/.rubocop.yml +0 -5
  115. data/features/step_definitions/reek_steps.rb +0 -102
  116. data/features/step_definitions/sample_file_steps.rb +0 -63
  117. data/features/support/env.rb +0 -33
  118. data/features/todo_list.feature +0 -108
  119. data/samples/checkstyle.xml +0 -7
  120. data/samples/clean_source/clean.rb +0 -6
  121. data/samples/configuration/accepts_rejects_and_excludes_for_detectors.reek.yml +0 -29
  122. data/samples/configuration/accepts_rejects_and_excludes_for_directory_directives.reek.yml +0 -30
  123. data/samples/configuration/corrupt.reek +0 -1
  124. data/samples/configuration/empty.reek +0 -0
  125. data/samples/configuration/full_configuration.reek +0 -13
  126. data/samples/configuration/full_mask.reek +0 -6
  127. data/samples/configuration/home/home.reek.yml +0 -4
  128. data/samples/configuration/partial_mask.reek +0 -4
  129. data/samples/configuration/regular_configuration/.reek.yml +0 -4
  130. data/samples/configuration/regular_configuration/empty_sub_directory/.gitignore +0 -0
  131. data/samples/configuration/with_excluded_paths.reek +0 -5
  132. data/samples/no_config_file/.keep +0 -0
  133. data/samples/paths.rb +0 -5
  134. data/samples/smelly_source/inline.rb +0 -704
  135. data/samples/smelly_source/optparse.rb +0 -1788
  136. data/samples/smelly_source/redcloth.rb +0 -1130
  137. data/samples/smelly_source/ruby.rb +0 -368
  138. data/samples/smelly_source/smelly.rb +0 -7
  139. data/samples/source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb +0 -5
  140. data/samples/source_with_exclude_paths/nested/ignore_me_as_well/irresponsible_module.rb +0 -2
  141. data/samples/source_with_exclude_paths/nested/uncommunicative_parameter_name.rb +0 -6
  142. data/samples/source_with_exclude_paths/nested/uncommunicative_variable_name.rb +0 -6
  143. data/samples/source_with_hidden_directories/.hidden/hidden.rb +0 -1
  144. data/samples/source_with_hidden_directories/not_hidden.rb +0 -1
  145. data/samples/source_with_non_ruby_files/gibberish +0 -1
  146. data/samples/source_with_non_ruby_files/python_source.py +0 -1
  147. data/samples/source_with_non_ruby_files/ruby.rb +0 -6
  148. data/spec/performance/reek/smell_detectors/runtime_speed_spec.rb +0 -17
  149. data/spec/quality/documentation_spec.rb +0 -40
  150. data/spec/quality/reek_source_spec.rb +0 -11
  151. data/spec/reek/ast/node_spec.rb +0 -211
  152. data/spec/reek/ast/object_refs_spec.rb +0 -83
  153. data/spec/reek/ast/reference_collector_spec.rb +0 -47
  154. data/spec/reek/ast/sexp_extensions_spec.rb +0 -498
  155. data/spec/reek/cli/application_spec.rb +0 -168
  156. data/spec/reek/cli/command/report_command_spec.rb +0 -44
  157. data/spec/reek/cli/command/todo_list_command_spec.rb +0 -86
  158. data/spec/reek/cli/options_spec.rb +0 -51
  159. data/spec/reek/cli/silencer_spec.rb +0 -28
  160. data/spec/reek/code_comment_spec.rb +0 -184
  161. data/spec/reek/configuration/app_configuration_spec.rb +0 -195
  162. data/spec/reek/configuration/configuration_file_finder_spec.rb +0 -230
  163. data/spec/reek/configuration/default_directive_spec.rb +0 -13
  164. data/spec/reek/configuration/directory_directives_spec.rb +0 -122
  165. data/spec/reek/configuration/excluded_paths_spec.rb +0 -16
  166. data/spec/reek/configuration/rake_task_converter_spec.rb +0 -33
  167. data/spec/reek/configuration/schema_validator_spec.rb +0 -165
  168. data/spec/reek/context/code_context_spec.rb +0 -192
  169. data/spec/reek/context/ghost_context_spec.rb +0 -60
  170. data/spec/reek/context/method_context_spec.rb +0 -72
  171. data/spec/reek/context/module_context_spec.rb +0 -55
  172. data/spec/reek/context/root_context_spec.rb +0 -12
  173. data/spec/reek/context/statement_counter_spec.rb +0 -24
  174. data/spec/reek/context_builder_spec.rb +0 -457
  175. data/spec/reek/detector_repository_spec.rb +0 -22
  176. data/spec/reek/documentation_link_spec.rb +0 -20
  177. data/spec/reek/errors/base_error_spec.rb +0 -13
  178. data/spec/reek/examiner_spec.rb +0 -309
  179. data/spec/reek/logging_error_handler_spec.rb +0 -24
  180. data/spec/reek/rake/task_spec.rb +0 -56
  181. data/spec/reek/report/code_climate/code_climate_configuration_spec.rb +0 -22
  182. data/spec/reek/report/code_climate/code_climate_fingerprint_spec.rb +0 -126
  183. data/spec/reek/report/code_climate/code_climate_formatter_spec.rb +0 -51
  184. data/spec/reek/report/code_climate/code_climate_report_spec.rb +0 -56
  185. data/spec/reek/report/html_report_spec.rb +0 -19
  186. data/spec/reek/report/json_report_spec.rb +0 -58
  187. data/spec/reek/report/location_formatter_spec.rb +0 -32
  188. data/spec/reek/report/progress_formatter_spec.rb +0 -68
  189. data/spec/reek/report/text_report_spec.rb +0 -89
  190. data/spec/reek/report/xml_report_spec.rb +0 -24
  191. data/spec/reek/report/yaml_report_spec.rb +0 -55
  192. data/spec/reek/report_spec.rb +0 -28
  193. data/spec/reek/smell_configuration_spec.rb +0 -56
  194. data/spec/reek/smell_detectors/attribute_spec.rb +0 -197
  195. data/spec/reek/smell_detectors/base_detector_spec.rb +0 -50
  196. data/spec/reek/smell_detectors/boolean_parameter_spec.rb +0 -93
  197. data/spec/reek/smell_detectors/class_variable_spec.rb +0 -106
  198. data/spec/reek/smell_detectors/control_parameter_spec.rb +0 -300
  199. data/spec/reek/smell_detectors/data_clump_spec.rb +0 -134
  200. data/spec/reek/smell_detectors/duplicate_method_call_spec.rb +0 -211
  201. data/spec/reek/smell_detectors/feature_envy_spec.rb +0 -295
  202. data/spec/reek/smell_detectors/instance_variable_assumption_spec.rb +0 -96
  203. data/spec/reek/smell_detectors/irresponsible_module_spec.rb +0 -226
  204. data/spec/reek/smell_detectors/long_parameter_list_spec.rb +0 -61
  205. data/spec/reek/smell_detectors/long_yield_list_spec.rb +0 -49
  206. data/spec/reek/smell_detectors/manual_dispatch_spec.rb +0 -75
  207. data/spec/reek/smell_detectors/missing_safe_method_spec.rb +0 -68
  208. data/spec/reek/smell_detectors/module_initialize_spec.rb +0 -77
  209. data/spec/reek/smell_detectors/nested_iterators_spec.rb +0 -333
  210. data/spec/reek/smell_detectors/nil_check_spec.rb +0 -100
  211. data/spec/reek/smell_detectors/repeated_conditional_spec.rb +0 -100
  212. data/spec/reek/smell_detectors/subclassed_from_core_class_spec.rb +0 -77
  213. data/spec/reek/smell_detectors/too_many_constants_spec.rb +0 -144
  214. data/spec/reek/smell_detectors/too_many_instance_variables_spec.rb +0 -132
  215. data/spec/reek/smell_detectors/too_many_methods_spec.rb +0 -54
  216. data/spec/reek/smell_detectors/too_many_statements_spec.rb +0 -90
  217. data/spec/reek/smell_detectors/uncommunicative_method_name_spec.rb +0 -78
  218. data/spec/reek/smell_detectors/uncommunicative_module_name_spec.rb +0 -78
  219. data/spec/reek/smell_detectors/uncommunicative_parameter_name_spec.rb +0 -147
  220. data/spec/reek/smell_detectors/uncommunicative_variable_name_spec.rb +0 -201
  221. data/spec/reek/smell_detectors/unused_parameters_spec.rb +0 -114
  222. data/spec/reek/smell_detectors/unused_private_method_spec.rb +0 -205
  223. data/spec/reek/smell_detectors/utility_function_spec.rb +0 -293
  224. data/spec/reek/smell_warning_spec.rb +0 -137
  225. data/spec/reek/source/source_code_spec.rb +0 -79
  226. data/spec/reek/source/source_locator_spec.rb +0 -166
  227. data/spec/reek/spec/should_reek_of_spec.rb +0 -153
  228. data/spec/reek/spec/should_reek_only_of_spec.rb +0 -91
  229. data/spec/reek/spec/should_reek_spec.rb +0 -52
  230. data/spec/reek/spec/smell_matcher_spec.rb +0 -87
  231. data/spec/reek/tree_dresser_spec.rb +0 -46
  232. data/spec/spec_helper.rb +0 -110
  233. data/tasks/configuration.rake +0 -19
  234. data/tasks/console.rake +0 -5
  235. data/tasks/reek.rake +0 -6
  236. data/tasks/rubocop.rake +0 -11
  237. data/tasks/test.rake +0 -32
@@ -1,168 +0,0 @@
1
- require_relative '../../spec_helper'
2
- require_lib 'reek/cli/application'
3
-
4
- RSpec.describe Reek::CLI::Application do
5
- describe '#initialize' do
6
- it 'exits with default error code on invalid options' do
7
- call = lambda do
8
- Reek::CLI::Silencer.silently do
9
- described_class.new ['--foo']
10
- end
11
- end
12
- expect(&call).to raise_error(SystemExit) do |error|
13
- expect(error.status).to eq Reek::CLI::Status::DEFAULT_ERROR_EXIT_CODE
14
- end
15
- end
16
- end
17
-
18
- describe '#execute' do
19
- let(:path_excluded_in_configuration) do
20
- SAMPLES_DIR.join('source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb')
21
- end
22
- let(:configuration) { test_configuration_for(CONFIGURATION_DIR.join('with_excluded_paths.reek')) }
23
- let(:command) { instance_double 'Reek::CLI::Command::ReportCommand' }
24
- let(:app) { described_class.new [] }
25
-
26
- before do
27
- allow(Reek::CLI::Command::ReportCommand).to receive(:new).and_return command
28
- allow(command).to receive(:execute).and_return 'foo'
29
- end
30
-
31
- it "returns the command's result code" do
32
- expect(app.execute).to eq 'foo'
33
- end
34
-
35
- context 'when no source files given and input was piped' do
36
- before do
37
- allow_any_instance_of(IO).to receive(:tty?).and_return(false)
38
- end
39
-
40
- it 'uses source from pipe' do
41
- expected_sources = a_collection_containing_exactly(have_attributes(origin: 'STDIN'))
42
- app.execute
43
- expect(Reek::CLI::Command::ReportCommand).to have_received(:new).
44
- with(sources: expected_sources,
45
- configuration: Reek::Configuration::AppConfiguration,
46
- options: Reek::CLI::Options)
47
- end
48
-
49
- context 'when a stdin filename is provided' do
50
- let(:app) { described_class.new ['--stdin-filename', 'foo.rb'] }
51
-
52
- it 'assumes that filename' do
53
- expected_sources = a_collection_containing_exactly(have_attributes(origin: 'foo.rb'))
54
- app.execute
55
- expect(Reek::CLI::Command::ReportCommand).to have_received(:new).
56
- with(sources: expected_sources,
57
- configuration: Reek::Configuration::AppConfiguration,
58
- options: Reek::CLI::Options)
59
- end
60
- end
61
- end
62
-
63
- context 'when no source files given and no input was piped' do
64
- before do
65
- allow_any_instance_of(IO).to receive(:tty?).and_return(true)
66
- end
67
-
68
- it 'uses working directory as source' do
69
- expected_sources = Reek::Source::SourceLocator.new(['.']).sources
70
- app.execute
71
- expect(Reek::CLI::Command::ReportCommand).to have_received(:new).
72
- with(sources: expected_sources,
73
- configuration: Reek::Configuration::AppConfiguration,
74
- options: Reek::CLI::Options)
75
- end
76
-
77
- context 'when source files are excluded through configuration' do
78
- let(:app) { described_class.new ['--config', 'some_file.reek'] }
79
-
80
- before do
81
- allow(Reek::Configuration::AppConfiguration).
82
- to receive(:from_path).
83
- with(Pathname.new('some_file.reek')).
84
- and_return configuration
85
- end
86
-
87
- it 'uses configuration for excluded paths' do
88
- expected_sources = Reek::Source::SourceLocator.
89
- new(['.'], configuration: configuration).sources
90
- expect(expected_sources).not_to include(path_excluded_in_configuration)
91
-
92
- app.execute
93
-
94
- expect(Reek::CLI::Command::ReportCommand).to have_received(:new).
95
- with(sources: expected_sources,
96
- configuration: configuration,
97
- options: Reek::CLI::Options)
98
- end
99
- end
100
- end
101
-
102
- context 'when source files given' do
103
- let(:app) { described_class.new ['.'] }
104
-
105
- it 'uses sources from argv' do
106
- expected_sources = Reek::Source::SourceLocator.new(['.']).sources
107
- app.execute
108
- expect(Reek::CLI::Command::ReportCommand).to have_received(:new).
109
- with(sources: expected_sources,
110
- configuration: Reek::Configuration::AppConfiguration,
111
- options: Reek::CLI::Options)
112
- end
113
-
114
- context 'when source files are excluded through configuration' do
115
- let(:app) { described_class.new ['--config', 'some_file.reek', '.'] }
116
-
117
- before do
118
- allow(Reek::Configuration::AppConfiguration).
119
- to receive(:from_path).
120
- with(Pathname.new('some_file.reek')).
121
- and_return configuration
122
- end
123
-
124
- it 'uses configuration for excluded paths' do
125
- expected_sources = Reek::Source::SourceLocator.
126
- new(['.'], configuration: configuration).sources
127
- expect(expected_sources).not_to include(path_excluded_in_configuration)
128
-
129
- app.execute
130
-
131
- expect(Reek::CLI::Command::ReportCommand).to have_received(:new).
132
- with(sources: expected_sources,
133
- configuration: configuration,
134
- options: Reek::CLI::Options)
135
- end
136
- end
137
- end
138
- end
139
-
140
- describe 'show configuration path' do
141
- let(:app) { described_class.new ['--show-configuration-path', '.'] }
142
-
143
- around do |example|
144
- Dir.mktmpdir do |tmp|
145
- Dir.chdir(tmp) do
146
- example.run
147
- end
148
- end
149
- end
150
-
151
- context 'when not using any configuration file' do
152
- it 'prints that we are not using any configuration file' do
153
- expect do
154
- app.execute
155
- end.to output("Not using any configuration file.\n").to_stdout
156
- end
157
- end
158
-
159
- context 'with a default configuration file' do
160
- it 'prints that we are using the default configuration file' do
161
- FileUtils.touch '.reek.yml'
162
- expect do
163
- app.execute
164
- end.to output("Using '.reek.yml' as configuration file.\n").to_stdout
165
- end
166
- end
167
- end
168
- end
@@ -1,44 +0,0 @@
1
- require_relative '../../../spec_helper'
2
- require_lib 'reek/cli/command/report_command'
3
- require_lib 'reek/cli/options'
4
-
5
- RSpec.describe Reek::CLI::Command::ReportCommand do
6
- describe '#execute' do
7
- let(:options) { Reek::CLI::Options.new [] }
8
-
9
- let(:configuration) { instance_double 'Reek::Configuration::AppConfiguration' }
10
- let(:sources) { [source_file] }
11
-
12
- let(:command) do
13
- described_class.new(options: options,
14
- sources: sources,
15
- configuration: configuration)
16
- end
17
-
18
- before do
19
- allow(configuration).to receive(:directive_for).and_return({})
20
- end
21
-
22
- context 'when no smells are found' do
23
- let(:source_file) { CLEAN_FILE }
24
-
25
- it 'returns a success code' do
26
- result = Reek::CLI::Silencer.silently do
27
- command.execute
28
- end
29
- expect(result).to eq Reek::CLI::Status::DEFAULT_SUCCESS_EXIT_CODE
30
- end
31
- end
32
-
33
- context 'when smells are found' do
34
- let(:source_file) { SMELLY_FILE }
35
-
36
- it 'returns a failure code' do
37
- result = Reek::CLI::Silencer.silently do
38
- command.execute
39
- end
40
- expect(result).to eq Reek::CLI::Status::DEFAULT_FAILURE_EXIT_CODE
41
- end
42
- end
43
- end
44
- end
@@ -1,86 +0,0 @@
1
- require_relative '../../../spec_helper'
2
- require_lib 'reek/cli/command/todo_list_command'
3
- require_lib 'reek/cli/options'
4
- require_lib 'reek/configuration/app_configuration'
5
-
6
- RSpec.describe Reek::CLI::Command::TodoListCommand do
7
- let(:existing_configuration) do
8
- <<~YAML
9
- ---
10
- detectors:
11
- UncommunicativeMethodName:
12
- exclude:
13
- - Smelly#x
14
- YAML
15
- end
16
-
17
- let(:smelly_file) do
18
- <<~RUBY
19
- # Smelly class
20
- class Smelly
21
- # This will reek of UncommunicativeMethodName
22
- def x
23
- y = 10 # This will reek of UncommunicativeVariableName
24
- end
25
- end
26
- RUBY
27
- end
28
-
29
- let(:new_configuration_file) do
30
- <<~YAML
31
- # Auto generated by Reeks --todo flag
32
- ---
33
- detectors:
34
- UncommunicativeMethodName:
35
- exclude:
36
- - Smelly#x
37
- UncommunicativeVariableName:
38
- exclude:
39
- - Smelly#x
40
- YAML
41
- end
42
-
43
- describe '#execute on smelly source' do
44
- around do |example|
45
- Dir.mktmpdir do |tmp|
46
- Dir.chdir(tmp) do
47
- File.write SMELLY_FILE.basename, smelly_file
48
- example.run
49
- end
50
- end
51
- end
52
-
53
- context 'with default configuration file' do
54
- let(:default_configuration_file_name) { Reek::DEFAULT_CONFIGURATION_FILE_NAME }
55
-
56
- context 'when does not exist yet' do
57
- it 'creates it' do
58
- Reek::CLI::Silencer.silently { todo_command.execute }
59
-
60
- actual_content = File.read(default_configuration_file_name)
61
- expect(actual_content).to match(new_configuration_file)
62
- end
63
- end
64
-
65
- context 'when exists already' do
66
- it 'does not update the configuration' do
67
- File.write default_configuration_file_name, existing_configuration
68
- command = todo_command
69
-
70
- Reek::CLI::Silencer.silently { command.execute }
71
-
72
- actual_content = File.read(default_configuration_file_name)
73
- expect(actual_content).to match(existing_configuration)
74
- end
75
- end
76
- end
77
-
78
- def todo_command(options: Reek::CLI::Options.new([]),
79
- sources: [Pathname.new(SMELLY_FILE.basename.to_s)],
80
- configuration: Reek::Configuration::AppConfiguration.default)
81
- described_class.new options: options,
82
- sources: sources,
83
- configuration: configuration
84
- end
85
- end
86
- end
@@ -1,51 +0,0 @@
1
- require_relative '../../spec_helper'
2
- require_lib 'reek/cli/options'
3
-
4
- RSpec.describe Reek::CLI::Options do
5
- let(:options) { described_class.new }
6
-
7
- describe '#initialize' do
8
- it 'sets a valid default value for report_format' do
9
- expect(options.report_format).to eq :text
10
- end
11
-
12
- it 'sets a valid default value for location_format' do
13
- expect(options.location_format).to eq :numbers
14
- end
15
-
16
- it 'enables colors when stdout is a TTY' do
17
- allow($stdout).to receive_messages(tty?: true)
18
- expect(options.colored).to be true
19
- end
20
-
21
- it 'does not enable colors when stdout is not a TTY' do
22
- allow($stdout).to receive_messages(tty?: false)
23
- expect(options.colored).to be false
24
- end
25
-
26
- it 'enables progress when stdout is a TTY' do
27
- allow($stdout).to receive_messages(tty?: true)
28
- expect(options.progress_format).to eq :dots
29
- end
30
-
31
- it 'does not enable progress when stdout is not a TTY' do
32
- allow($stdout).to receive_messages(tty?: false)
33
- expect(options.progress_format).to eq :quiet
34
- end
35
-
36
- it 'sets force_exclusion to false by default' do
37
- expect(options.force_exclusion?).to be false
38
- end
39
- end
40
-
41
- describe 'parse' do
42
- it 'raises on invalid argument in ARGV' do
43
- options = described_class.new ['-z']
44
- expect { options.parse }.to raise_error(OptionParser::InvalidOption)
45
- end
46
-
47
- it 'returns self' do
48
- expect(options.parse).to be_a(described_class)
49
- end
50
- end
51
- end
@@ -1,28 +0,0 @@
1
- require_relative '../../spec_helper'
2
- require_lib 'reek/cli/silencer'
3
-
4
- RSpec.describe Reek::CLI::Silencer do
5
- describe '.silently' do
6
- it 'blocks output from the block on $stdout' do
7
- expect { described_class.silently { puts 'Hi!' } }.not_to output.to_stdout
8
- end
9
-
10
- it 'blocks output from the block on $stderr' do
11
- expect { described_class.silently { warn 'Hi!' } }.not_to output.to_stderr
12
- end
13
-
14
- it 'restores output on $stdout after the block' do
15
- expect do
16
- described_class.silently { puts 'Hi!' }
17
- puts 'there!'
18
- end.to output("there!\n").to_stdout
19
- end
20
-
21
- it 'restores output on $stderr after the block' do
22
- expect do
23
- described_class.silently { warn 'Hi!' }
24
- warn 'there!'
25
- end.to output("there!\n").to_stderr
26
- end
27
- end
28
- end
@@ -1,184 +0,0 @@
1
- require_relative '../spec_helper'
2
- require_lib 'reek/code_comment'
3
-
4
- RSpec.describe Reek::CodeComment do
5
- context 'with an empty comment' do
6
- let(:comment) { build_code_comment(comment: '') }
7
-
8
- it 'is not descriptive' do
9
- expect(comment).not_to be_descriptive
10
- end
11
-
12
- it 'has an empty config' do
13
- expect(comment.config).to be_empty
14
- end
15
- end
16
-
17
- describe '#descriptive' do
18
- it 'rejects an empty comment' do
19
- comment = build_code_comment(comment: '#')
20
- expect(comment).not_to be_descriptive
21
- end
22
-
23
- it 'rejects a 1-word comment' do
24
- comment = build_code_comment(comment: "# alpha\n# ")
25
- expect(comment).not_to be_descriptive
26
- end
27
-
28
- it 'accepts a 2-word comment' do
29
- comment = build_code_comment(comment: '# alpha bravo ')
30
- expect(comment).to be_descriptive
31
- end
32
-
33
- it 'accepts a multi-word comment' do
34
- comment = build_code_comment(comment: "# alpha bravo \n# charlie \n # delta ")
35
- expect(comment).to be_descriptive
36
- end
37
- end
38
-
39
- describe 'good comment config' do
40
- it 'parses hashed options' do
41
- comment = '# :reek:DuplicateMethodCall { max_calls: 3 }'
42
- config = build_code_comment(comment: comment).config
43
-
44
- expect(config).to include('DuplicateMethodCall')
45
- expect(config['DuplicateMethodCall']).to have_key 'max_calls'
46
- expect(config['DuplicateMethodCall']['max_calls']).to eq 3
47
- end
48
-
49
- it 'parses multiple hashed options' do
50
- comment = <<-RUBY
51
- # :reek:DuplicateMethodCall { max_calls: 3 }
52
- # :reek:NestedIterators { enabled: true }
53
- RUBY
54
- config = build_code_comment(comment: comment).config
55
-
56
- expect(config).to include('DuplicateMethodCall', 'NestedIterators')
57
- expect(config['DuplicateMethodCall']['max_calls']).to eq 3
58
- expect(config['NestedIterators']['enabled']).to be_truthy
59
- end
60
-
61
- it 'parses multiple hashed options on the same line' do
62
- comment = <<-RUBY
63
- #:reek:DuplicateMethodCall { max_calls: 3 } and :reek:NestedIterators { enabled: true }
64
- RUBY
65
- config = build_code_comment(comment: comment).config
66
-
67
- expect(config).to include('DuplicateMethodCall', 'NestedIterators')
68
- expect(config['DuplicateMethodCall']['max_calls']).to eq 3
69
- expect(config['NestedIterators']).to include('enabled')
70
- expect(config['NestedIterators']['enabled']).to be_truthy
71
- end
72
-
73
- it 'parses multiple unhashed options on the same line' do
74
- comment = '# :reek:DuplicateMethodCall and :reek:NestedIterators'
75
- config = build_code_comment(comment: comment).config
76
-
77
- expect(config).to include('DuplicateMethodCall', 'NestedIterators')
78
- expect(config['DuplicateMethodCall']).to include('enabled')
79
- expect(config['DuplicateMethodCall']['enabled']).to be_falsey
80
- expect(config['NestedIterators']).to include('enabled')
81
- expect(config['NestedIterators']['enabled']).to be_falsey
82
- end
83
-
84
- it 'disables the smell if no options are specifed' do
85
- comment = '# :reek:DuplicateMethodCall'
86
- config = build_code_comment(comment: comment).config
87
-
88
- expect(config).to include('DuplicateMethodCall')
89
- expect(config['DuplicateMethodCall']).to include('enabled')
90
- expect(config['DuplicateMethodCall']['enabled']).to be_falsey
91
- end
92
-
93
- it 'does not disable the smell if options are specifed' do
94
- comment = '# :reek:DuplicateMethodCall { max_calls: 3 }'
95
- config = build_code_comment(comment: comment).config
96
-
97
- expect(config['DuplicateMethodCall']).not_to include('enabled')
98
- end
99
-
100
- it 'ignores smells after a space' do
101
- config = build_code_comment(comment: '# :reek: DuplicateMethodCall').config
102
- expect(config).not_to include('DuplicateMethodCall')
103
- end
104
-
105
- it 'removes the configuration options from the comment' do
106
- original_comment = <<-RUBY
107
- # Actual
108
- # :reek:DuplicateMethodCall { max_calls: 3 }
109
- # :reek:NestedIterators { enabled: true }
110
- # comment
111
- RUBY
112
- comment = build_code_comment(comment: original_comment)
113
-
114
- expect(comment.send(:sanitized_comment)).to eq('Actual comment')
115
- end
116
- end
117
- end
118
-
119
- RSpec.describe Reek::CodeComment::CodeCommentValidator do
120
- context 'when the comment contains an unknown detector name' do
121
- it 'raises BadDetectorInCommentError' do
122
- expect do
123
- build_code_comment(comment: '# :reek:DoesNotExist')
124
- end.to raise_error(Reek::Errors::BadDetectorInCommentError)
125
- end
126
- end
127
-
128
- context 'when the comment contains an unparsable detector configuration' do
129
- it 'raises GarbageDetectorConfigurationInCommentError' do
130
- expect do
131
- comment = '# :reek:UncommunicativeMethodName { thats: a: bad: config }'
132
- build_code_comment(comment: comment)
133
- end.to raise_error(Reek::Errors::GarbageDetectorConfigurationInCommentError)
134
- end
135
- end
136
-
137
- context 'when the legacy comment format was used' do
138
- it 'raises LegacyCommentSeparatorError' do
139
- comment = '# :reek:DuplicateMethodCall:'
140
- expect { build_code_comment(comment: comment) }.
141
- to raise_error Reek::Errors::LegacyCommentSeparatorError
142
- end
143
- end
144
-
145
- describe 'validating configuration keys' do
146
- context 'when basic options are mispelled' do
147
- it 'raises BadDetectorConfigurationKeyInCommentError' do
148
- expect do
149
- # exclude -> exlude and enabled -> nabled
150
- comment = '# :reek:UncommunicativeMethodName { exlude: alfa, nabled: true }'
151
- build_code_comment(comment: comment)
152
- end.to raise_error(Reek::Errors::BadDetectorConfigurationKeyInCommentError)
153
- end
154
- end
155
-
156
- context 'when basic options are not mispelled' do
157
- it 'does not raise' do
158
- expect do
159
- comment = '# :reek:UncommunicativeMethodName { exclude: alfa, enabled: true }'
160
- build_code_comment(comment: comment)
161
- end.not_to raise_error
162
- end
163
- end
164
-
165
- context 'when unknown custom options are specified' do
166
- it 'raises BadDetectorConfigurationKeyInCommentError' do
167
- expect do
168
- # max_copies -> mx_copies and min_clump_size -> mn_clump_size
169
- comment = '# :reek:DataClump { mx_copies: 4, mn_clump_size: 3 }'
170
- build_code_comment(comment: comment)
171
- end.to raise_error(Reek::Errors::BadDetectorConfigurationKeyInCommentError)
172
- end
173
- end
174
-
175
- context 'when valid custom options are specified' do
176
- it 'does not raise' do
177
- expect do
178
- comment = '# :reek:DataClump { max_copies: 4, min_clump_size: 3 }'
179
- build_code_comment(comment: comment)
180
- end.not_to raise_error
181
- end
182
- end
183
- end
184
- end