reek 2.0.4 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +13 -0
  3. data/.rubocop.yml +66 -0
  4. data/.ruby-gemset +1 -0
  5. data/.travis.yml +25 -0
  6. data/CHANGELOG +6 -0
  7. data/CONTRIBUTING.md +106 -0
  8. data/Gemfile +14 -0
  9. data/README.md +16 -21
  10. data/bin/reek +2 -2
  11. data/config/cucumber.yml +3 -0
  12. data/config/defaults.reek +1 -1
  13. data/features/command_line_interface/smell_selection.feature +4 -8
  14. data/features/command_line_interface/smells_count.feature +25 -32
  15. data/features/command_line_interface/stdin.feature +2 -2
  16. data/features/configuration_files/masking_smells.feature +30 -41
  17. data/features/configuration_files/overrides_defaults.feature +5 -3
  18. data/features/configuration_loading.feature +26 -23
  19. data/features/programmatic_access.feature +24 -0
  20. data/features/rake_task/rake_task.feature +25 -22
  21. data/features/reports/json.feature +24 -26
  22. data/features/reports/reports.feature +77 -103
  23. data/features/reports/yaml.feature +26 -20
  24. data/features/ruby_api/api.feature +4 -3
  25. data/features/samples.feature +21 -20
  26. data/features/step_definitions/.rubocop.yml +5 -0
  27. data/features/step_definitions/reek_steps.rb +16 -28
  28. data/features/step_definitions/sample_file_steps.rb +158 -0
  29. data/features/support/env.rb +16 -27
  30. data/lib/reek.rb +3 -3
  31. data/lib/reek/cli/application.rb +4 -4
  32. data/lib/reek/cli/command.rb +1 -1
  33. data/lib/reek/cli/input.rb +2 -4
  34. data/lib/reek/cli/option_interpreter.rb +9 -9
  35. data/lib/reek/cli/options.rb +5 -4
  36. data/lib/reek/cli/reek_command.rb +3 -3
  37. data/lib/reek/cli/report/formatter.rb +2 -2
  38. data/lib/reek/cli/report/heading_formatter.rb +1 -1
  39. data/lib/reek/cli/report/location_formatter.rb +1 -1
  40. data/lib/reek/cli/report/report.rb +4 -4
  41. data/lib/reek/configuration/app_configuration.rb +1 -1
  42. data/lib/reek/configuration/configuration_file_finder.rb +17 -32
  43. data/lib/reek/core/code_context.rb +1 -1
  44. data/lib/reek/core/method_context.rb +6 -2
  45. data/lib/reek/core/module_context.rb +2 -2
  46. data/lib/reek/core/singleton_method_context.rb +1 -1
  47. data/lib/reek/core/smell_repository.rb +3 -2
  48. data/lib/reek/core/tree_walker.rb +4 -4
  49. data/lib/reek/examiner.rb +4 -4
  50. data/lib/reek/smells/attribute.rb +3 -3
  51. data/lib/reek/smells/boolean_parameter.rb +2 -2
  52. data/lib/reek/smells/class_variable.rb +2 -2
  53. data/lib/reek/smells/control_parameter.rb +2 -2
  54. data/lib/reek/smells/data_clump.rb +2 -3
  55. data/lib/reek/smells/duplicate_method_call.rb +2 -2
  56. data/lib/reek/smells/feature_envy.rb +6 -2
  57. data/lib/reek/smells/irresponsible_module.rb +3 -3
  58. data/lib/reek/smells/long_parameter_list.rb +3 -3
  59. data/lib/reek/smells/long_yield_list.rb +2 -2
  60. data/lib/reek/smells/module_initialize.rb +2 -2
  61. data/lib/reek/smells/nested_iterators.rb +2 -2
  62. data/lib/reek/smells/nil_check.rb +2 -2
  63. data/lib/reek/smells/prima_donna_method.rb +2 -2
  64. data/lib/reek/smells/repeated_conditional.rb +3 -2
  65. data/lib/reek/smells/smell_detector.rb +2 -2
  66. data/lib/reek/smells/too_many_instance_variables.rb +2 -2
  67. data/lib/reek/smells/too_many_methods.rb +2 -2
  68. data/lib/reek/smells/too_many_statements.rb +2 -2
  69. data/lib/reek/smells/uncommunicative_method_name.rb +2 -2
  70. data/lib/reek/smells/uncommunicative_module_name.rb +2 -2
  71. data/lib/reek/smells/uncommunicative_parameter_name.rb +2 -2
  72. data/lib/reek/smells/uncommunicative_variable_name.rb +2 -2
  73. data/lib/reek/smells/unused_parameters.rb +2 -2
  74. data/lib/reek/smells/utility_function.rb +8 -9
  75. data/lib/reek/source/ast_node.rb +1 -1
  76. data/lib/reek/source/ast_node_class_map.rb +6 -6
  77. data/lib/reek/source/sexp_extensions.rb +11 -2
  78. data/lib/reek/source/source_code.rb +10 -2
  79. data/lib/reek/source/source_locator.rb +1 -3
  80. data/lib/reek/source/source_repository.rb +3 -4
  81. data/lib/reek/source/tree_dresser.rb +2 -2
  82. data/lib/reek/spec.rb +3 -3
  83. data/lib/reek/spec/should_reek.rb +3 -3
  84. data/lib/reek/spec/should_reek_of.rb +1 -1
  85. data/lib/reek/spec/should_reek_only_of.rb +3 -3
  86. data/lib/reek/version.rb +1 -1
  87. data/reek.gemspec +18 -24
  88. data/spec/factories/factories.rb +1 -1
  89. data/spec/gem/updates_spec.rb +1 -1
  90. data/spec/gem/yard_spec.rb +1 -1
  91. data/spec/quality/reek_source_spec.rb +1 -1
  92. data/spec/reek/cli/html_report_spec.rb +6 -9
  93. data/spec/reek/cli/json_report_spec.rb +6 -6
  94. data/spec/reek/cli/option_interperter_spec.rb +5 -5
  95. data/spec/reek/cli/text_report_spec.rb +16 -19
  96. data/spec/reek/cli/yaml_report_spec.rb +7 -10
  97. data/spec/reek/configuration/app_configuration_spec.rb +23 -25
  98. data/spec/reek/configuration/configuration_file_finder_spec.rb +46 -21
  99. data/spec/reek/core/code_context_spec.rb +17 -19
  100. data/spec/reek/core/method_context_spec.rb +15 -14
  101. data/spec/reek/core/module_context_spec.rb +5 -7
  102. data/spec/reek/core/object_refs_spec.rb +4 -6
  103. data/spec/reek/core/singleton_method_context_spec.rb +5 -7
  104. data/spec/reek/core/smell_configuration_spec.rb +5 -7
  105. data/spec/reek/core/smell_repository_spec.rb +8 -8
  106. data/spec/reek/core/stop_context_spec.rb +4 -7
  107. data/spec/reek/core/tree_walker_spec.rb +5 -7
  108. data/spec/reek/core/warning_collector_spec.rb +5 -7
  109. data/spec/reek/examiner_spec.rb +10 -12
  110. data/spec/reek/smell_warning_spec.rb +7 -9
  111. data/spec/reek/smells/attribute_spec.rb +6 -6
  112. data/spec/reek/smells/boolean_parameter_spec.rb +4 -4
  113. data/spec/reek/smells/class_variable_spec.rb +6 -6
  114. data/spec/reek/smells/control_parameter_spec.rb +4 -4
  115. data/spec/reek/smells/data_clump_spec.rb +4 -4
  116. data/spec/reek/smells/duplicate_method_call_spec.rb +6 -6
  117. data/spec/reek/smells/feature_envy_spec.rb +9 -10
  118. data/spec/reek/smells/irresponsible_module_spec.rb +7 -7
  119. data/spec/reek/smells/long_parameter_list_spec.rb +5 -5
  120. data/spec/reek/smells/long_yield_list_spec.rb +5 -5
  121. data/spec/reek/smells/module_initialize_spec.rb +3 -3
  122. data/spec/reek/smells/nested_iterators_spec.rb +4 -4
  123. data/spec/reek/smells/nil_check_spec.rb +5 -5
  124. data/spec/reek/smells/prima_donna_method_spec.rb +7 -4
  125. data/spec/reek/smells/repeated_conditional_spec.rb +12 -11
  126. data/spec/reek/smells/smell_detector_shared.rb +4 -5
  127. data/spec/reek/smells/too_many_instance_variables_spec.rb +4 -4
  128. data/spec/reek/smells/too_many_methods_spec.rb +11 -7
  129. data/spec/reek/smells/too_many_statements_spec.rb +6 -5
  130. data/spec/reek/smells/uncommunicative_method_name_spec.rb +4 -4
  131. data/spec/reek/smells/uncommunicative_module_name_spec.rb +7 -7
  132. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +5 -5
  133. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +9 -6
  134. data/spec/reek/smells/unused_parameters_spec.rb +3 -3
  135. data/spec/reek/smells/utility_function_spec.rb +41 -37
  136. data/spec/reek/source/code_comment_spec.rb +19 -17
  137. data/spec/reek/source/object_source_spec.rb +1 -3
  138. data/spec/reek/source/reference_collector_spec.rb +5 -6
  139. data/spec/reek/source/sexp_extensions_spec.rb +9 -11
  140. data/spec/reek/source/sexp_formatter_spec.rb +7 -8
  141. data/spec/reek/source/sexp_node_spec.rb +3 -5
  142. data/spec/reek/source/source_code_spec.rb +9 -9
  143. data/spec/reek/source/tree_dresser_spec.rb +4 -6
  144. data/spec/reek/spec/should_reek_of_spec.rb +11 -10
  145. data/spec/reek/spec/should_reek_only_of_spec.rb +4 -7
  146. data/spec/reek/spec/should_reek_spec.rb +4 -7
  147. data/spec/samples/{overrides/masked/lower.reek → masked_by_dotfile/.reek} +3 -1
  148. data/spec/spec_helper.rb +4 -4
  149. data/tasks/develop.rake +1 -1
  150. data/tasks/reek.rake +1 -1
  151. metadata +72 -86
  152. data/features/support/hooks.rb +0 -15
  153. data/lib/reek/source.rb +0 -16
  154. data/lib/reek/source/core_extras.rb +0 -46
  155. data/lib/reek/source/source_file.rb +0 -16
  156. data/spec/samples/config/allow_duplication.reek +0 -3
  157. data/spec/samples/config/deeper_nested_iterators.reek +0 -3
  158. data/spec/samples/configuration_loading/minimal_dirty.rb +0 -4
  159. data/spec/samples/configuration_loading/reek-test-run-disable_smells.reek +0 -7
  160. data/spec/samples/configuration_loading/reek-test-run-enable_smells.reek +0 -7
  161. data/spec/samples/corrupt_config_file/corrupt.reek +0 -1
  162. data/spec/samples/corrupt_config_file/dirty.rb +0 -8
  163. data/spec/samples/demo/demo.rb +0 -8
  164. data/spec/samples/empty_config_file/dirty.rb +0 -8
  165. data/spec/samples/empty_config_file/empty.reek +0 -0
  166. data/spec/samples/inline_config/dirty.rb +0 -16
  167. data/spec/samples/inline_config/masked.reek +0 -7
  168. data/spec/samples/mask_some/dirty.rb +0 -8
  169. data/spec/samples/mask_some/some.reek +0 -8
  170. data/spec/samples/masked/dirty.rb +0 -8
  171. data/spec/samples/masked/masked.reek +0 -5
  172. data/spec/samples/minimal_smelly_and_masked/config.reek +0 -7
  173. data/spec/samples/minimal_smelly_and_masked/minimal_dirty.rb +0 -4
  174. data/spec/samples/mixed_results/clean_one.rb +0 -7
  175. data/spec/samples/mixed_results/clean_three.rb +0 -7
  176. data/spec/samples/mixed_results/clean_two.rb +0 -7
  177. data/spec/samples/mixed_results/dirty_one.rb +0 -8
  178. data/spec/samples/mixed_results/dirty_two.rb +0 -8
  179. data/spec/samples/not_quite_masked/dirty.rb +0 -8
  180. data/spec/samples/not_quite_masked/masked.reek +0 -5
  181. data/spec/samples/not_quite_masked/smelly.rb +0 -3
  182. data/spec/samples/one_smelly_file/dirty.rb +0 -3
  183. data/spec/samples/overrides/masked/dirty.rb +0 -8
  184. data/spec/samples/overrides/upper.reek +0 -5
  185. data/spec/samples/overrides_defaults/camel_case.rb +0 -14
  186. data/spec/samples/overrides_defaults/config.reek +0 -6
  187. data/spec/samples/standard_smelly/dirty.rb +0 -8
  188. data/spec/samples/standard_smelly/minimal_dirty.rb +0 -4
  189. data/spec/samples/three_smelly_files/dirty_one.rb +0 -3
  190. data/spec/samples/three_smelly_files/dirty_three.rb +0 -5
  191. data/spec/samples/three_smelly_files/dirty_two.rb +0 -4
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
2
- require 'reek/smells/uncommunicative_parameter_name'
3
- require 'reek/smells/smell_detector_shared'
4
- require 'reek/core/method_context'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/uncommunicative_parameter_name'
3
+ require_relative 'smell_detector_shared'
4
+ require_relative '../../../lib/reek/core/method_context'
5
5
 
