reek 2.2.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.travis.yml +9 -4
  4. data/CHANGELOG +8 -0
  5. data/Gemfile +6 -4
  6. data/README.md +6 -0
  7. data/docs/API.md +51 -22
  8. data/docs/Configuration-Files.md +12 -1
  9. data/docs/Feature-Envy.md +30 -10
  10. data/docs/How-reek-works-internally.md +109 -39
  11. data/docs/RSpec-matchers.md +26 -22
  12. data/docs/Reek-Driven-Development.md +0 -8
  13. data/docs/Utility-Function.md +8 -10
  14. data/features/{ruby_api/api.feature → command_line_interface/basic_usage.feature} +2 -2
  15. data/features/programmatic_access.feature +21 -2
  16. data/features/samples.feature +3 -1
  17. data/lib/reek.rb +2 -2
  18. data/lib/reek/{core → ast}/ast_node_class_map.rb +8 -8
  19. data/lib/reek/{sexp/sexp_node.rb → ast/node.rb} +47 -6
  20. data/lib/reek/{core → ast}/object_refs.rb +2 -1
  21. data/lib/reek/{core → ast}/reference_collector.rb +2 -1
  22. data/lib/reek/{sexp → ast}/sexp_extensions.rb +10 -5
  23. data/lib/reek/{sexp → ast}/sexp_formatter.rb +7 -5
  24. data/lib/reek/cli/application.rb +1 -0
  25. data/lib/reek/cli/command.rb +1 -0
  26. data/lib/reek/cli/input.rb +4 -1
  27. data/lib/reek/cli/option_interpreter.rb +6 -4
  28. data/lib/reek/cli/options.rb +2 -1
  29. data/lib/reek/cli/reek_command.rb +3 -2
  30. data/lib/reek/cli/silencer.rb +1 -0
  31. data/lib/reek/{core → cli}/warning_collector.rb +2 -1
  32. data/lib/reek/code_comment.rb +36 -0
  33. data/lib/reek/configuration/app_configuration.rb +17 -2
  34. data/lib/reek/configuration/configuration_file_finder.rb +1 -0
  35. data/lib/reek/{core → context}/code_context.rb +7 -5
  36. data/lib/reek/{core → context}/method_context.rb +5 -3
  37. data/lib/reek/{core → context}/module_context.rb +8 -3
  38. data/lib/reek/{core/stop_context.rb → context/root_context.rb} +4 -2
  39. data/lib/reek/{core → context}/singleton_method_context.rb +2 -1
  40. data/lib/reek/examiner.rb +82 -0
  41. data/lib/reek/report/formatter.rb +70 -0
  42. data/lib/reek/report/heading_formatter.rb +45 -0
  43. data/lib/reek/report/location_formatter.rb +35 -0
  44. data/lib/reek/report/report.rb +198 -0
  45. data/lib/reek/smells.rb +24 -13
  46. data/lib/reek/smells/attribute.rb +6 -4
  47. data/lib/reek/smells/boolean_parameter.rb +3 -1
  48. data/lib/reek/smells/class_variable.rb +3 -1
  49. data/lib/reek/smells/control_parameter.rb +3 -1
  50. data/lib/reek/smells/data_clump.rb +3 -1
  51. data/lib/reek/smells/duplicate_method_call.rb +3 -1
  52. data/lib/reek/smells/feature_envy.rb +3 -1
  53. data/lib/reek/smells/irresponsible_module.rb +12 -7
  54. data/lib/reek/smells/long_parameter_list.rb +5 -3
  55. data/lib/reek/smells/long_yield_list.rb +3 -1
  56. data/lib/reek/smells/module_initialize.rb +3 -1
  57. data/lib/reek/smells/nested_iterators.rb +3 -1
  58. data/lib/reek/smells/nil_check.rb +3 -1
  59. data/lib/reek/smells/prima_donna_method.rb +3 -1
  60. data/lib/reek/smells/repeated_conditional.rb +5 -3
  61. data/lib/reek/{core → smells}/smell_configuration.rb +3 -1
  62. data/lib/reek/smells/smell_detector.rb +9 -7
  63. data/lib/reek/{core → smells}/smell_repository.rb +3 -2
  64. data/lib/reek/smells/smell_warning.rb +6 -4
  65. data/lib/reek/smells/too_many_instance_variables.rb +3 -1
  66. data/lib/reek/smells/too_many_methods.rb +3 -1
  67. data/lib/reek/smells/too_many_statements.rb +3 -1
  68. data/lib/reek/smells/uncommunicative_method_name.rb +3 -1
  69. data/lib/reek/smells/uncommunicative_module_name.rb +3 -1
  70. data/lib/reek/smells/uncommunicative_parameter_name.rb +3 -1
  71. data/lib/reek/smells/uncommunicative_variable_name.rb +3 -1
  72. data/lib/reek/smells/unused_parameters.rb +3 -1
  73. data/lib/reek/smells/utility_function.rb +5 -2
  74. data/lib/reek/source/source_code.rb +40 -9
  75. data/lib/reek/source/source_locator.rb +30 -12
  76. data/lib/reek/spec/should_reek.rb +5 -4
  77. data/lib/reek/spec/should_reek_of.rb +3 -2
  78. data/lib/reek/spec/should_reek_only_of.rb +5 -4
  79. data/lib/reek/tree_dresser.rb +32 -0
  80. data/lib/reek/tree_walker.rb +182 -0
  81. data/lib/reek/version.rb +1 -1
  82. data/reek.gemspec +3 -3
  83. data/spec/factories/factories.rb +2 -0
  84. data/spec/reek/{sexp/sexp_node_spec.rb → ast/node_spec.rb} +2 -2
  85. data/spec/reek/{core → ast}/object_refs_spec.rb +3 -3
  86. data/spec/reek/{core → ast}/reference_collector_spec.rb +2 -2
  87. data/spec/reek/{sexp → ast}/sexp_extensions_spec.rb +6 -16
  88. data/spec/reek/{sexp → ast}/sexp_formatter_spec.rb +2 -2
  89. data/spec/reek/cli/option_interpreter_spec.rb +2 -1
  90. data/spec/reek/{core → cli}/warning_collector_spec.rb +3 -3
  91. data/spec/reek/{core/code_comment_spec.rb → code_comment_spec.rb} +3 -3
  92. data/spec/reek/configuration/app_configuration_spec.rb +31 -18
  93. data/spec/reek/{core → context}/code_context_spec.rb +14 -15
  94. data/spec/reek/{core → context}/method_context_spec.rb +8 -8
  95. data/spec/reek/{core → context}/module_context_spec.rb +4 -4
  96. data/spec/reek/context/root_context_spec.rb +14 -0
  97. data/spec/reek/{core → context}/singleton_method_context_spec.rb +4 -4
  98. data/spec/reek/{core/examiner_spec.rb → examiner_spec.rb} +3 -42
  99. data/spec/reek/{cli → report}/html_report_spec.rb +5 -5
  100. data/spec/reek/report/json_report_spec.rb +20 -0
  101. data/spec/reek/{cli → report}/text_report_spec.rb +14 -14
  102. data/spec/reek/{cli → report}/xml_report_spec.rb +7 -7
  103. data/spec/reek/report/yaml_report_spec.rb +20 -0
  104. data/spec/reek/smells/attribute_spec.rb +2 -1
  105. data/spec/reek/smells/boolean_parameter_spec.rb +1 -1
  106. data/spec/reek/smells/class_variable_spec.rb +5 -5
  107. data/spec/reek/smells/control_parameter_spec.rb +1 -1
  108. data/spec/reek/smells/data_clump_spec.rb +1 -1
  109. data/spec/reek/smells/duplicate_method_call_spec.rb +3 -3
  110. data/spec/reek/smells/feature_envy_spec.rb +1 -1
  111. data/spec/reek/smells/irresponsible_module_spec.rb +24 -28
  112. data/spec/reek/smells/long_parameter_list_spec.rb +2 -2
  113. data/spec/reek/smells/long_yield_list_spec.rb +2 -2
  114. data/spec/reek/smells/nested_iterators_spec.rb +1 -1
  115. data/spec/reek/smells/nil_check_spec.rb +2 -2
  116. data/spec/reek/smells/prima_donna_method_spec.rb +3 -3
  117. data/spec/reek/smells/repeated_conditional_spec.rb +6 -6
  118. data/spec/reek/{core → smells}/smell_configuration_spec.rb +4 -4
  119. data/spec/reek/smells/smell_detector_shared.rb +2 -2
  120. data/spec/reek/{core → smells}/smell_repository_spec.rb +5 -4
  121. data/spec/reek/smells/too_many_instance_variables_spec.rb +1 -1
  122. data/spec/reek/smells/too_many_methods_spec.rb +4 -4
  123. data/spec/reek/smells/too_many_statements_spec.rb +2 -2
  124. data/spec/reek/smells/uncommunicative_method_name_spec.rb +1 -1
  125. data/spec/reek/smells/uncommunicative_module_name_spec.rb +4 -4
  126. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +2 -2
  127. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +3 -3
  128. data/spec/reek/smells/utility_function_spec.rb +23 -1
  129. data/spec/reek/source/source_code_spec.rb +1 -1
  130. data/spec/reek/source/source_locator_spec.rb +30 -0
  131. data/spec/reek/spec/should_reek_of_spec.rb +0 -17
  132. data/spec/reek/spec/should_reek_spec.rb +0 -25
  133. data/spec/reek/tree_dresser_spec.rb +16 -0
  134. data/spec/reek/{core/tree_walker_spec.rb → tree_walker_spec.rb} +5 -5
  135. data/spec/samples/{simple_configuration.reek → configuration/simple_configuration.reek} +0 -0
  136. data/spec/samples/configuration/with_excluded_paths.reek +4 -0
  137. data/spec/samples/source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb +5 -0
  138. data/spec/samples/source_with_exclude_paths/nested/ignore_me_as_well/irresponsible_module.rb +2 -0
  139. data/spec/samples/source_with_exclude_paths/nested/uncommunicative_parameter_name.rb +6 -0
  140. data/spec/spec_helper.rb +6 -7
  141. data/tasks/develop.rake +2 -2
  142. metadata +71 -69
  143. data/lib/reek/cli/report/formatter.rb +0 -69
  144. data/lib/reek/cli/report/heading_formatter.rb +0 -45
  145. data/lib/reek/cli/report/location_formatter.rb +0 -34
  146. data/lib/reek/cli/report/report.rb +0 -191
  147. data/lib/reek/core/ast_node.rb +0 -38
  148. data/lib/reek/core/code_comment.rb +0 -37
  149. data/lib/reek/core/examiner.rb +0 -85
  150. data/lib/reek/core/tree_dresser.rb +0 -24
  151. data/lib/reek/core/tree_walker.rb +0 -180
  152. data/lib/reek/source/source_repository.rb +0 -43
  153. data/spec/reek/cli/json_report_spec.rb +0 -20
  154. data/spec/reek/cli/yaml_report_spec.rb +0 -20
  155. data/spec/reek/core/object_source_spec.rb +0 -18
  156. data/spec/reek/core/stop_context_spec.rb +0 -14
  157. data/spec/reek/core/tree_dresser_spec.rb +0 -16
