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,8 +1,8 @@
1
- require 'spec_helper'
2
- require 'reek/smells/duplicate_method_call'
3
- require 'reek/core/code_context'
4
- require 'reek/core/tree_walker'
5
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/duplicate_method_call'
3
+ require_relative '../../../lib/reek/core/code_context'
4
+ require_relative '../../../lib/reek/core/tree_walker'
5
+ require_relative 'smell_detector_shared'
6
6
 
7
7
  describe Reek::Smells::DuplicateMethodCall do
8
8
  context 'when a smell is reported' do
@@ -16,7 +16,7 @@ describe Reek::Smells::DuplicateMethodCall do
16
16
  other[@thing]
17
17
  end
18
18
  EOS
19
- ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
19
+ ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
20
20
  smells = @detector.examine_context(ctx)
21
21
  expect(smells.length).to eq(1)
22
22
  @warning = smells[0]
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
2
- require 'reek/smells/feature_envy'
3
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/feature_envy'
3
+ require_relative 'smell_detector_shared'
4
4
 
5
5
  describe Reek::Smells::FeatureEnvy do
6
6
  context 'with no smell' do
@@ -74,7 +74,7 @@ describe Reek::Smells::FeatureEnvy do
74
74
  def envy(arga)
75
75
  arga.b(arga) + arga.c(@fred)
76
76
  end
77
- ').to reek_only_of(:FeatureEnvy)
77
+ ').to reek_of(:FeatureEnvy, name: 'arga')
78
78
  end
79
79
  end
80
80
 
@@ -88,7 +88,8 @@ describe Reek::Smells::FeatureEnvy do
88
88
  total *= 1.15
89
89
  end
90
90
  EOS
91
- expect(src).to reek_only_of(:FeatureEnvy)
91
+ expect(src).to reek_of(:FeatureEnvy, name: 'total')
92
+ expect(src).not_to reek_of(:FeatureEnvy, name: 'fred')
92
93
  end
93
94
 
94
95
  it 'should report multiple affinities' do
@@ -100,8 +101,8 @@ describe Reek::Smells::FeatureEnvy do
100
101
  total += fred.tax
101
102
  end
102
103
  EOS
103
- expect(src).to reek_of(:FeatureEnvy, name: 'total')
104
- expect(src).to reek_of(:FeatureEnvy, name: 'fred')
104
+ expect(src).to reek_of(:FeatureEnvy, name: 'total')
105
+ expect(src).to reek_of(:FeatureEnvy, name: 'fred')
105
106
  end
106
107
 
107
108
  it 'should not be fooled by duplication' do
@@ -179,9 +180,7 @@ describe Reek::Smells::FeatureEnvy do
179
180
  EOS
180
181
  expect(src).not_to reek_of(:FeatureEnvy)
181
182
  end
182
- end
183
183
 
184
- describe Reek::Smells::FeatureEnvy do
185
184
  it 'counts references to self correctly' do
186
185
  ruby = <<-EOS
187
186
  def report
@@ -231,7 +230,7 @@ describe Reek::Smells::FeatureEnvy do
231
230
  #{@receiver}.fred
232
231
  end
233
232
  EOS
234
- source = src.to_reek_source
233
+ source = Reek::Source::SourceCode.from(src)
235
234
  @mctx = Reek::Core::TreeWalker.new.process_def(source.syntax_tree)
236
235
  @smells = @detector.examine_context(@mctx)
237
236
  end
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
2
- require 'reek/core/code_context'
3
- require 'reek/smells/irresponsible_module'
4
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/core/code_context'
3
+ require_relative '../../../lib/reek/smells/irresponsible_module'
4
+ require_relative 'smell_detector_shared'
5
5
 
6
6
  describe Reek::Smells::IrresponsibleModule do
7
7
  before(:each) do
@@ -27,13 +27,13 @@ describe Reek::Smells::IrresponsibleModule do
27
27
  # test class
28
28
  class Responsible; end