6
6
  describe Reek::Smells::UncommunicativeParameterName do
7
7
  before :each do
@@ -69,7 +69,7 @@ describe Reek::Smells::UncommunicativeParameterName do
69
69
  context 'looking at the smell result fields' do
70
70
  before :each do
71
71
  src = 'def bad(good, bad2, good_again); basics(good, bad2, good_again); end'
72
- ctx = Reek::Core::MethodContext.new(nil, src.to_reek_source.syntax_tree)
72
+ ctx = Reek::Core::MethodContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
73
73
  @smells = @detector.examine_context(ctx)
74
74
  @warning = @smells[0]
75
75
  end
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
2
- require 'reek/smells/uncommunicative_variable_name'
3
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/uncommunicative_variable_name'
3
+ require_relative 'smell_detector_shared'
4
4
 
5
5
  describe Reek::Smells::UncommunicativeVariableName do
6
6
  before :each do
@@ -52,7 +52,8 @@ describe Reek::Smells::UncommunicativeVariableName do
52
52
 
53
53
  it 'reports variable name only once' do
54
54
  src = 'def simple(fred) x = jim(45); x = y end'
55
- ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
55
+ syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
56
+ ctx = Reek::Core::CodeContext.new(nil, syntax_tree)
56
57
  smells = @detector.examine_context(ctx)