@@ -1,7 +1,7 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/sexp/sexp_formatter'
2
+ require_relative '../../../lib/reek/ast/sexp_formatter'
3
3
 
4
- RSpec.describe Reek::Sexp::SexpFormatter do
4
+ RSpec.describe Reek::AST::SexpFormatter do
5
5
  describe '::format' do
6
6
  it 'formats a simple s-expression' do
7
7
  result = described_class.format s(:lvar, :foo)
@@ -1,6 +1,7 @@
1
1
  require_relative '../../spec_helper'
2
2
 
3
3
  require_relative '../../../lib/reek/cli/options'
4
+ require_relative '../../../lib/reek/report/report'
4
5
 
5
6
  RSpec.describe Reek::CLI::OptionInterpreter do
6
7
  let(:options) { OpenStruct.new }
@@ -8,7 +9,7 @@ RSpec.describe Reek::CLI::OptionInterpreter do
8
9
 
9
10
  describe '#reporter' do
10
11
  it 'returns a Report::TextReport instance by default' do
11
- expect(instance.reporter).to be_instance_of Reek::CLI::Report::TextReport
12
+ expect(instance.reporter).to be_instance_of Reek::Report::TextReport
12
13
  end
13
14
  end
14
15
  end
@@ -1,10 +1,10 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/core/warning_collector'
2
+ require_relative '../../../lib/reek/cli/warning_collector'
3
3
  require_relative '../../../lib/reek/smells/smell_warning'
