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,6 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $LOAD_PATH.push File.join(File.dirname(__FILE__), 'lib')
3
- require 'reek/version'
2
+ require File.join(File.dirname(__FILE__), 'lib/reek/version')
4
3
 
5
4
  Gem::Specification.new do |s|
6
5
  s.name = 'reek'
@@ -15,31 +14,26 @@ Gem::Specification.new do |s|
15
14
 
16
15
  s.license = 'MIT'
17
16
  s.email = ['timo.roessner@googlemail.com']
18
- s.executables = ['reek']
19
17
  s.extra_rdoc_files = ['CHANGELOG', 'License.txt']
20
- s.files = Dir['.yardopts', 'CHANGELOG', 'License.txt', 'README.md',
21
- 'Rakefile', 'assets/html_output.html.erb', 'bin/reek',
22
- 'config/defaults.reek', '{features,lib,spec,tasks}/**/*',
23
- 'reek.gemspec'] & `git ls-files -z`.split("\0")
24
- s.homepage = 'https://wiki.github.com/troessner/reek'
25
- s.rdoc_options = ['--main', 'README.md',
26
- '-x', 'assets/|bin/|config/|features/|spec/|tasks/']
27
- s.require_paths = ['lib']
28
- s.rubyforge_project = 'reek'
29
- s.rubygems_version = '1.3.6'
18
+ s.files = `git ls-files -z`.split("\0")
19
+ s.executables = s.files.grep(%r{^bin/}).map { |path| File.basename(path) }
20
+ s.homepage = 'https://github.com/troessner/reek/wiki'
21
+ s.rdoc_options = %w(--main README.md -x assets/|bin/|config/|features/|spec/|tasks/)
30
22
  s.required_ruby_version = '>= 1.9.3'
31
23
  s.summary = 'Code smell detector for Ruby'
32
24
 
33
- s.add_runtime_dependency('parser', ['~> 2.2'])
34
- s.add_runtime_dependency('unparser', ['~> 0.2.2'])
35
- s.add_runtime_dependency('rainbow', ['~> 2.0'])
36
- s.add_runtime_dependency('require_all', ['~> 1.3'])
25
+ s.add_runtime_dependency 'parser', '~> 2.2'
26
+ s.add_runtime_dependency 'rainbow', '~> 2.0'
27
+ s.add_runtime_dependency 'require_all', '~> 1.3'
28
+ s.add_runtime_dependency 'unparser', '~> 0.2.2'
37
29
 
38
- s.add_development_dependency('bundler', ['~> 1.1'])
39
- s.add_development_dependency('rake', ['~> 10.0'])
40
- s.add_development_dependency('cucumber', ['~> 1.3', '>= 1.3.18'])
41
- s.add_development_dependency('rspec', ['~> 3.0'])
42
- s.add_development_dependency('yard', ['>= 0.8.7', '< 0.9'])
43
- s.add_development_dependency('factory_girl', ['~> 4.0'])
44
- s.add_development_dependency('rubocop', ['~> 0.29.0'])
30
+ s.add_development_dependency 'activesupport', '~> 4.2'
31
+ s.add_development_dependency 'aruba', '~> 0.6.2'
32
+ s.add_development_dependency 'bundler', '~> 1.1'
33
+ s.add_development_dependency 'cucumber', '~> 2.0'
34
+ s.add_development_dependency 'factory_girl', '~> 4.0'
35
+ s.add_development_dependency 'rake', '~> 10.0'
36
+ s.add_development_dependency 'rspec', '~> 3.0'
37
+ s.add_development_dependency 'rubocop', '~> 0.30.0'
38
+ s.add_development_dependency 'yard', '~> 0.8.7'
45
39
  end
@@ -1,4 +1,4 @@
1
- require 'reek/smells'
1
+ require_relative '../../lib/reek/smells'
2
2
 
3
3
  FactoryGirl.define do
4
4
  factory :smell_detector, class: Reek::Smells::SmellDetector do
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative '../spec_helper'
2
2
  require 'find'
3
3
 