57
58
  expect(smells.length).to eq(1)
58
59
  expect(smells[0].smell_type).to eq(described_class.smell_type)
@@ -163,7 +164,8 @@ describe Reek::Smells::UncommunicativeVariableName do
163
164
  end
164
165
  end
165
166
  EOS
166
- ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
167
+ syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
168
+ ctx = Reek::Core::CodeContext.new(nil, syntax_tree)
167
169
  @smells = @detector.examine_context(ctx)
168
170
  @warning = @smells[0]
169
171
  end
@@ -179,7 +181,8 @@ describe Reek::Smells::UncommunicativeVariableName do
179
181
  context 'when a smell is reported in a singleton method' do
180
182
  before :each do
181
183
  src = 'def self.bad() x2 = 4; end'
182
- ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
184
+ syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
185
+ ctx = Reek::Core::CodeContext.new(nil, syntax_tree)
183
186
  @smells = @detector.examine_context(ctx)
184
187
  @warning = @smells[0]
185
188
  end
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
2
- require 'reek/smells/unused_parameters'
3
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/unused_parameters'
3
+ require_relative 'smell_detector_shared'
4
4
 
5
5
  describe Reek::Smells::UnusedParameters do
6
6
  context 'for methods' do
@@ -1,30 +1,50 @@
1
- require 'spec_helper'
2
- require 'reek/smells/utility_function'
3
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/utility_function'
3
+ require_relative 'smell_detector_shared'
4
4
 