29
29
  EOS
30
- ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
30
+ ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
31
31
  expect(@detector.examine_context(ctx)).to be_empty
32
32
  end
33
33
 
34
34
  it 'reports a class without a comment' do
35
35
  src = "class #{@bad_module_name}; end"
36
- ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
36
+ ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
37
37
  smells = @detector.examine_context(ctx)
38
38
  expect(smells.length).to eq(1)
39
39
  expect(smells[0].smell_category).to eq(Reek::Smells::IrresponsibleModule.smell_category)
@@ -65,7 +65,7 @@ describe Reek::Smells::IrresponsibleModule do
65
65
 
66
66
  it 'reports a fq module name correctly' do
67
67
  src = 'class Foo::Bar; end'
68
- ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
68
+ ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
69
69
  smells = @detector.examine_context(ctx)
70
70
  expect(smells.length).to eq(1)
71
71
  expect(smells[0].smell_category).to eq(described_class.smell_category)
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
2
- require 'reek/core/code_context'
3
- require 'reek/smells/long_parameter_list'
4
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/core/code_context'
3
+ require_relative '../../../lib/reek/smells/long_parameter_list'
4
+ require_relative 'smell_detector_shared'
5
5
 
6
6
  describe Reek::Smells::LongParameterList do
7
7
  context 'for methods with few parameters' do
@@ -89,7 +89,7 @@ describe Reek::Smells::LongParameterList do
89
89
  true
90
90
  end
91
91
  EOS
92
- ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
92
+ ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
93
93
  @smells = @detector.examine_context(ctx)
94
94
  @warning = @smells[0]
95
95
  end
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
2
- require 'reek/core/code_context'
3
- require 'reek/smells/long_yield_list'
4
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/core/code_context'
3
+ require_relative '../../../lib/reek/smells/long_yield_list'
4
+ require_relative 'smell_detector_shared'
5
5
 
6
6
  describe Reek::Smells::LongYieldList do
7
7
  before(:each) do
@@ -38,7 +38,7 @@ describe Reek::Smells::LongYieldList do
38
38
  yield(arga,argb,arga,argb)
39
39
  end
40
40
  EOS
41
- ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
41
+ ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
42
42
  @smells = @detector.examine_context(ctx)
43
43
  @warning = @smells[0]
44
44
  end
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
2
- require 'reek/smells/module_initialize'
3
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/module_initialize'
3
+ require_relative 'smell_detector_shared'
4
4
 
5
5
  describe Reek::Smells::ModuleInitialize do
6
6
  context 'module' do
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
2
- require 'reek/smells/nested_iterators'
3
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/nested_iterators'
3
+ require_relative 'smell_detector_shared'
4
4
 
5
5
  describe Reek::Smells::NestedIterators do
6
6
  context 'with no iterators' do
@@ -237,7 +237,7 @@ describe Reek::Smells::NestedIterators do
237
237
  end
238
238
  end
239
239
  EOS
240
- ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
240
+ ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
241
241
  @warning = @detector.examine_context(ctx)[0]
242
242
  end
243
243
 
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
2
- require 'reek/core/code_context'
3
- require 'reek/smells/nil_check'
4
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/core/code_context'
3
+ require_relative '../../../lib/reek/smells/nil_check'
4
+ require_relative 'smell_detector_shared'
5
5
 
6
6
  describe Reek::Smells::NilCheck do
7
7
  context 'for methods' do
@@ -11,7 +11,7 @@ describe Reek::Smells::NilCheck do
11
11
  foo.nil?
12
12
  end
13
13
  EOS
14
- ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
14
+ ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
15
15
  detector = build(:smell_detector, smell_type: :NilCheck, source: 'source_name')
16
16
  smells = detector.examine_context(ctx)
17
17
  expect(smells[0].lines).to eq [2]
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
2
- require 'reek/core/module_context'
3
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/core/module_context'
3
+ require_relative 'smell_detector_shared'
4
4
 