4
4
 
5
- RSpec.describe Reek::Core::WarningCollector do
5
+ RSpec.describe Reek::CLI::WarningCollector do
6
6
  before(:each) do
7
- @collector = Reek::Core::WarningCollector.new
7
+ @collector = described_class.new
8
8
  end
9
9
 
10
10
  context 'when empty' do
@@ -1,7 +1,7 @@
1
- require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/core/code_comment'
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/reek/code_comment'
3
3
 
4
- RSpec.describe Reek::Core::CodeComment do
4
+ RSpec.describe Reek::CodeComment do
5
5
  context 'with an empty comment' do
6
6
  before :each do
7
7
  @comment = described_class.new('')
@@ -1,9 +1,9 @@
1
1
  require_relative '../../spec_helper'
2
2
  require_relative '../../../lib/reek/configuration/app_configuration'
3
- require_relative '../../../lib/reek/core/smell_repository'
3
+ require_relative '../../../lib/reek/smells/smell_repository'
4
4
 
5
5
  RSpec.describe Reek::Configuration::AppConfiguration do
6
- let(:sample_configuration_path) { 'spec/samples/simple_configuration.reek' }
6
+ let(:sample_configuration_path) { 'spec/samples/configuration/simple_configuration.reek' }
7
7
  let(:sample_configuration_loaded) do