5
5
  describe Reek::Smells::UtilityFunction do
6
- before(:each) do
7
- @source_name = 'dummy_source'
8
- @detector = build(:smell_detector, smell_type: :UtilityFunction, source: @source_name)
9
- end
6
+ describe 'a detector' do
7
+ before(:each) do
8
+ @source_name = 'dummy_source'
9
+ @detector = build(:smell_detector,
10
+ smell_type: :UtilityFunction,
11
+ source: @source_name)
12
+ end
13
+
14
+ it_should_behave_like 'SmellDetector'
15
+
16
+ context 'when a smells is reported' do
17
+ before :each do
18
+ src = <<-EOS
19
+ def simple(arga)
20
+ arga.b.c
21
+ end
22
+ EOS
23
+ source = Reek::Source::SourceCode.from(src)
24
+ mctx = Reek::Core::TreeWalker.new.process_def(source.syntax_tree)
25
+ @warning = @detector.examine_context(mctx)[0] # SMELL: too cumbersome!
26
+ end
27
+
28
+ it_should_behave_like 'common fields set correctly'
10
29
 
11
- it_should_behave_like 'SmellDetector'
30
+ it 'reports the line number of the method' do
31
+ expect(@warning.lines).to eq([1])
32
+ end
33
+ end
34
+ end
12
35
 