5
5
  describe Reek::Smells::PrimaDonnaMethod do
6
6
  it 'should report nothing when method and bang counterpart exist' do
@@ -14,7 +14,10 @@ describe Reek::Smells::PrimaDonnaMethod do
14
14
  describe 'the right smell' do
15
15
  let(:detector) { build(:smell_detector, smell_type: :PrimaDonnaMethod, source: 'source_name') }
16
16
  let(:src) { 'class C; def m!; end; end' }
17
- let(:ctx) { Reek::Core::ModuleContext.new(nil, src.to_reek_source.syntax_tree) }
17
+ let(:ctx) do
18
+ Reek::Core::ModuleContext.new(nil,
19
+ Reek::Source::SourceCode.from(src).syntax_tree)
20
+ end
18
21
 
19
22
  it 'should be reported' do
20
23
  smells = detector.examine_context(ctx)
@@ -1,7 +1,8 @@
1
- require 'spec_helper'
2
- require 'reek/smells/repeated_conditional'
3
- require 'reek/core/code_context'
4
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/repeated_conditional'
3
+ require_relative '../../../lib/reek/core/code_context'
4
+ require_relative 'smell_detector_shared'
5
+ require_relative '../../../lib/reek/source/source_code'
5
6
 
6
7
  describe Reek::Smells::RepeatedConditional do
7
8
  before(:each) do
@@ -13,7 +14,7 @@ describe Reek::Smells::RepeatedConditional do
13
14
 
14
15
  context 'with no conditionals' do
15
16
  it 'gathers an empty hash' do
16
- ast = 'module Stable; end'.to_reek_source.syntax_tree
17
+ ast = Reek::Source::SourceCode.from('module Stable; end').syntax_tree
17
18
  ctx = Reek::Core::CodeContext.new(nil, ast)
18
19
  expect(@detector.conditional_counts(ctx).length).to eq(0)
19
20
  end
@@ -21,7 +22,7 @@ describe Reek::Smells::RepeatedConditional do
21
22
 
22
23
  context 'with a test of block_given?' do
23
24
  it 'does not record the condition' do
24
- ast = 'def fred() yield(3) if block_given?; end'.to_reek_source.syntax_tree
25
+ ast = Reek::Source::SourceCode.from('def fred() yield(3) if block_given?; end').syntax_tree
25
26
  ctx = Reek::Core::CodeContext.new(nil, ast)
26
27
  expect(@detector.conditional_counts(ctx).length).to eq(0)
27
28
  end
@@ -29,7 +30,7 @@ describe Reek::Smells::RepeatedConditional do
29
30
 
30
31
  context 'with an empty condition' do
31
32
  it 'does not record the condition' do
32
- ast = 'def fred() case; when 3; end; end'.to_reek_source.syntax_tree
33
+ ast = Reek::Source::SourceCode.from('def fred() case; when 3; end; end').syntax_tree
33
34
  ctx = Reek::Core::CodeContext.new(nil, ast)
34
35
  expect(@detector.conditional_counts(ctx).length).to eq(0)
35
36
  end
@@ -38,7 +39,7 @@ describe Reek::Smells::RepeatedConditional do
38
39
  context 'with three identical conditionals' do
39
40
  before :each do
40
41
  @cond = '@field == :sym'
41
- @cond_expr = @cond.to_reek_source.syntax_tree
42
+ @cond_expr = Reek::Source::SourceCode.from(@cond).syntax_tree
42
43
  src = <<-EOS
43
44
  class Scrunch
44
45
  def first
@@ -56,7 +57,7 @@ describe Reek::Smells::RepeatedConditional do
56
57
  end
57
58
  EOS
58
59
 
59
- ast = src.to_reek_source.syntax_tree
60
+ ast = Reek::Source::SourceCode.from(src).syntax_tree
60
61
  @ctx = Reek::Core::CodeContext.new(nil, ast)
61
62
  @conds = @detector.conditional_counts(@ctx)
62
63
  end