8
8
  {
9
9
  'UncommunicativeVariableName' => { 'enabled' => false },
@@ -12,32 +12,32 @@ RSpec.describe Reek::Configuration::AppConfiguration do
12
12
  end
13
13
  let(:default_configuration) { Hash.new }
14
14
 
15
- after(:each) { Reek::Configuration::AppConfiguration.reset }
15
+ after(:each) { described_class.reset }
16
16
 
17
17
  describe '.initialize_with' do
18
18
  it 'loads a configuration file if it can find one' do
19
19
  finder = Reek::Configuration::ConfigurationFileFinder
20
20
  allow(finder).to receive(:find).and_return sample_configuration_path
21
- expect(Reek::Configuration::AppConfiguration.configuration).to eq(default_configuration)
21
+ expect(described_class.configuration).to eq(default_configuration)
22
22
 
23
- Reek::Configuration::AppConfiguration.initialize_with(nil)
24
- expect(Reek::Configuration::AppConfiguration.configuration).to eq(sample_configuration_loaded)
23
+ described_class.initialize_with(nil)
24
+ expect(described_class.configuration).to eq(sample_configuration_loaded)
25
25
  end
26
26
 
27
27
  it 'leaves the default configuration untouched if it can\'t find one' do
28
28
  allow(Reek::Configuration::ConfigurationFileFinder).to receive(:find).and_return nil
29
- expect(Reek::Configuration::AppConfiguration.configuration).to eq(default_configuration)
29
+ expect(described_class.configuration).to eq(default_configuration)
30
30
 
31
- Reek::Configuration::AppConfiguration.initialize_with(nil)
32
- expect(Reek::Configuration::AppConfiguration.configuration).to eq(default_configuration)
31
+ described_class.initialize_with(nil)
32
+ expect(described_class.configuration).to eq(default_configuration)
33
33
  end
34
34
  end
35
35
 
36
36
  describe '.configure_smell_repository' do
37
37
  it 'should configure a given smell_repository' do
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
38
+ described_class.load_from_file(sample_configuration_path)
39
+ smell_repository = Reek::Smells::SmellRepository.new('def m; end')
40
+ described_class.configure_smell_repository smell_repository
41
41
 
42
42
  expect(smell_repository.detectors[Reek::Smells::DataClump]).to be_enabled
43
43
  expect(smell_repository.detectors[Reek::Smells::UncommunicativeVariableName]).
@@ -46,20 +46,33 @@ RSpec.describe Reek::Configuration::AppConfiguration do
46
46
  end
47
47
  end
48
48
 
49
+ describe '.exclude_paths' do
50
+ let(:config_path) { 'spec/samples/configuration/with_excluded_paths.reek' }
51
+
52
+ it 'should return all paths to exclude' do
53
+ with_test_config(config_path) do
54
+ expect(described_class.exclude_paths).to eq [
55
+ 'spec/samples/source_with_exclude_paths/ignore_me',
56
+ 'spec/samples/source_with_exclude_paths/nested/ignore_me_as_well'
57
+ ]
58
+ end
59
+ end
60
+ end
61
+
49
62
  describe '.load_from_file' do
50
63
  it 'loads the configuration from given file' do
51
- Reek::Configuration::AppConfiguration.load_from_file(sample_configuration_path)
52
- expect(Reek::Configuration::AppConfiguration.configuration).to eq(sample_configuration_loaded)
64
+ described_class.load_from_file(sample_configuration_path)
65
+ expect(described_class.configuration).to eq(sample_configuration_loaded)
53
66
  end
54
67
  end
55
68
 
56
69
  describe '.reset' do
57
70
  it 'resets the configuration' do
58
- Reek::Configuration::AppConfiguration.load_from_file(sample_configuration_path)
71
+ described_class.load_from_file(sample_configuration_path)
59
72
 
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)
73
+ expect(described_class.configuration).to eq(sample_configuration_loaded)
74
+ described_class.reset
75
+ expect(described_class.configuration).to eq(default_configuration)
63
76
  end