13
36
  context 'with a singleton method' do
14
37
  ['self', 'local_call', '$global'].each do |receiver|
15
38
  it 'ignores the receiver' do
16
39
  src = "def #{receiver}.simple(arga) arga.to_s + arga.to_i end"
17
- ctx = Reek::Core::MethodContext.new(nil, src.to_reek_source.syntax_tree)
18
- expect(@detector.examine_context(ctx)).to be_empty
40
+ expect(src).not_to reek_of(:UtilityFunction)
19
41
  end
20
42
  end
21
43
  end
22
44
 
23
45
  context 'with no calls' do
24
46
  it 'does not report empty method' do
25
- src = 'def simple(arga) end'
26
- ctx = Reek::Core::MethodContext.new(nil, src.to_reek_source.syntax_tree)
27
- expect(@detector.examine_context(ctx)).to be_empty
47
+ expect('def simple(arga) end').not_to reek_of(:UtilityFunction)
28
48
  end
29
49
 
30
50
  it 'does not report literal' do
@@ -53,12 +73,12 @@ describe Reek::Smells::UtilityFunction do
53
73
  end
54
74
 
55
75
  context 'with only one call' do
56
- it 'does not report a call to a parameter' do
57
- expect('def simple(arga) arga.to_s end').not_to reek_of(:UtilityFunction, name: 'simple')
76
+ it 'reports a call to a parameter' do
77
+ expect('def simple(arga) arga.to_s end').to reek_of(:UtilityFunction, name: 'simple')
58
78
  end
59
79
 
60
- it 'does not report a call to a constant' do
61
- expect('def simple(arga) FIELDS[arga] end').not_to reek_of(:UtilityFunction)
80
+ it 'reports a call to a constant' do
81
+ expect('def simple(arga) FIELDS[arga] end').to reek_of(:UtilityFunction)
62
82
  end
63
83
  end
64
84
 
@@ -66,6 +86,7 @@ describe Reek::Smells::UtilityFunction do
66
86
  it 'reports two calls' do
67
87
  src = 'def simple(arga) arga.to_s + arga.to_i end'
68
88
  expect(src).to reek_of(:UtilityFunction, name: 'simple')
89
+ expect(src).not_to reek_of(:FeatureEnvy)
69
90
  end
70
91
 
71
92
  it 'counts a local call in a param initializer' do
@@ -88,7 +109,9 @@ describe Reek::Smells::UtilityFunction do
88
109
  end
89
110
 
90
111
  it 'should report message chain' do
91
- expect('def simple(arga) arga.b.c end').to reek_of(:UtilityFunction, name: 'simple')
112
+ src = 'def simple(arga) arga.b.c end'
113
+ expect(src).to reek_of(:UtilityFunction, name: 'simple')
114
+ expect(src).not_to reek_of(:FeatureEnvy)
92
115
  end
93
116
 
94
117
  it 'does not report a method that calls super' do
@@ -110,23 +133,4 @@ describe Reek::Smells::UtilityFunction do
110
133
  expect(src).not_to reek_of(:UtilityFunction)
111
134
  end
112
135
  end