4
4
  release_timestamp_file = 'build/.last-release'
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative '../spec_helper'
2
2
  require 'tempfile'
3
3
 
4
4
  describe 'yardoc' do
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative '../spec_helper'
2
2
 
3
3
  describe 'Reek source code' do
4
4
  it 'has no smells' do
@@ -1,15 +1,12 @@
1
- require 'spec_helper'
2
- require 'reek/examiner'
3
- require 'reek/cli/report/report'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/examiner'
3
+ require_relative '../../../lib/reek/cli/report/report'
4
4
 
5
- include Reek
6
- include Reek::Cli
7
-
8
- describe Report::HtmlReport do
9
- let(:instance) { Report::HtmlReport.new }
5
+ describe Reek::CLI::Report::HTMLReport do
6
+ let(:instance) { Reek::CLI::Report::HTMLReport.new }
10
7
 
11
8
  context 'with an empty source' do
12
- let(:examiner) { Examiner.new('') }
9
+ let(:examiner) { Reek::Examiner.new('') }
13
10
 
14
11
  before do
15
12
  instance.add_examiner examiner
@@ -1,10 +1,10 @@
1
- require 'spec_helper'
2
- require 'reek/examiner'
3
- require 'reek/cli/report/report'
4
- require 'reek/cli/report/formatter'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/examiner'
3
+ require_relative '../../../lib/reek/cli/report/report'
4
+ require_relative '../../../lib/reek/cli/report/formatter'
5
5
 
6
- describe Reek::Cli::Report::JsonReport do
7
- let(:instance) { Reek::Cli::Report::JsonReport.new }
6
+ describe Reek::CLI::Report::JSONReport do
7
+ let(:instance) { Reek::CLI::Report::JSONReport.new }
8
8
 
9
9
  context 'empty source' do
10
10
  let(:examiner) { Reek::Examiner.new('') }
@@ -1,14 +1,14 @@
1
- require 'spec_helper'
1
+ require_relative '../../spec_helper'
2
2
 
3
- require 'reek/cli/options'
3
+ require_relative '../../../lib/reek/cli/options'
4
4
 
5
- describe Reek::Cli::OptionInterpreter do
5
+ describe Reek::CLI::OptionInterpreter do
6
6
  let(:options) { OpenStruct.new }
7
- let(:instance) { Reek::Cli::OptionInterpreter.new(options) }
7
+ let(:instance) { Reek::CLI::OptionInterpreter.new(options) }
8
8
 
9
9
  describe '#reporter' do
10
10
  it 'returns a Report::TextReport instance by default' do
11
- expect(instance.reporter).to be_instance_of Reek::Cli::Report::TextReport
11
+ expect(instance.reporter).to be_instance_of Reek::CLI::Report::TextReport
12
12
  end
13
13
  end
14
14
  end
@@ -1,26 +1,23 @@
1
- require 'spec_helper'
2
- require 'reek/examiner'
3
- require 'reek/cli/report/report'
4
- require 'reek/cli/report/formatter'
5
- require 'reek/cli/report/heading_formatter'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/examiner'
3
+ require_relative '../../../lib/reek/cli/report/report'
4
+ require_relative '../../../lib/reek/cli/report/formatter'
5
+ require_relative '../../../lib/reek/cli/report/heading_formatter'
6
6
  require 'rainbow'
7
7
 
8
- include Reek
9
- include Reek::Cli
10
-
11
- describe Report::TextReport do
8
+ describe Reek::CLI::Report::TextReport do
12
9
  let(:report_options) do
13
10
  {
14
- warning_formatter: Report::SimpleWarningFormatter.new,
15
- report_formatter: Report::Formatter,
16
- heading_formatter: Report::HeadingFormatter::Quiet
11
+ warning_formatter: Reek::CLI::Report::SimpleWarningFormatter.new,
12
+ report_formatter: Reek::CLI::Report::Formatter,
13
+ heading_formatter: Reek::CLI::Report::HeadingFormatter::Quiet
17
14
  }
18
15
  end