64
77
  end
65
78
  end
@@ -1,9 +1,9 @@
1
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'
2
+ require_relative '../../../lib/reek/context/method_context'
3
+ require_relative '../../../lib/reek/context/module_context'
4
+ require_relative '../../../lib/reek/context/root_context'
5
5
 
6
- RSpec.describe Reek::Core::CodeContext do
6
+ RSpec.describe Reek::Context::CodeContext do
7
7
  context 'name recognition' do
8
8
  before :each do
9
9
  @exp_name = 'random_name' # SMELL: could use a String.random here
@@ -11,8 +11,7 @@ RSpec.describe Reek::Core::CodeContext do
11
11
  @exp = double('exp')
12
12
  allow(@exp).to receive(:name).and_return(@exp_name)
13
13
  allow(@exp).to receive(:full_name).and_return(@full_name)
14
- allow(@exp).to receive(:comments).and_return('')
15
- @ctx = Reek::Core::CodeContext.new(nil, @exp)
14
+ @ctx = Reek::Context::CodeContext.new(nil, @exp)
16
15
  end
17
16
  it 'gets its short name from the exp' do
18
17
  expect(@ctx.name).to eq(@exp_name)
@@ -42,7 +41,7 @@ RSpec.describe Reek::Core::CodeContext do
42
41
  @outer_name = 'another_random sting'
43
42
  allow(outer).to receive(:full_name).at_least(:once).and_return(@outer_name)
44
43
  allow(outer).to receive(:config).and_return({})
45
- @ctx = Reek::Core::CodeContext.new(outer, @exp)
44
+ @ctx = Reek::Context::CodeContext.new(outer, @exp)
46
45
  end
47
46
  it 'creates the correct full name' do
48
47
  expect(@ctx.full_name).to eq("#{@full_name}")
@@ -58,10 +57,10 @@ RSpec.describe Reek::Core::CodeContext do
58
57
 
59
58
  context 'generics' do
60
59
  it 'should pass unknown method calls down the stack' do
61
- stop = Reek::Core::StopContext.new
60
+ stop = Reek::Context::RootContext.new
62
61
  def stop.bananas(arg1, arg2) arg1 + arg2 + 43 end
63
- element = Reek::Core::ModuleContext.new(stop, s(:module, :mod, nil))
64
- element = Reek::Core::MethodContext.new(element, s(:def, :bad, s(:args), nil))
62
+ element = Reek::Context::ModuleContext.new(stop, s(:module, :mod, nil))
63
+ element = Reek::Context::MethodContext.new(element, s(:def, :bad, s(:args), nil))
65
64
  expect(element.bananas(17, -5)).to eq(55)
66
65
  end
67
66
  end