113
-
114
- context 'when a smells is reported' do
115
- before :each do
116
- src = <<-EOS
117
- def simple(arga)
118
- arga.b.c
119
- end
120
- EOS
121
- source = src.to_reek_source
122
- mctx = Reek::Core::TreeWalker.new.process_def(source.syntax_tree)
123
- @warning = @detector.examine_context(mctx)[0] # SMELL: too cumbersome!
124
- end
125
-
126
- it_should_behave_like 'common fields set correctly'
127
-
128
- it 'reports the line number of the method' do
129
- expect(@warning.lines).to eq([1])
130
- end
131
- end
132
136
  end
@@ -1,12 +1,10 @@
1
- require 'spec_helper'
2
- require 'reek/source/code_comment'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/source/code_comment'
3
3
 
4
- include Reek::Source
5
-
6
- describe CodeComment do
4
+ describe Reek::Source::CodeComment do
7
5
  context 'with an empty comment' do
8
6
  before :each do
9
- @comment = CodeComment.new('')
7
+ @comment = Reek::Source::CodeComment.new('')
10
8
  end
11
9
  it 'is not descriptive' do
12
10
  expect(@comment).not_to be_descriptive
@@ -18,34 +16,37 @@ describe CodeComment do
18
16
 
19
17
  context 'comment checks' do
20
18
  it 'rejects an empty comment' do
21
- expect(CodeComment.new('#')).not_to be_descriptive
19
+ expect(Reek::Source::CodeComment.new('#')).not_to be_descriptive
22
20
  end
23
21
  it 'rejects a 1-word comment' do
24
- expect(CodeComment.new("# fred\n# ")).not_to be_descriptive
22
+ expect(Reek::Source::CodeComment.new("# fred\n# ")).not_to be_descriptive
25
23
  end
26
24
  it 'accepts a 2-word comment' do
27
- expect(CodeComment.new('# fred here ')).to be_descriptive
25
+ expect(Reek::Source::CodeComment.new('# fred here ')).to be_descriptive
28
26
  end
29
27
  it 'accepts a multi-word comment' do
30
- expect(CodeComment.new("# fred here \n# with \n # biscuits ")).to be_descriptive
28
+ comment = "# fred here \n# with \n # biscuits "
29
+ expect(Reek::Source::CodeComment.new(comment)).to be_descriptive
31
30
  end
32
31
  end
33
32
 
34
33
  context 'comment config' do
35
34
  it 'parses hashed options' do
36
- config = CodeComment.new('# :reek:Duplication: { enabled: false }').config
35
+ comment = '# :reek:Duplication: { enabled: false }'
36
+ config = Reek::Source::CodeComment.new(comment).config
37
37
  expect(config).to include('Duplication')
38
38
  expect(config['Duplication']).to include('enabled')
39
39
  expect(config['Duplication']['enabled']).to be_falsey
40
40
  end
41
41
  it 'parses hashed options with ruby names' do
42
- config = CodeComment.new('# :reek:nested_iterators: { enabled: true }').config
42
+ comment = '# :reek:nested_iterators: { enabled: true }'
43
+ config = Reek::Source::CodeComment.new(comment).config
43
44
  expect(config).to include('NestedIterators')
44
45
  expect(config['NestedIterators']).to include('enabled')
45
46
  expect(config['NestedIterators']['enabled']).to be_truthy
46
47
  end
47
48
  it 'parses multiple hashed options' do