19
- let(:instance) { Report::TextReport.new report_options }
16
+ let(:instance) { Reek::CLI::Report::TextReport.new report_options }
20
17
 
21
18
  context 'with a single empty source' do
22
19
  before do
23
- instance.add_examiner Examiner.new('')
20
+ instance.add_examiner Reek::Examiner.new('')
24
21
  end
25
22
 
26
23
  it 'has an empty quiet_report' do
@@ -30,8 +27,8 @@ describe Report::TextReport do
30
27
 
31
28
  context 'with non smelly files' do
32
29
  before do
33
- instance.add_examiner(Examiner.new('def simple() puts "a" end'))
34
- instance.add_examiner(Examiner.new('def simple() puts "a" end'))
30
+ instance.add_examiner(Reek::Examiner.new('def simple() puts "a" end'))
31
+ instance.add_examiner(Reek::Examiner.new('def simple() puts "a" end'))
35
32
  end
36
33
 
37
34
  context 'with colors disabled' do
@@ -57,8 +54,8 @@ describe Report::TextReport do
57
54
 
58
55
  context 'with a couple of smells' do
59
56
  before do
60
- instance.add_examiner(Examiner.new('def simple(a) a[3] end'))
61
- instance.add_examiner(Examiner.new('def simple(a) a[3] end'))
57
+ instance.add_examiner(Reek::Examiner.new('def simple(a) a[3] end'))
58
+ instance.add_examiner(Reek::Examiner.new('def simple(a) a[3] end'))
62
59
  end
63
60
 
64
61
  context 'with colors disabled' do
@@ -72,7 +69,7 @@ describe Report::TextReport do
72
69
 
73
70
  it 'should mention every smell name' do
74
71
  expect { instance.show }.to output(/UncommunicativeParameterName/).to_stdout
75
- expect { instance.show }.to output(/FeatureEnvy/).to_stdout
72
+ expect { instance.show }.to output(/UtilityFunction/).to_stdout
76
73
  end
77
74
  end
78
75
 
@@ -1,16 +1,13 @@
1
- require 'spec_helper'
2
- require 'reek/examiner'
3
- require 'reek/cli/report/report'
4
- require 'reek/cli/report/formatter'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/examiner'
3
+ require_relative '../../../lib/reek/cli/report/report'
4
+ require_relative '../../../lib/reek/cli/report/formatter'
5
5
 
6
- include Reek
7
- include Reek::Cli
8
-
9
- describe Report::YamlReport do
10
- let(:instance) { Report::YamlReport.new }
6
+ describe Reek::CLI::Report::YAMLReport do
7
+ let(:instance) { Reek::CLI::Report::YAMLReport.new }
11
8
 
12
9
  context 'empty source' do
13
- let(:examiner) { Examiner.new('') }
10
+ let(:examiner) { Reek::Examiner.new('') }
14
11
 
15
12
  before do
16
13
  instance.add_examiner examiner
@@ -1,11 +1,8 @@
1
- require 'spec_helper'
2
- require 'reek/configuration/app_configuration'
3
- require 'reek/core/smell_repository'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/configuration/app_configuration'
3
+ require_relative '../../../lib/reek/core/smell_repository'
4
4
 
5
- include Reek::Configuration
6
- include Reek::Core
7
-
8
- describe AppConfiguration do
5
+ describe Reek::Configuration::AppConfiguration do
9
6
  let(:sample_configuration_path) { 'spec/samples/simple_configuration.reek' }
10
7
  let(:sample_configuration_loaded) do
