reek 6.0.3 → 6.0.4

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.
Files changed (217) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -1
  3. data/CONTRIBUTING.md +3 -0
  4. data/Dockerfile +1 -1
  5. data/Gemfile +6 -6
  6. data/lib/reek/ast/ast_node_class_map.rb +1 -1
  7. data/lib/reek/report/code_climate/code_climate_formatter.rb +1 -3
  8. data/lib/reek/smell_detectors/base_detector.rb +1 -1
  9. data/lib/reek/smell_warning.rb +1 -1
  10. data/lib/reek/source/source_locator.rb +1 -3
  11. data/lib/reek/version.rb +1 -1
  12. data/reek.gemspec +4 -1
  13. metadata +3 -208
  14. data/docs/API.md +0 -174
  15. data/docs/Attribute.md +0 -39
  16. data/docs/Basic-Smell-Options.md +0 -85
  17. data/docs/Boolean-Parameter.md +0 -54
  18. data/docs/Class-Variable.md +0 -40
  19. data/docs/Code-Smells.md +0 -39
  20. data/docs/Command-Line-Options.md +0 -119
  21. data/docs/Control-Couple.md +0 -26
  22. data/docs/Control-Parameter.md +0 -32
  23. data/docs/Data-Clump.md +0 -46
  24. data/docs/Duplicate-Method-Call.md +0 -264
  25. data/docs/Feature-Envy.md +0 -93
  26. data/docs/How-To-Write-New-Detectors.md +0 -132
  27. data/docs/How-reek-works-internally.md +0 -114
  28. data/docs/Instance-Variable-Assumption.md +0 -163
  29. data/docs/Irresponsible-Module.md +0 -47
  30. data/docs/Large-Class.md +0 -16
  31. data/docs/Long-Parameter-List.md +0 -39
  32. data/docs/Long-Yield-List.md +0 -37
  33. data/docs/Manual-Dispatch.md +0 -30
  34. data/docs/Missing-Safe-Method.md +0 -92
  35. data/docs/Module-Initialize.md +0 -62
  36. data/docs/Nested-Iterators.md +0 -59
  37. data/docs/Nil-Check.md +0 -47
  38. data/docs/RSpec-matchers.md +0 -129
  39. data/docs/Rake-Task.md +0 -66
  40. data/docs/Reek-4-to-Reek-5-migration.md +0 -188
  41. data/docs/Reek-Driven-Development.md +0 -46
  42. data/docs/Repeated-Conditional.md +0 -47
  43. data/docs/Simulated-Polymorphism.md +0 -16
  44. data/docs/Smell-Suppression.md +0 -96
  45. data/docs/Style-Guide.md +0 -19
  46. data/docs/Subclassed-From-Core-Class.md +0 -79
  47. data/docs/Too-Many-Constants.md +0 -37
  48. data/docs/Too-Many-Instance-Variables.md +0 -43
  49. data/docs/Too-Many-Methods.md +0 -56
  50. data/docs/Too-Many-Statements.md +0 -54
  51. data/docs/Uncommunicative-Method-Name.md +0 -94
  52. data/docs/Uncommunicative-Module-Name.md +0 -92
  53. data/docs/Uncommunicative-Name.md +0 -18
  54. data/docs/Uncommunicative-Parameter-Name.md +0 -90
  55. data/docs/Uncommunicative-Variable-Name.md +0 -96
  56. data/docs/Unused-Parameters.md +0 -28
  57. data/docs/Unused-Private-Method.md +0 -101
  58. data/docs/Utility-Function.md +0 -56
  59. data/docs/Versioning-Policy.md +0 -7
  60. data/docs/YAML-Reports.md +0 -93
  61. data/docs/defaults.reek.yml +0 -129
  62. data/docs/templates/default/docstring/html/public_api_marker.erb +0 -3
  63. data/docs/templates/default/docstring/setup.rb +0 -35
  64. data/docs/templates/default/fulldoc/html/css/common.css +0 -1
  65. data/docs/yard_plugin.rb +0 -17
  66. data/features/command_line_interface/basic_usage.feature +0 -15
  67. data/features/command_line_interface/options.feature +0 -123
  68. data/features/command_line_interface/show_progress.feature +0 -33
  69. data/features/command_line_interface/smell_selection.feature +0 -15
  70. data/features/command_line_interface/smells_count.feature +0 -38
  71. data/features/command_line_interface/stdin.feature +0 -65
  72. data/features/configuration_files/accept_setting.feature +0 -87
  73. data/features/configuration_files/directory_specific_directives.feature +0 -274
  74. data/features/configuration_files/exclude_directives.feature +0 -35
  75. data/features/configuration_files/exclude_paths_directives.feature +0 -42
  76. data/features/configuration_files/masking_smells.feature +0 -94
  77. data/features/configuration_files/mix_accept_reject_setting.feature +0 -84
  78. data/features/configuration_files/reject_setting.feature +0 -89
  79. data/features/configuration_files/schema_validation.feature +0 -59
  80. data/features/configuration_files/show_configuration_file.feature +0 -44
  81. data/features/configuration_files/unused_private_method.feature +0 -68
  82. data/features/configuration_loading.feature +0 -91
  83. data/features/configuration_via_source_comments/erroneous_source_comments.feature +0 -68
  84. data/features/configuration_via_source_comments/well_formed_source_comments.feature +0 -116
  85. data/features/locales.feature +0 -32
  86. data/features/programmatic_access.feature +0 -41
  87. data/features/rake_task/rake_task.feature +0 -138
  88. data/features/reports/codeclimate.feature +0 -59
  89. data/features/reports/json.feature +0 -59
  90. data/features/reports/reports.feature +0 -219
  91. data/features/reports/yaml.feature +0 -52
  92. data/features/rspec_matcher.feature +0 -41
  93. data/features/samples.feature +0 -305
  94. data/features/step_definitions/.rubocop.yml +0 -5
  95. data/features/step_definitions/reek_steps.rb +0 -102
  96. data/features/step_definitions/sample_file_steps.rb +0 -63
  97. data/features/support/env.rb +0 -33
  98. data/features/todo_list.feature +0 -108
  99. data/samples/checkstyle.xml +0 -7
  100. data/samples/clean_source/clean.rb +0 -6
  101. data/samples/configuration/accepts_rejects_and_excludes_for_detectors.reek.yml +0 -29
  102. data/samples/configuration/accepts_rejects_and_excludes_for_directory_directives.reek.yml +0 -30
  103. data/samples/configuration/corrupt.reek +0 -1
  104. data/samples/configuration/empty.reek +0 -0
  105. data/samples/configuration/full_configuration.reek +0 -13
  106. data/samples/configuration/full_mask.reek +0 -6
  107. data/samples/configuration/home/home.reek.yml +0 -4
  108. data/samples/configuration/partial_mask.reek +0 -4
  109. data/samples/configuration/regular_configuration/.reek.yml +0 -4
  110. data/samples/configuration/regular_configuration/empty_sub_directory/.gitignore +0 -0
  111. data/samples/configuration/with_excluded_paths.reek +0 -5
  112. data/samples/no_config_file/.keep +0 -0
  113. data/samples/paths.rb +0 -5
  114. data/samples/smelly_source/inline.rb +0 -704
  115. data/samples/smelly_source/optparse.rb +0 -1788
  116. data/samples/smelly_source/redcloth.rb +0 -1130
  117. data/samples/smelly_source/ruby.rb +0 -368
  118. data/samples/smelly_source/smelly.rb +0 -7
  119. data/samples/source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb +0 -5
  120. data/samples/source_with_exclude_paths/nested/ignore_me_as_well/irresponsible_module.rb +0 -2
  121. data/samples/source_with_exclude_paths/nested/uncommunicative_parameter_name.rb +0 -6
  122. data/samples/source_with_exclude_paths/nested/uncommunicative_variable_name.rb +0 -6
  123. data/samples/source_with_hidden_directories/.hidden/hidden.rb +0 -1
  124. data/samples/source_with_hidden_directories/not_hidden.rb +0 -1
  125. data/samples/source_with_non_ruby_files/gibberish +0 -1
  126. data/samples/source_with_non_ruby_files/python_source.py +0 -1
  127. data/samples/source_with_non_ruby_files/ruby.rb +0 -6
  128. data/spec/performance/reek/smell_detectors/runtime_speed_spec.rb +0 -15
  129. data/spec/quality/documentation_spec.rb +0 -41
  130. data/spec/quality/reek_source_spec.rb +0 -11
  131. data/spec/reek/ast/node_spec.rb +0 -211
  132. data/spec/reek/ast/object_refs_spec.rb +0 -83
  133. data/spec/reek/ast/reference_collector_spec.rb +0 -47
  134. data/spec/reek/ast/sexp_extensions_spec.rb +0 -498
  135. data/spec/reek/cli/application_spec.rb +0 -168
  136. data/spec/reek/cli/command/report_command_spec.rb +0 -44
  137. data/spec/reek/cli/command/todo_list_command_spec.rb +0 -86
  138. data/spec/reek/cli/options_spec.rb +0 -51
  139. data/spec/reek/cli/silencer_spec.rb +0 -28
  140. data/spec/reek/code_comment_spec.rb +0 -184
  141. data/spec/reek/configuration/app_configuration_spec.rb +0 -195
  142. data/spec/reek/configuration/configuration_file_finder_spec.rb +0 -230
  143. data/spec/reek/configuration/default_directive_spec.rb +0 -13
  144. data/spec/reek/configuration/directory_directives_spec.rb +0 -122
  145. data/spec/reek/configuration/excluded_paths_spec.rb +0 -25
  146. data/spec/reek/configuration/rake_task_converter_spec.rb +0 -33
  147. data/spec/reek/configuration/schema_validator_spec.rb +0 -165
  148. data/spec/reek/context/code_context_spec.rb +0 -192
  149. data/spec/reek/context/ghost_context_spec.rb +0 -60
  150. data/spec/reek/context/method_context_spec.rb +0 -72
  151. data/spec/reek/context/module_context_spec.rb +0 -55
  152. data/spec/reek/context/root_context_spec.rb +0 -12
  153. data/spec/reek/context/statement_counter_spec.rb +0 -24
  154. data/spec/reek/context_builder_spec.rb +0 -457
  155. data/spec/reek/detector_repository_spec.rb +0 -22
  156. data/spec/reek/documentation_link_spec.rb +0 -20
  157. data/spec/reek/errors/base_error_spec.rb +0 -13
  158. data/spec/reek/examiner_spec.rb +0 -309
  159. data/spec/reek/logging_error_handler_spec.rb +0 -24
  160. data/spec/reek/rake/task_spec.rb +0 -56
  161. data/spec/reek/report/code_climate/code_climate_configuration_spec.rb +0 -22
  162. data/spec/reek/report/code_climate/code_climate_fingerprint_spec.rb +0 -126
  163. data/spec/reek/report/code_climate/code_climate_formatter_spec.rb +0 -51
  164. data/spec/reek/report/code_climate/code_climate_report_spec.rb +0 -56
  165. data/spec/reek/report/html_report_spec.rb +0 -19
  166. data/spec/reek/report/json_report_spec.rb +0 -58
  167. data/spec/reek/report/location_formatter_spec.rb +0 -32
  168. data/spec/reek/report/progress_formatter_spec.rb +0 -68
  169. data/spec/reek/report/text_report_spec.rb +0 -89
  170. data/spec/reek/report/xml_report_spec.rb +0 -24
  171. data/spec/reek/report/yaml_report_spec.rb +0 -55
  172. data/spec/reek/report_spec.rb +0 -28
  173. data/spec/reek/smell_configuration_spec.rb +0 -56
  174. data/spec/reek/smell_detectors/attribute_spec.rb +0 -197
  175. data/spec/reek/smell_detectors/base_detector_spec.rb +0 -50
  176. data/spec/reek/smell_detectors/boolean_parameter_spec.rb +0 -93
  177. data/spec/reek/smell_detectors/class_variable_spec.rb +0 -106
  178. data/spec/reek/smell_detectors/control_parameter_spec.rb +0 -300
  179. data/spec/reek/smell_detectors/data_clump_spec.rb +0 -134
  180. data/spec/reek/smell_detectors/duplicate_method_call_spec.rb +0 -211
  181. data/spec/reek/smell_detectors/feature_envy_spec.rb +0 -295
  182. data/spec/reek/smell_detectors/instance_variable_assumption_spec.rb +0 -96
  183. data/spec/reek/smell_detectors/irresponsible_module_spec.rb +0 -226
  184. data/spec/reek/smell_detectors/long_parameter_list_spec.rb +0 -61
  185. data/spec/reek/smell_detectors/long_yield_list_spec.rb +0 -49
  186. data/spec/reek/smell_detectors/manual_dispatch_spec.rb +0 -75
  187. data/spec/reek/smell_detectors/missing_safe_method_spec.rb +0 -68
  188. data/spec/reek/smell_detectors/module_initialize_spec.rb +0 -77
  189. data/spec/reek/smell_detectors/nested_iterators_spec.rb +0 -333
  190. data/spec/reek/smell_detectors/nil_check_spec.rb +0 -100
  191. data/spec/reek/smell_detectors/repeated_conditional_spec.rb +0 -100
  192. data/spec/reek/smell_detectors/subclassed_from_core_class_spec.rb +0 -77
  193. data/spec/reek/smell_detectors/too_many_constants_spec.rb +0 -144
  194. data/spec/reek/smell_detectors/too_many_instance_variables_spec.rb +0 -132
  195. data/spec/reek/smell_detectors/too_many_methods_spec.rb +0 -54
  196. data/spec/reek/smell_detectors/too_many_statements_spec.rb +0 -90
  197. data/spec/reek/smell_detectors/uncommunicative_method_name_spec.rb +0 -78
  198. data/spec/reek/smell_detectors/uncommunicative_module_name_spec.rb +0 -78
  199. data/spec/reek/smell_detectors/uncommunicative_parameter_name_spec.rb +0 -147
  200. data/spec/reek/smell_detectors/uncommunicative_variable_name_spec.rb +0 -201
  201. data/spec/reek/smell_detectors/unused_parameters_spec.rb +0 -114
  202. data/spec/reek/smell_detectors/unused_private_method_spec.rb +0 -205
  203. data/spec/reek/smell_detectors/utility_function_spec.rb +0 -309
  204. data/spec/reek/smell_warning_spec.rb +0 -137
  205. data/spec/reek/source/source_code_spec.rb +0 -79
  206. data/spec/reek/source/source_locator_spec.rb +0 -166
  207. data/spec/reek/spec/should_reek_of_spec.rb +0 -153
  208. data/spec/reek/spec/should_reek_only_of_spec.rb +0 -91
  209. data/spec/reek/spec/should_reek_spec.rb +0 -52
  210. data/spec/reek/spec/smell_matcher_spec.rb +0 -87
  211. data/spec/reek/tree_dresser_spec.rb +0 -46
  212. data/spec/spec_helper.rb +0 -110
  213. data/tasks/configuration.rake +0 -18
  214. data/tasks/console.rake +0 -5
  215. data/tasks/reek.rake +0 -6
  216. data/tasks/rubocop.rake +0 -11
  217. 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