@@ -77,7 +78,7 @@ describe Reek::Smells::RepeatedConditional do
77
78
  context 'with a matching if and case' do
78
79
  before :each do
79
80
  cond = '@field == :sym'
80
- @cond_expr = cond.to_reek_source.syntax_tree
81
+ @cond_expr = Reek::Source::SourceCode.from(cond).syntax_tree
81
82
  src = <<-EOS
82
83
  class Scrunch
83
84
  def alpha
@@ -92,7 +93,7 @@ describe Reek::Smells::RepeatedConditional do
92
93
  end
93
94
  EOS
94
95
 
95
- ast = src.to_reek_source.syntax_tree
96
+ ast = Reek::Source::SourceCode.from(src).syntax_tree
96
97
  ctx = Reek::Core::CodeContext.new(nil, ast)
97
98
  @conds = @detector.conditional_counts(ctx)
98
99
  end
@@ -1,7 +1,5 @@
1
- require 'spec_helper'
2
- require 'reek/core/smell_configuration'
3
-
4
- include Reek::Core
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/core/smell_configuration'
5
3
 
6
4
  shared_examples_for 'SmellDetector' do
7
5
  context 'exception matching follows the context' do
@@ -23,7 +21,8 @@ shared_examples_for 'SmellDetector' do
23
21
 
24
22
  context 'configuration' do
25
23
  it 'becomes disabled when disabled' do
26
- @detector.configure_with(SmellConfiguration::ENABLED_KEY => false)
24
+ enabled_key = Reek::Core::SmellConfiguration::ENABLED_KEY
25
+ @detector.configure_with(enabled_key => false)
27
26
  expect(@detector).not_to be_enabled
28
27
  end
29
28
  end
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
2
- require 'reek/smells/too_many_instance_variables'
3
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/too_many_instance_variables'
3
+ require_relative 'smell_detector_shared'
4
4
 
5
5
  describe Reek::Smells::TooManyInstanceVariables do
6
6
  before(:each) do
@@ -72,7 +72,7 @@ describe Reek::Smells::TooManyInstanceVariables do
72
72
  end
73
73
  end
74
74
  EOS
75
- ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
75
+ ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
76
76
  @warning = @detector.examine_context(ctx)[0]
77
77
  expect(@warning.source).to eq(@source_name)
78
78
  expect(@warning.smell_category).to eq(Reek::Smells::TooManyInstanceVariables.smell_category)
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
2
- require 'reek/smells/too_many_methods'
3
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/too_many_methods'
3
+ require_relative 'smell_detector_shared'
4
4
 
5
5
  describe Reek::Smells::TooManyMethods do
6
6
  before(:each) do
@@ -19,7 +19,8 @@ describe Reek::Smells::TooManyMethods do
19
19
  def m2; end
20
20
  end
21
21
  EOS
22
- ctx = ModuleContext.new(nil, src.to_reek_source.syntax_tree)
22
+ syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
23
+ ctx = Reek::Core::ModuleContext.new(nil, syntax_tree)
23
24
  expect(@detector.examine_context(ctx)).to be_empty
24
25
  end
25
26
 
@@ -31,7 +32,8 @@ describe Reek::Smells::TooManyMethods do
31
32
  def m3; end
32
33
  end
33
34
  EOS
34
- ctx = ModuleContext.new(nil, src.to_reek_source.syntax_tree)
35
+ syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
36
+ ctx = Reek::Core::ModuleContext.new(nil, syntax_tree)
35
37
  smells = @detector.examine_context(ctx)
36
38
  expect(smells.length).to eq(1)
37
39
  expect(smells[0].smell_type).to eq(described_class.smell_type)
@@ -53,7 +55,8 @@ describe Reek::Smells::TooManyMethods do
53
55
  end
54
56
  end
55
57
  EOS