@@ -72,7 +71,7 @@ RSpec.describe Reek::Core::CodeContext do
72
71
  @module_name = 'Emptiness'
73
72
  src = "module #{@module_name}; end"
74
73
  ast = Reek::Source::SourceCode.from(src).syntax_tree
75
- @ctx = Reek::Core::CodeContext.new(nil, ast)
74
+ @ctx = Reek::Context::CodeContext.new(nil, ast)
76
75
  end
77
76
 
78
77
  it 'yields no calls' do
@@ -104,7 +103,7 @@ RSpec.describe Reek::Core::CodeContext do
104
103
  @method_name = 'calloo'
105
104
  src = "module #{@module_name}; def #{@method_name}; puts('hello') end; end"
106
105
  ast = Reek::Source::SourceCode.from(src).syntax_tree
107
- @ctx = Reek::Core::CodeContext.new(nil, ast)
106
+ @ctx = Reek::Context::CodeContext.new(nil, ast)
108
107
  end
109
108
  it 'yields no ifs' do
110
109
  @ctx.each_node(:if, []) { |exp| raise "#{exp} yielded by empty module!" }
@@ -156,7 +155,7 @@ end
156
155
  EOS
157
156
 
158
157
  ast = Reek::Source::SourceCode.from(src).syntax_tree
159
- ctx = Reek::Core::CodeContext.new(nil, ast)
158
+ ctx = Reek::Context::CodeContext.new(nil, ast)
160
159
  expect(ctx.each_node(:if, []).length).to eq(3)
161
160
  end
162
161
  end
@@ -164,12 +163,12 @@ EOS
164
163
  describe '#config_for' do
165
164
  let(:expression) { double('exp') }
166
165
  let(:outer) { nil }
167
- let(:context) { Reek::Core::CodeContext.new(outer, expression) }
166
+ let(:context) { Reek::Context::CodeContext.new(outer, expression) }
168
167
  let(:sniffer) { double('sniffer') }
169
168
 
170
169
  before :each do
171
170
  allow(sniffer).to receive(:smell_type).and_return('DuplicateMethodCall')