48
- config = CodeComment.new('
49
+ config = Reek::Source::CodeComment.new('
49
50
  # :reek:Duplication: { enabled: false }
50
51
  :reek:nested_iterators: { enabled: true }
51
52
  ').config
@@ -56,7 +57,7 @@ describe CodeComment do
56
57
  expect(config['NestedIterators']['enabled']).to be_truthy
57
58
  end
58
59
  it 'parses multiple hashed options on the same line' do
59
- config = CodeComment.new('
60
+ config = Reek::Source::CodeComment.new('
60
61
  #:reek:Duplication: { enabled: false } and :reek:nested_iterators: { enabled: true }
61
62
  ').config
62
63
  expect(config).to include('Duplication', 'NestedIterators')
@@ -66,7 +67,8 @@ describe CodeComment do
66
67
  expect(config['NestedIterators']['enabled']).to be_truthy
67
68
  end
68
69
  it 'parses multiple unhashed options on the same line' do
69
- config = CodeComment.new('# :reek:Duplication and :reek:nested_iterators').config
70
+ comment = '# :reek:Duplication and :reek:nested_iterators'
71
+ config = Reek::Source::CodeComment.new(comment).config
70
72
  expect(config).to include('Duplication', 'NestedIterators')
71
73
  expect(config['Duplication']).to include('enabled')
72
74
  expect(config['Duplication']['enabled']).to be_falsey
@@ -74,13 +76,13 @@ describe CodeComment do
74
76
  expect(config['NestedIterators']['enabled']).to be_falsey
75
77
  end
76
78
  it 'disables the smell if no options are specifed' do
77
- config = CodeComment.new('# :reek:Duplication').config
79
+ config = Reek::Source::CodeComment.new('# :reek:Duplication').config
78
80
  expect(config).to include('Duplication')
79
81
  expect(config['Duplication']).to include('enabled')
80
82
  expect(config['Duplication']['enabled']).to be_falsey
81
83
  end
82
84
  it 'ignores smells after a space' do
83
- config = CodeComment.new('# :reek: Duplication').config
85
+ config = Reek::Source::CodeComment.new('# :reek: Duplication').config
84
86
  expect(config).not_to include('Duplication')
85
87
  end
86
88
  end
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- include Reek
1
+ require_relative '../../spec_helper'
4
2
 
5
3
  describe Dir do
6
4
  it 'reports correct smells via the Dir matcher' do
@@ -1,12 +1,11 @@
1
- require 'spec_helper'
2
- require 'reek/source/reference_collector'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/source/reference_collector'
3
3
 
4
- include Reek::Source
5
-
6
- describe ReferenceCollector do
4
+ describe Reek::Source::ReferenceCollector do
7
5
  context 'counting refs to self' do
8
6
  def refs_to_self(src)
9
- ReferenceCollector.new(src.to_reek_source.syntax_tree).num_refs_to_self
7
+ syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
8
+ Reek::Source::ReferenceCollector.new(syntax_tree).num_refs_to_self
10
9
  end
11
10
  it 'with no refs to self' do
12
11
  expect(refs_to_self('def no_envy(arga) arga.barg end')).to eq(0)
@@ -1,9 +1,7 @@
1
- require 'spec_helper'
2
- require 'reek/source/sexp_extensions'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/source/sexp_extensions'
3
3
 
4
- include Reek::Source
5
-
6
- describe SexpExtensions::DefNode do
4
+ describe Reek::Source::SexpExtensions::DefNode do
7
5
  context 'with no parameters' do
8
6
  before :each do
9
7
  @node = s(:def, :hello, s(:args))
@@ -112,7 +110,7 @@ describe SexpExtensions::DefNode do
112
110
 
113
111
  it 'has a body extended with SexpNode' do
114
112
  b = @node.body
115
- expect(b.class.included_modules.first).to eq SexpNode
113
+ expect(b.class.included_modules.first).to eq Reek::Source::SexpNode
116
114
  end
117
115
 
118
116
  it 'finds nodes in the body with #body_nodes' do
@@ -135,7 +133,7 @@ describe SexpExtensions::DefNode do
135
133
  end
136
134
  end
137
135
 
138
- describe SexpExtensions::DefsNode do
136
+ describe Reek::Source::SexpExtensions::DefsNode do
139
137
  context 'with no parameters' do
140
138
  before :each do
141
139
  @node = s(:defs, s(:lvar, :obj), :hello, s(:args))
@@ -244,12 +242,12 @@ describe SexpExtensions::DefsNode do
244
242
 
245
243
  it 'has a body extended with SexpNode' do
246
244
  b = @node.body
247
- expect(b.class.included_modules.first).to eq SexpNode
245
+ expect(b.class.included_modules.first).to eq Reek::Source::SexpNode
248
246
  end
249
247
  end
250
248
  end
251
249
 
252
- describe SexpExtensions::SendNode do
250
+ describe Reek::Source::SexpExtensions::SendNode do
253
251
  context 'with no parameters' do
254
252
  before :each do
255
253
  @node = s(:send, nil, :hello)
@@ -281,7 +279,7 @@ describe SexpExtensions::SendNode do
281
279
  end
282
280
  end
283
281
 
284
- describe SexpExtensions::BlockNode do
282
+ describe Reek::Source::SexpExtensions::BlockNode do
285
283
  context 'with no parameters' do
286
284
  before :each do
287
285
  @node = s(:block, s(:send, nil, :map), s(:args), nil)
@@ -313,7 +311,7 @@ describe SexpExtensions::BlockNode do
313
311
  end
314
312
  end
315
313
 
316
- describe SexpExtensions::ModuleNode do
314
+ describe Reek::Source::SexpExtensions::ModuleNode do
317
315
  context 'with a simple name' do
318
316
  subject do
319
317
  mod = ast(:module, :Fred, nil)
@@ -1,17 +1,16 @@
1
- require 'spec_helper'
2
- require 'reek/source/sexp_formatter'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/source/sexp_formatter'
3
3
 
4
- include Reek::Source
5
-
6
- describe SexpFormatter do
4
+ describe Reek::Source::SexpFormatter do
7
5
  describe '::format' do
8
6
  it 'formats a simple s-expression' do
9
- result = SexpFormatter.format s(:lvar, :foo)
7
+ result = Reek::Source::SexpFormatter.format s(:lvar, :foo)
10
8
  expect(result).to eq('foo')
11
9
  end
12
10
 
13
11
  it 'formats a more complex s-expression' do
14
- result = SexpFormatter.format s(:send, nil, :foo, s(:lvar, :bar))
12
+ ast = s(:send, nil, :foo, s(:lvar, :bar))
13
+ result = Reek::Source::SexpFormatter.format(ast)
15
14
  expect(result).to eq('foo(bar)')
16
15
  end
17
16
 
@@ -22,7 +21,7 @@ describe SexpFormatter do
22
21
  s(:begin,
23
22
  s(:send, nil, :baz),
24
23
  s(:send, nil, :qux)))
25
- result = SexpFormatter.format ast
24
+ result = Reek::Source::SexpFormatter.format ast
26
25
 
27
26
  expect(result).to eq 'if foo ... end'
28
27
  end
@@ -1,9 +1,7 @@
1
- require 'spec_helper'
2
- require 'reek/source/sexp_node'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/source/sexp_node'
3
3
 
4
- include Reek::Source
5
-
6
- describe SexpNode do
4
+ describe Reek::Source::SexpNode do
7
5
  context 'format' do
8
6
  it 'formats self' do
9
7
  @node = s(:self)
@@ -1,25 +1,25 @@
1
- require 'spec_helper'
1
+ require_relative '../../spec_helper'
2
2
  require 'stringio'
3
- require 'reek/source/source_code'
3
+ require_relative '../../../lib/reek/source/source_code'
4
4
 
5
- include Reek::Source
6
-
7
- describe SourceCode do
5
+ describe Reek::Source::SourceCode do
8
6
  describe '#syntax_tree' do
9
7
  it 'associates comments with the AST' do
10
- source_code = SourceCode.new("# this is\n# a comment\ndef foo; end", '(string)')
8
+ source = "# this is\n# a comment\ndef foo; end"
9
+ source_code = Reek::Source::SourceCode.new(source, '(string)')
11
10
  result = source_code.syntax_tree
12
11
  expect(result.comments).to eq "# this is\n# a comment"
13
12
  end
14
13
 
15
14
  it 'cleanly processes empty source' do
16
- source_code = SourceCode.new('', '(string)')
15
+ source_code = Reek::Source::SourceCode.new('', '(string)')
17
16
  result = source_code.syntax_tree
18
17
  expect(result).to be_nil
19
18
  end
20
19
 
21
20
  it 'cleanly processes empty source with comments' do
22
- source_code = SourceCode.new("# this is\n# a comment\n", '(string)')
21
+ source = "# this is\n# a comment\n"
22
+ source_code = Reek::Source::SourceCode.new(source, '(string)')
23
23
  result = source_code.syntax_tree
24
24
  expect(result).to be_nil
25
25
  end
@@ -29,7 +29,7 @@ describe SourceCode do
29
29
  let(:source_name) { 'Test source' }
30
30
  let(:error_message) { 'Error message' }
31
31
  let(:parser) { double('parser') }
32
- let(:src) { SourceCode.new('', source_name, parser) }
32
+ let(:src) { Reek::Source::SourceCode.new('', source_name, parser) }
33
33
 
34
34
  before :each do
35
35
  @catcher = StringIO.new