56
- ctx = ModuleContext.new(nil, src.to_reek_source.syntax_tree)
58
+ syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
59
+ ctx = Reek::Core::ModuleContext.new(nil, syntax_tree)
57
60
  expect(@detector.examine_context(ctx)).to be_empty
58
61
  end
59
62
  end
@@ -67,7 +70,8 @@ describe Reek::Smells::TooManyMethods do
67
70
  end
68
71
  EOS
69
72
 
70
- ctx = ModuleContext.new(nil, src.to_reek_source.syntax_tree)
73
+ syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
74
+ ctx = Reek::Core::ModuleContext.new(nil, syntax_tree)
71
75
  @warning = @detector.examine_context(ctx)[0]
72
76
  expect(@warning.source).to eq(@source_name)
73
77
  expect(@warning.smell_category).to eq(described_class.smell_category)
@@ -1,13 +1,14 @@
1
- require 'spec_helper'
2
- require 'reek/smells/too_many_statements'
3
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/too_many_statements'
3
+ require_relative 'smell_detector_shared'
4
+ require_relative '../../../lib/reek/source/source_code'
4
5
 
5
6
  def process_method(source)
6
- Reek::Core::TreeWalker.new.process_def(source.to_reek_source.syntax_tree)
7
+ Reek::Core::TreeWalker.new.process_def(Reek::Source::SourceCode.from(source).syntax_tree)
7
8
  end
8
9
 
9
10
  def process_singleton_method(source)
10
- Reek::Core::TreeWalker.new.process_defs(source.to_reek_source.syntax_tree)
11
+ Reek::Core::TreeWalker.new.process_defs(Reek::Source::SourceCode.from(source).syntax_tree)
11
12
  end
12
13
 
13
14
  describe Reek::Smells::TooManyStatements do
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
2
- require 'reek/smells/uncommunicative_method_name'
3
- require 'reek/smells/smell_detector_shared'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/uncommunicative_method_name'
3
+ require_relative 'smell_detector_shared'
4
4
 
5
5
  describe Reek::Smells::UncommunicativeMethodName do
6
6
  before do
@@ -21,7 +21,7 @@ describe Reek::Smells::UncommunicativeMethodName do
21
21
  context 'with a bad name' do
22
22
  before do
23
23
  src = "def #{method_name}; end"
24
- ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
24
+ ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
25
25
  smells = @detector.examine_context(ctx)
26
26
  @warning = smells[0]
27
27
  end
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
2
- require 'reek/smells/uncommunicative_module_name'
3
- require 'reek/smells/smell_detector_shared'
4
- require 'reek/core/code_context'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/smells/uncommunicative_module_name'
3
+ require_relative 'smell_detector_shared'
4
+ require_relative '../../../lib/reek/core/code_context'
5
5
 
6
6
  describe Reek::Smells::UncommunicativeModuleName do
7
7
  before do
@@ -30,7 +30,7 @@ describe Reek::Smells::UncommunicativeModuleName do
30
30
 
31
31
  it 'reports a bad scoped name' do
32
32
  src = "#{type} Foo::X; end"
33
- ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
33
+ ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
34
34
  smells = @detector.examine_context(ctx)
35
35
  expect(smells.length).to eq(1)
36
36
  expect(smells[0].smell_category).to eq(Reek::Smells::UncommunicativeModuleName.smell_category)
@@ -43,7 +43,7 @@ describe Reek::Smells::UncommunicativeModuleName do
43
43
  context 'accepting names' do
44
44
  it 'accepts Inline::C' do
45
45
  src = 'module Inline::C; end'
46
- ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
46
+ ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
47
47
  expect(@detector.examine_context(ctx)).to be_empty
48
48
  end
49
49
  end
@@ -51,7 +51,7 @@ describe Reek::Smells::UncommunicativeModuleName do
51
51
  context 'looking at the YAML' do
52
52
  before :each do
53
53
  src = 'module Printer2; end'
54
- ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
54
+ ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
55
55
  smells = @detector.examine_context(ctx)
56
56
  @warning = smells[0]
57
57
  end