172
- allow(expression).to receive(:comments).and_return(
171
+ allow(expression).to receive(:full_comment).and_return(
173
172
  ':reek:DuplicateMethodCall: { allow_calls: [ puts ] }')
174
173
  end
175
174
 
@@ -1,12 +1,12 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/core/method_context'
3
- require_relative '../../../lib/reek/core/stop_context'
2
+ require_relative '../../../lib/reek/context/method_context'
3
+ require_relative '../../../lib/reek/context/root_context'
4
4
 
5
- RSpec.describe Reek::Core::MethodContext, 'matching' do
5
+ RSpec.describe Reek::Context::MethodContext, 'matching' do
6
6
  before :each do
7
7
  exp = double('exp').as_null_object
8
8
  expect(exp).to receive(:full_name).at_least(:once).and_return('mod')
9
- @element = Reek::Core::MethodContext.new(Reek::Core::StopContext.new, exp)
9
+ @element = Reek::Context::MethodContext.new(Reek::Context::RootContext.new, exp)
10
10
  end
11
11
 
12
12
  it 'should recognise itself in a collection of names' do
@@ -20,10 +20,10 @@ RSpec.describe Reek::Core::MethodContext, 'matching' do
20
20
  end
21
21
  end
22
22
 
23
- RSpec.describe Reek::Core::MethodContext do
23
+ RSpec.describe Reek::Context::MethodContext do
24
24
  let(:mc) do
25
25
  sexp = s(:def, :foo, s(:args, s(:arg, :bar)), nil)
26
- Reek::Core::MethodContext.new(Reek::Core::StopContext.new, sexp)
26
+ Reek::Context::MethodContext.new(Reek::Context::RootContext.new, sexp)
27
27
  end
28
28
 
29
29
  describe '#envious_receivers' do
@@ -51,10 +51,10 @@ RSpec.describe Reek::Core::MethodContext do
51
51
  end
52
52
  end
53
53
 
54
- RSpec.describe Reek::Core::MethodParameters, 'default assignments' do
54
+ RSpec.describe Reek::Context::MethodParameters, 'default assignments' do
55
55
  def assignments_from(src)
56
56
  exp = Reek::Source::SourceCode.from(src).syntax_tree
57
- ctx = Reek::Core::MethodContext.new(Reek::Core::StopContext.new, exp)
57
+ ctx = Reek::Context::MethodContext.new(Reek::Context::RootContext.new, exp)
58
58
  ctx.parameters.default_assignments
59
59
  end
60
60
 
@@ -1,8 +1,8 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/core/module_context'
3
- require_relative '../../../lib/reek/core/stop_context'
2
+ require_relative '../../../lib/reek/context/module_context'
3
+ require_relative '../../../lib/reek/context/root_context'
4
4
 
5
- RSpec.describe Reek::Core::ModuleContext do
5
+ RSpec.describe Reek::Context::ModuleContext do
6
6
  it 'should report module name for smell in method' do
7
7
  expect('
8
8
  module Fred
@@ -19,7 +19,7 @@ module Fred
19
19
  end
20
20
  end
21
21
 
22
- RSpec.describe Reek::Core::ModuleContext do
22
+ RSpec.describe Reek::Context::ModuleContext do
23
23
  it 'should recognise global constant' do
24
24
  expect('# module for test
25
25
  module ::Global
@@ -0,0 +1,14 @@
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/context/root_context'
3
+
4
+ RSpec.describe Reek::Context::RootContext do
5
+ before :each do
6
+ @root = Reek::Context::RootContext.new
7
+ end
8
+
9
+ context 'full_name' do
10
+ it 'reports full context' do
11
+ expect(@root.full_name).to eq('')
12
+ end
13
+ end
14
+ end
@@ -1,11 +1,11 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/core/singleton_method_context'
3
- require_relative '../../../lib/reek/core/stop_context'
2
+ require_relative '../../../lib/reek/context/singleton_method_context'
3
+ require_relative '../../../lib/reek/context/root_context'
4
4
 
5
- RSpec.describe Reek::Core::SingletonMethodContext do
5
+ RSpec.describe Reek::Context::SingletonMethodContext do
6
6
  let(:smc) do
7
7
  sexp = s(:def, :foo, s(:args, s(:arg, :bar)), nil)
8
- Reek::Core::SingletonMethodContext.new(Reek::Core::StopContext.new, sexp)
8
+ Reek::Context::SingletonMethodContext.new(Reek::Context::RootContext.new, sexp)
9
9
  end
10
10
 
11
11
  describe '#envious_receivers' do
@@ -1,5 +1,5 @@
1
- require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/core/examiner'
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/reek/examiner'
3
3
 
4
4
  RSpec.shared_examples_for 'no smells found' do
5
5
  it 'is not smelly' do
@@ -22,7 +22,7 @@ RSpec.shared_examples_for 'one smell found' do
22
22
  end
23
23
  end
24
24
 
25
- RSpec.describe Reek::Core::Examiner do
25
+ RSpec.describe Reek::Examiner do
26
26
  before :each do
27
27
  @expected_first_smell = 'NestedIterators'
28
28
  end
@@ -44,45 +44,6 @@ RSpec.describe Reek::Core::Examiner do
44
44
  it_should_behave_like 'one smell found'
45
45
  end
46
46
 
47
- context 'with a partially masked smelly Dir' do
48
- around(:each) do |example|
49
- with_test_config('spec/samples/all_but_one_masked/masked.reek') do
50
- example.run
51
- end
52
- end
53
-
54
- before :each do
55
- smelly_dir = Dir['spec/samples/all_but_one_masked/*.rb']
56
- @examiner = described_class.new(smelly_dir)
57
- end
58
-
59
- it_should_behave_like 'one smell found'
60
- end
61
-
62
- context 'with a fragrant Dir' do
63
- before :each do
64
- clean_dir = Dir['spec/samples/three_clean_files/*.rb']
65
- @examiner = described_class.new(clean_dir)
66
- end
67
-
68
- it_should_behave_like 'no smells found'
69
- end
70
-
71
- context 'with a smelly Dir masked by a dotfile' do
72
- around(:each) do |example|
73
- with_test_config('spec/samples/masked_by_dotfile/.reek') do
74
- example.run
75
- end
76
- end
77
-
78
- before :each do
79
- smelly_dir = Dir['spec/samples/masked_by_dotfile/*.rb']
80
- @examiner = described_class.new(smelly_dir)
81
- end
82
-
83
- it_should_behave_like 'one smell found'
84
- end
85
-
86
47
  context 'with a partially masked smelly File' do
87
48
  around(:each) do |example|
88
49
  with_test_config('spec/samples/all_but_one_masked/masked.reek') do
@@ -1,12 +1,12 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/core/examiner'
3
- require_relative '../../../lib/reek/cli/report/report'
2
+ require_relative '../../../lib/reek/examiner'
3
+ require_relative '../../../lib/reek/report/report'
4
4
 
5
- RSpec.describe Reek::CLI::Report::HTMLReport do
6
- let(:instance) { Reek::CLI::Report::HTMLReport.new }
5
+ RSpec.describe Reek::Report::HTMLReport do
6
+ let(:instance) { Reek::Report::HTMLReport.new }
7
7
 
8
8
  context 'with an empty source' do
9
- let(:examiner) { Reek::Core::Examiner.new('') }
9
+ let(:examiner) { Reek::Examiner.new('') }
10
10
 
11
11
  before do
12
12
  instance.add_examiner examiner
@@ -0,0 +1,20 @@
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/examiner'
3
+ require_relative '../../../lib/reek/report/report'
4
+ require_relative '../../../lib/reek/report/formatter'
5
+
6
+ RSpec.describe Reek::Report::JSONReport do
7
+ let(:instance) { Reek::Report::JSONReport.new }
8
+
9
+ context 'empty source' do
10
+ let(:examiner) { Reek::Examiner.new('') }
11
+
12
+ before do
13
+ instance.add_examiner examiner
14
+ end
15
+
16
+ it 'prints empty json' do
17
+ expect { instance.show }.to output(/^\[\]$/).to_stdout
18
+ end
19
+ end
20
+ end
@@ -1,23 +1,23 @@
1
1
  require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/core/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'
2
+ require_relative '../../../lib/reek/examiner'
3
+ require_relative '../../../lib/reek/report/report'
4
+ require_relative '../../../lib/reek/report/formatter'
5
+ require_relative '../../../lib/reek/report/heading_formatter'
6
6
  require 'rainbow'
7
7
 
8
- RSpec.describe Reek::CLI::Report::TextReport do
8
+ RSpec.describe Reek::Report::TextReport do
9
9
  let(:report_options) do
10
10
  {
11
- warning_formatter: Reek::CLI::Report::SimpleWarningFormatter.new,
12
- report_formatter: Reek::CLI::Report::Formatter,
13
- heading_formatter: Reek::CLI::Report::HeadingFormatter::Quiet
11
+ warning_formatter: Reek::Report::SimpleWarningFormatter.new,
12
+ report_formatter: Reek::Report::Formatter,
13
+ heading_formatter: Reek::Report::HeadingFormatter::Quiet
14
14
  }
15
15
  end
16
- let(:instance) { Reek::CLI::Report::TextReport.new report_options }
16
+ let(:instance) { Reek::Report::TextReport.new report_options }
17
17
 
18
18
  context 'with a single empty source' do
19
19
  before do
20
- instance.add_examiner Reek::Core::Examiner.new('')
20
+ instance.add_examiner Reek::Examiner.new('')
21
21
  end
22
22
 
23
23
  it 'has an empty quiet_report' do
@@ -27,8 +27,8 @@ RSpec.describe Reek::CLI::Report::TextReport do
27
27
 
28
28
  context 'with non smelly files' do
29
29
  before do
30
- instance.add_examiner(Reek::Core::Examiner.new('def simple() puts "a" end'))
31
- instance.add_examiner(Reek::Core::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'))
32
32
  end
33
33
 
34
34
  context 'with colors disabled' do
@@ -54,8 +54,8 @@ RSpec.describe Reek::CLI::Report::TextReport do
54
54
 
55
55
  context 'with a couple of smells' do
56
56
  before do
57
- instance.add_examiner(Reek::Core::Examiner.new('def simple(a) a[3] end'))
58
- instance.add_examiner(Reek::Core::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'))
59
59
  end
60
60
 
61
61
  context 'with colors disabled' do