11
8
  {
@@ -15,31 +12,32 @@ describe AppConfiguration do
15
12
  end
16
13
  let(:default_configuration) { Hash.new }
17
14
 
18
- after(:each) { AppConfiguration.reset }
15
+ after(:each) { Reek::Configuration::AppConfiguration.reset }
19
16
 
20
17
  describe '.initialize_with' do
21
18
  it 'loads a configuration file if it can find one' do
22
- allow(ConfigurationFileFinder).to receive(:find).and_return sample_configuration_path
23
- expect(AppConfiguration.configuration).to eq(default_configuration)
19
+ finder = Reek::Configuration::ConfigurationFileFinder
20
+ allow(finder).to receive(:find).and_return sample_configuration_path
21
+ expect(Reek::Configuration::AppConfiguration.configuration).to eq(default_configuration)
24
22
 
25
- AppConfiguration.initialize_with(nil)
26
- expect(AppConfiguration.configuration).to eq(sample_configuration_loaded)
23
+ Reek::Configuration::AppConfiguration.initialize_with(nil)
24
+ expect(Reek::Configuration::AppConfiguration.configuration).to eq(sample_configuration_loaded)
27
25
  end
28
26
 
29
27
  it 'leaves the default configuration untouched if it can\'t find one' do
30
- allow(ConfigurationFileFinder).to receive(:find).and_return nil
31
- expect(AppConfiguration.configuration).to eq(default_configuration)
28
+ allow(Reek::Configuration::ConfigurationFileFinder).to receive(:find).and_return nil
29
+ expect(Reek::Configuration::AppConfiguration.configuration).to eq(default_configuration)
32
30
 
33
- AppConfiguration.initialize_with(nil)
34
- expect(AppConfiguration.configuration).to eq(default_configuration)
31
+ Reek::Configuration::AppConfiguration.initialize_with(nil)
32
+ expect(Reek::Configuration::AppConfiguration.configuration).to eq(default_configuration)
35
33
  end
36
34
  end
37
35
 
38
36
  describe '.configure_smell_repository' do
39
37
  it 'should configure a given smell_repository' do
40
- AppConfiguration.load_from_file(sample_configuration_path)
41
- smell_repository = SmellRepository.new('def m; end')
42
- AppConfiguration.configure_smell_repository smell_repository
38
+ Reek::Configuration::AppConfiguration.load_from_file(sample_configuration_path)
39
+ smell_repository = Reek::Core::SmellRepository.new('def m; end')
40
+ Reek::Configuration::AppConfiguration.configure_smell_repository smell_repository
43
41
 
44
42
  expect(smell_repository.detectors[Reek::Smells::DataClump]).to be_enabled
45
43
  expect(smell_repository.detectors[Reek::Smells::UncommunicativeVariableName]).
@@ -50,18 +48,18 @@ describe AppConfiguration do
50
48
 
51
49
  describe '.load_from_file' do
52
50
  it 'loads the configuration from given file' do
53
- AppConfiguration.load_from_file(sample_configuration_path)
54
- expect(AppConfiguration.configuration).to eq(sample_configuration_loaded)
51
+ Reek::Configuration::AppConfiguration.load_from_file(sample_configuration_path)
52
+ expect(Reek::Configuration::AppConfiguration.configuration).to eq(sample_configuration_loaded)
55
53
  end
56
54
  end
57
55
 
58
56
  describe '.reset' do
59
57
  it 'resets the configuration' do
60
- AppConfiguration.load_from_file(sample_configuration_path)
58
+ Reek::Configuration::AppConfiguration.load_from_file(sample_configuration_path)
61
59
 
62
- expect(AppConfiguration.configuration).to eq(sample_configuration_loaded)
63
- AppConfiguration.reset
64
- expect(AppConfiguration.configuration).to eq(default_configuration)
60
+ expect(Reek::Configuration::AppConfiguration.configuration).to eq(sample_configuration_loaded)
61
+ Reek::Configuration::AppConfiguration.reset
62
+ expect(Reek::Configuration::AppConfiguration.configuration).to eq(default_configuration)
65
63
  end
66
64
  end
67
65
  end
@@ -1,34 +1,59 @@
1
- require 'spec_helper'
2
- require 'reek/cli/application'
1
+ # encoding: UTF-8
3
2
 
4
- include Reek::Cli
5
- include Reek::Configuration
3
+ require 'pathname'
4
+ require 'tmpdir'
5
+ require_relative '../../spec_helper'
6
6
 
7
- describe ConfigurationFileFinder do
7
+ describe Reek::Configuration::ConfigurationFileFinder do
8
8
  describe '.find' do
9
- let(:sample_config_path) { Pathname.new('spec/samples/simple_configuration.reek') }
10
- let(:config_path_same_level) { Pathname.new('spec/samples/simple_configuration.reek') }
11
- let(:options_with_config_file) { double(config_file: sample_config_path) }
12
- let(:options_without_config_file) { double(config_file: nil) }
9
+ it 'returns the config_file if it’s set' do
10
+ config_file = double
11
+ options = double(config_file: config_file)
12
+ found = described_class.find(options: options)
13
+ expect(found).to eq(config_file)
14
+ end
13
15
 
14
- it 'should return the config file we passed as cli option if given' do
15
- expect(ConfigurationFileFinder.find(options_with_config_file)).to eq(sample_config_path)
16
+ it 'returns the file in current dir if config_file is nil' do
17
+ options = double(config_file: nil)
18
+ current = Pathname.new('spec/samples')
19
+ found = described_class.find(options: options, current: current)
20
+ expect(found).to eq(Pathname.new('spec/samples/exceptions.reek'))
16
21
  end
17
22
 
18
- it 'should return the first configuration file it can find in the current directory' do
19
- allow(ConfigurationFileFinder).to receive(:detect_or_traverse_up).
20
- and_return config_path_same_level
23
+ it 'returns the file in current dir if options is nil' do
24
+ current = Pathname.new('spec/samples')
25
+ found = described_class.find(current: current)
26
+ expect(found).to eq(Pathname.new('spec/samples/exceptions.reek'))
27
+ end
21
28
 
22
- expect(ConfigurationFileFinder.find(options_without_config_file)).
23
- to eq(config_path_same_level)
29
+ it 'returns the file in a parent dir if none in current dir' do
30
+ current = Pathname.new('spec/samples/no_config_file')
31
+ found = described_class.find(current: current)
32
+ expect(found).to eq(Pathname.new('spec/samples/exceptions.reek'))
24
33
  end
25
34
 
26
- it 'should look in the HOME directory lastly' do
27
- allow(ConfigurationFileFinder).to receive(:configuration_by_cli).and_return nil
28
- allow(ConfigurationFileFinder).to receive(:configuration_in_file_system).and_return nil
29
- expect(ConfigurationFileFinder).to receive(:configuration_in_home_directory).once
35
+ it 'returns the file even if it’s just ‘.reek’' do
36
+ current = Pathname.new('spec/samples/masked_by_dotfile')
37
+ found = described_class.find(current: current)
38
+ expect(found).to eq(Pathname.new('spec/samples/masked_by_dotfile/.reek'))
39
+ end
40
+
41
+ it 'returns the file in home if traversing from the current dir fails' do
42
+ Dir.mktmpdir do |tempdir|
43
+ current = Pathname.new(tempdir)
44
+ home = Pathname.new('spec/samples')
45
+ found = described_class.find(current: current, home: home)
46
+ expect(found).to eq(Pathname.new('spec/samples/exceptions.reek'))
47
+ end
48
+ end
30
49
 
31
- ConfigurationFileFinder.find nil
50
+ it 'returns nil when there are no files to find' do
51
+ Dir.mktmpdir do |tempdir|
52
+ current = Pathname.new(tempdir)
53
+ home = Pathname.new(tempdir)
54
+ found = described_class.find(current: current, home: home)
55
+ expect(found).to be_nil
56
+ end
32
57
  end
33
58
  end
34
59
  end
@@ -1,11 +1,9 @@
1
- require 'spec_helper'
2
- require 'reek/core/method_context'
3
- require 'reek/core/module_context'
4
- require 'reek/core/stop_context'
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/core/method_context'
3
+ require_relative '../../../lib/reek/core/module_context'
4
+ require_relative '../../../lib/reek/core/stop_context'
5
5
 
6
- include Reek::Core
7
-
8
- describe CodeContext do
6
+ describe Reek::Core::CodeContext do
9
7
  context 'name recognition' do
10
8
  before :each do
11
9
  @exp_name = 'random_name' # SMELL: could use a String.random here
@@ -14,7 +12,7 @@ describe CodeContext do
14
12
  allow(@exp).to receive(:name).and_return(@exp_name)
15
13
  allow(@exp).to receive(:full_name).and_return(@full_name)
16
14
  allow(@exp).to receive(:comments).and_return('')
17
- @ctx = CodeContext.new(nil, @exp)
15
+ @ctx = Reek::Core::CodeContext.new(nil, @exp)
18
16
  end
19
17
  it 'gets its short name from the exp' do
20
18
  expect(@ctx.name).to eq(@exp_name)
@@ -44,7 +42,7 @@ describe CodeContext do
44
42
  @outer_name = 'another_random sting'
45
43
  allow(outer).to receive(:full_name).at_least(:once).and_return(@outer_name)
46
44
  allow(outer).to receive(:config).and_return({})
47
- @ctx = CodeContext.new(outer, @exp)
45
+ @ctx = Reek::Core::CodeContext.new(outer, @exp)
48
46
  end
49
47
  it 'creates the correct full name' do
50
48
  expect(@ctx.full_name).to eq("#{@full_name}")
@@ -60,10 +58,10 @@ describe CodeContext do
60
58
 
61
59
  context 'generics' do
62
60
  it 'should pass unknown method calls down the stack' do
63
- stop = StopContext.new
61
+ stop = Reek::Core::StopContext.new
64
62
  def stop.bananas(arg1, arg2) arg1 + arg2 + 43 end
65
- element = ModuleContext.new(stop, s(:module, :mod, nil))
66
- element = MethodContext.new(element, s(:def, :bad, s(:args), nil))
63
+ element = Reek::Core::ModuleContext.new(stop, s(:module, :mod, nil))
64
+ element = Reek::Core::MethodContext.new(element, s(:def, :bad, s(:args), nil))
67
65
  expect(element.bananas(17, -5)).to eq(55)
68
66
  end
69
67
  end
@@ -73,8 +71,8 @@ describe CodeContext do
73
71
  before :each do
74
72
  @module_name = 'Emptiness'
75
73
  src = "module #{@module_name}; end"
76
- ast = src.to_reek_source.syntax_tree
77
- @ctx = CodeContext.new(nil, ast)
74
+ ast = Reek::Source::SourceCode.from(src).syntax_tree
75
+ @ctx = Reek::Core::CodeContext.new(nil, ast)
78
76
  end
79
77
 
80
78
  it 'yields no calls' do
@@ -105,8 +103,8 @@ describe CodeContext do
105
103
  @module_name = 'Loneliness'
106
104
  @method_name = 'calloo'
107
105
  src = "module #{@module_name}; def #{@method_name}; puts('hello') end; end"
108
- ast = src.to_reek_source.syntax_tree
109
- @ctx = CodeContext.new(nil, ast)
106
+ ast = Reek::Source::SourceCode.from(src).syntax_tree
107
+ @ctx = Reek::Core::CodeContext.new(nil, ast)
110
108
  end
111
109
  it 'yields no ifs' do
112
110
  @ctx.each_node(:if, []) { |exp| raise "#{exp} yielded by empty module!" }
@@ -157,8 +155,8 @@ class Scrunch
157
155
  end
158
156
  EOS
159
157
 
160
- ast = src.to_reek_source.syntax_tree
161
- ctx = CodeContext.new(nil, ast)
158
+ ast = Reek::Source::SourceCode.from(src).syntax_tree
159
+ ctx = Reek::Core::CodeContext.new(nil, ast)
162
160
  expect(ctx.each_node(:if, []).length).to eq(3)
163
161
  end
164
162
  end
@@ -166,7 +164,7 @@ EOS
166
164
  describe '#config_for' do
167
165
  let(:expression) { double('exp') }
168
166
  let(:outer) { nil }
169
- let(:context) { CodeContext.new(outer, expression) }
167
+ let(:context) { Reek::Core::CodeContext.new(outer, expression) }
170
168
  let(:sniffer) { double('sniffer') }
171
169
 
172
170
  before :each do