reek 4.2.3 → 4.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +6 -0
  4. data/CONTRIBUTING.md +7 -6
  5. data/Gemfile +2 -2
  6. data/README.md +8 -15
  7. data/Rakefile +1 -1
  8. data/defaults.reek +1 -0
  9. data/features/command_line_interface/basic_usage.feature +8 -14
  10. data/features/command_line_interface/smell_selection.feature +4 -4
  11. data/features/command_line_interface/smells_count.feature +12 -14
  12. data/features/configuration_files/masking_smells.feature +31 -24
  13. data/features/configuration_loading.feature +15 -18
  14. data/features/programmatic_access.feature +7 -9
  15. data/features/rake_task/rake_task.feature +20 -24
  16. data/features/reports/json.feature +16 -28
  17. data/features/reports/reports.feature +56 -67
  18. data/features/reports/yaml.feature +13 -26
  19. data/features/samples.feature +3 -3
  20. data/features/step_definitions/sample_file_steps.rb +22 -156
  21. data/features/todo_list.feature +13 -14
  22. data/lib/reek/cli/options.rb +1 -1
  23. data/lib/reek/examiner.rb +45 -10
  24. data/lib/reek/smells/attribute.rb +3 -4
  25. data/lib/reek/smells/boolean_parameter.rb +2 -2
  26. data/lib/reek/smells/class_variable.rb +1 -1
  27. data/lib/reek/smells/control_parameter.rb +4 -4
  28. data/lib/reek/smells/data_clump.rb +2 -3
  29. data/lib/reek/smells/duplicate_method_call.rb +1 -1
  30. data/lib/reek/smells/feature_envy.rb +2 -2
  31. data/lib/reek/smells/irresponsible_module.rb +2 -3
  32. data/lib/reek/smells/long_parameter_list.rb +1 -1
  33. data/lib/reek/smells/long_yield_list.rb +1 -1
  34. data/lib/reek/smells/module_initialize.rb +1 -1
  35. data/lib/reek/smells/nested_iterators.rb +2 -2
  36. data/lib/reek/smells/nil_check.rb +1 -1
  37. data/lib/reek/smells/prima_donna_method.rb +5 -2
  38. data/lib/reek/smells/repeated_conditional.rb +1 -1
  39. data/lib/reek/smells/smell_detector.rb +1 -1
  40. data/lib/reek/smells/smell_warning.rb +6 -5
  41. data/lib/reek/smells/subclassed_from_core_class.rb +3 -3
  42. data/lib/reek/smells/too_many_constants.rb +1 -1
  43. data/lib/reek/smells/too_many_instance_variables.rb +1 -1
  44. data/lib/reek/smells/too_many_methods.rb +1 -1
  45. data/lib/reek/smells/too_many_statements.rb +1 -1
  46. data/lib/reek/smells/uncommunicative_method_name.rb +1 -1
  47. data/lib/reek/smells/uncommunicative_module_name.rb +1 -1
  48. data/lib/reek/smells/uncommunicative_parameter_name.rb +1 -1
  49. data/lib/reek/smells/uncommunicative_variable_name.rb +1 -1
  50. data/lib/reek/smells/unused_parameters.rb +1 -1
  51. data/lib/reek/smells/unused_private_method.rb +1 -1
  52. data/lib/reek/smells/utility_function.rb +2 -3
  53. data/lib/reek/spec/should_reek_of.rb +14 -1
  54. data/lib/reek/version.rb +1 -1
  55. data/samples/checkstyle.xml +7 -0
  56. data/samples/clean.rb +6 -0
  57. data/samples/configuration/.reek +0 -0
  58. data/samples/configuration/corrupt.reek +1 -0
  59. data/samples/configuration/empty.reek +0 -0
  60. data/samples/configuration/full_configuration.reek +9 -0
  61. data/{spec/samples/configuration/simple_configuration.reek → samples/configuration/full_mask.reek} +2 -2
  62. data/samples/configuration/non_public_modifiers_mask.reek +3 -0
  63. data/samples/configuration/partial_mask.reek +3 -0
  64. data/samples/configuration/with_excluded_paths.reek +4 -0
  65. data/{spec/samples → samples}/exceptions.reek +0 -0
  66. data/{spec/samples → samples}/inline.rb +0 -0
  67. data/{spec/samples → samples}/optparse.rb +0 -0
  68. data/samples/paths.rb +4 -0
  69. data/{spec/samples → samples}/redcloth.rb +0 -0
  70. data/samples/smelly.rb +7 -0
  71. data/samples/smelly_with_inline_mask.rb +8 -0
  72. data/samples/smelly_with_modifiers.rb +12 -0
  73. data/{spec/samples → samples}/source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb +0 -0
  74. data/{spec/samples → samples}/source_with_exclude_paths/nested/ignore_me_as_well/irresponsible_module.rb +0 -0
  75. data/{spec/samples → samples}/source_with_exclude_paths/nested/uncommunicative_parameter_name.rb +0 -0
  76. data/{spec/samples → samples}/source_with_hidden_directories/.hidden/uncommunicative_method_name.rb +0 -0
  77. data/{spec/samples → samples}/source_with_hidden_directories/uncommunicative_parameter_name.rb +0 -0
  78. data/{spec/samples → samples}/source_with_non_ruby_files/gibberish +0 -0
  79. data/{spec/samples → samples}/source_with_non_ruby_files/python_source.py +0 -0
  80. data/{spec/samples → samples}/source_with_non_ruby_files/uncommunicative_parameter_name.rb +0 -0
  81. data/spec/reek/cli/application_spec.rb +1 -1
  82. data/spec/reek/cli/command/report_command_spec.rb +2 -5
  83. data/spec/reek/configuration/app_configuration_spec.rb +10 -8
  84. data/spec/reek/configuration/configuration_file_finder_spec.rb +24 -17
  85. data/spec/reek/examiner_spec.rb +84 -5
  86. data/spec/reek/report/json_report_spec.rb +1 -3
  87. data/spec/reek/report/xml_report_spec.rb +2 -3
  88. data/spec/reek/report/yaml_report_spec.rb +0 -2
  89. data/spec/reek/smells/attribute_spec.rb +21 -10
  90. data/spec/reek/smells/boolean_parameter_spec.rb +13 -12
  91. data/spec/reek/smells/class_variable_spec.rb +4 -4
  92. data/spec/reek/smells/control_parameter_spec.rb +25 -18
  93. data/spec/reek/smells/data_clump_spec.rb +5 -5
  94. data/spec/reek/smells/duplicate_method_call_spec.rb +1 -1
  95. data/spec/reek/smells/feature_envy_spec.rb +8 -2
  96. data/spec/reek/smells/irresponsible_module_spec.rb +16 -14
  97. data/spec/reek/smells/long_parameter_list_spec.rb +5 -1
  98. data/spec/reek/smells/long_yield_list_spec.rb +5 -2
  99. data/spec/reek/smells/nested_iterators_spec.rb +37 -13
  100. data/spec/reek/smells/nil_check_spec.rb +50 -53
  101. data/spec/reek/smells/prima_donna_method_spec.rb +9 -1
  102. data/spec/reek/smells/too_many_instance_variables_spec.rb +1 -1
  103. data/spec/reek/smells/too_many_methods_spec.rb +4 -4
  104. data/spec/reek/smells/too_many_statements_spec.rb +1 -1
  105. data/spec/reek/smells/uncommunicative_method_name_spec.rb +3 -3
  106. data/spec/reek/smells/uncommunicative_module_name_spec.rb +3 -3
  107. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +3 -3
  108. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +3 -3
  109. data/spec/reek/smells/utility_function_spec.rb +12 -8
  110. data/spec/reek/source/source_locator_spec.rb +5 -1
  111. data/spec/reek/spec/should_reek_of_spec.rb +20 -13
  112. data/spec/reek/spec/should_reek_spec.rb +6 -11
  113. data/spec/spec_helper.rb +2 -2
  114. metadata +28 -36
  115. data/spec/samples/all_but_one_masked/clean_one.rb +0 -7
  116. data/spec/samples/all_but_one_masked/dirty.rb +0 -8
  117. data/spec/samples/all_but_one_masked/masked.reek +0 -9
  118. data/spec/samples/checkstyle.xml +0 -13
  119. data/spec/samples/clean_due_to_masking/clean_one.rb +0 -7
  120. data/spec/samples/clean_due_to_masking/clean_three.rb +0 -7
  121. data/spec/samples/clean_due_to_masking/clean_two.rb +0 -7
  122. data/spec/samples/clean_due_to_masking/dirty_one.rb +0 -7
  123. data/spec/samples/clean_due_to_masking/dirty_two.rb +0 -7
  124. data/spec/samples/clean_due_to_masking/masked.reek +0 -11
  125. data/spec/samples/configuration/full_configuration.reek +0 -9
  126. data/spec/samples/configuration/with_excluded_paths.reek +0 -4
  127. data/spec/samples/masked_by_dotfile/.reek +0 -9
  128. data/spec/samples/masked_by_dotfile/dirty.rb +0 -8
  129. data/spec/samples/no_config_file/dirty.rb +0 -8
  130. data/spec/samples/three_clean_files/clean_one.rb +0 -7
  131. data/spec/samples/three_clean_files/clean_three.rb +0 -7
  132. data/spec/samples/three_clean_files/clean_two.rb +0 -7
  133. data/spec/samples/two_smelly_files/dirty_one.rb +0 -8
  134. data/spec/samples/two_smelly_files/dirty_two.rb +0 -8
@@ -34,7 +34,7 @@ module Reek
34
34
  #
35
35
  # @return [Array<SmellWarning>]
36
36
  #
37
- def inspect(ctx)
37
+ def sniff(ctx)
38
38
  max_allowed_constants = value(MAX_ALLOWED_CONSTANTS_KEY, ctx)
39
39
 
40
40
  count = ctx.each_node(:casgn, IGNORED_NODES).delete_if(&:defines_module?).length
@@ -33,7 +33,7 @@ module Reek
33
33
  #
34
34
  # @return [Array<SmellWarning>]
35
35
  #
36
- def inspect(ctx)
36
+ def sniff(ctx)
37
37
  max_allowed_ivars = value(MAX_ALLOWED_IVARS_KEY, ctx)
38
38
  count = ctx.local_nodes(:ivasgn).map { |ivasgn| ivasgn.children.first }.uniq.length
39
39
  return [] if count <= max_allowed_ivars
@@ -35,7 +35,7 @@ module Reek
35
35
  #
36
36
  # @return [Array<SmellWarning>]
37
37
  #
38
- def inspect(ctx)
38
+ def sniff(ctx)
39
39
  max_allowed_methods = value(MAX_ALLOWED_METHODS_KEY, ctx)
40
40
  # TODO: Only checks instance methods!
41
41
  actual = ctx.node_instance_methods.length
@@ -27,7 +27,7 @@ module Reek
27
27
  #
28
28
  # @return [Array<SmellWarning>]
29
29
  #
30
- def inspect(ctx)
30
+ def sniff(ctx)
31
31
  max_allowed_statements = value(MAX_ALLOWED_STATEMENTS_KEY, ctx)
32
32
  count = ctx.number_of_statements
33
33
  return [] if count <= max_allowed_statements
@@ -36,7 +36,7 @@ module Reek
36
36
  #
37
37
  # @return [Array<SmellWarning>]
38
38
  #
39
- def inspect(context)
39
+ def sniff(context)
40
40
  name = context.name.to_s
41
41
  return [] if acceptable_name?(name: name, context: context)
42
42
 
@@ -45,7 +45,7 @@ module Reek
45
45
  #
46
46
  # @return [Array<SmellWarning>]
47
47
  #
48
- def inspect(context)
48
+ def sniff(context)
49
49
  fully_qualified_name = context.full_name
50
50
  exp = context.exp
51
51
  module_name = exp.simple_name
@@ -38,7 +38,7 @@ module Reek
38
38
  #
39
39
  # @return [Array<SmellWarning>]
40
40
  #
41
- def inspect(context)
41
+ def sniff(context)
42
42
  expression = context.exp
43
43
  expression.parameter_names.select do |name|
44
44
  sanitized_name = sanitize name
@@ -47,7 +47,7 @@ module Reek
47
47
  #
48
48
  # @return [Array<SmellWarning>]
49
49
  #
50
- def inspect(ctx)
50
+ def sniff(ctx)
51
51
  self.reject_names = value(REJECT_KEY, ctx)
52
52
  self.accept_names = value(ACCEPT_KEY, ctx)
53
53
  variable_names(ctx.exp).select do |name, _lines|
@@ -15,7 +15,7 @@ module Reek
15
15
  # @return [Array<SmellWarning>]
16
16
  #
17
17
  # :reek:FeatureEnvy
18
- def inspect(ctx)
18
+ def sniff(ctx)
19
19
  return [] if ctx.uses_super_with_implicit_arguments?
20
20
  ctx.unused_params.map do |param|
21
21
  name = param.name.to_s
@@ -37,7 +37,7 @@ module Reek
37
37
  # @return [Array<SmellWarning>]
38
38
  #
39
39
  # :reek:FeatureEnvy
40
- def inspect(ctx)
40
+ def sniff(ctx)
41
41
  hits(ctx).map do |hit|
42
42
  name = hit.name
43
43
  smell_warning(
@@ -58,7 +58,7 @@ module Reek
58
58
  #
59
59
  # :reek:FeatureEnvy
60
60
  # :reek:TooManyStatements: { max_statements: 6 }
61
- def inspect(ctx)
61
+ def sniff(ctx)
62
62
  return [] if ctx.singleton_method? || ctx.module_function?
63
63
  return [] if ctx.references_self?
64
64
  return [] if num_helper_methods(ctx).zero?
@@ -67,8 +67,7 @@ module Reek
67
67
  [smell_warning(
68
68
  context: ctx,
69
69
  lines: [ctx.exp.line],
70
- message: "doesn't depend on instance state (maybe move it to another class?)",
71
- parameters: { name: ctx.full_name })]
70
+ message: "doesn't depend on instance state (maybe move it to another class?)")]
72
71
  end
73
72
 
74
73
  private
@@ -74,11 +74,24 @@ module Reek
74
74
 
75
75
  def set_failure_messages_for_smell_details
76
76
  self.failure_message = "Expected #{origin} to reek of #{smell_type} "\
77
- "(which it did) with smell details #{smell_details}, which it didn't"
77
+ "(which it did) with smell details #{smell_details}, which it didn't.\n"\
78
+ "The number of smell details I had to compare with the given one was #{matching_smell_types.count} "\
79
+ "and here they are:\n"\
80
+ "#{all_relevant_smell_details_formatted}"
78
81
  self.failure_message_when_negated = "Expected #{origin} not to reek of "\
79
82
  "#{smell_type} with smell details #{smell_details}, but it did"
80
83
  end
81
84
 
85
+ # :reek:FeatureEnvy
86
+ def all_relevant_smell_details_formatted
87
+ matching_smell_types.each_with_object([]).with_index do |(smell, accumulator), index|
88
+ accumulator << "#{index + 1}.)\n"
89
+ warning_as_hash = smell.smell_warning.to_hash
90
+ warning_as_hash.delete('smell_type')
91
+ accumulator << "#{warning_as_hash}\n"
92
+ end.join
93
+ end
94
+
82
95
  def origin
83
96
  examiner.description
84
97
  end
data/lib/reek/version.rb CHANGED
@@ -7,6 +7,6 @@ module Reek
7
7
  # @public
8
8
  module Version
9
9
  # @public
10
- STRING = '4.2.3'.freeze
10
+ STRING = '4.2.4'.freeze
11
11
  end
12
12
  end
@@ -0,0 +1,7 @@
1
+ <?xml version='1.0'?>
2
+ <checkstyle>
3
+ <file name='samples/smelly.rb'>
4
+ <error column='0' line='4' message='has the name &apos;x&apos;' severity='warning' source='UncommunicativeMethodName'/>
5
+ <error column='0' line='5' message='has the variable name &apos;y&apos;' severity='warning' source='UncommunicativeVariableName'/>
6
+ </file>
7
+ </checkstyle>
data/samples/clean.rb ADDED
@@ -0,0 +1,6 @@
1
+ # Well documented Clean class.
2
+ class Clean
3
+ def hello(argument)
4
+ say argument
5
+ end
6
+ end
File without changes
@@ -0,0 +1 @@
1
+ Not a valid configuration file
File without changes
@@ -0,0 +1,9 @@
1
+ ---
2
+ IrresponsibleModule:
3
+ enabled: false
4
+ "samples/three_clean_files/":
5
+ UtilityFunction:
6
+ enabled: false
7
+ exclude_paths:
8
+ - "samples/two_smelly_files/"
9
+ - "samples/source_with_non_ruby_files/"
@@ -1,5 +1,5 @@
1
1
  ---
2
- UncommunicativeVariableName:
3
- enabled: false
4
2
  UncommunicativeMethodName:
5
3
  enabled: false
4
+ UncommunicativeVariableName:
5
+ enabled: false
@@ -0,0 +1,3 @@
1
+ ---
2
+ UtilityFunction:
3
+ public_methods_only: true
@@ -0,0 +1,3 @@
1
+ ---
2
+ UncommunicativeMethodName:
3
+ enabled: false
@@ -0,0 +1,4 @@
1
+ ---
2
+ exclude_paths:
3
+ - samples/source_with_exclude_paths/ignore_me/
4
+ - samples/source_with_exclude_paths/nested/ignore_me_as_well
File without changes
File without changes
File without changes
data/samples/paths.rb ADDED
@@ -0,0 +1,4 @@
1
+ SAMPLES_PATH = Pathname.new(__dir__).relative_path_from(Pathname.pwd)
2
+ CONFIG_PATH = SAMPLES_PATH.join('configuration')
3
+ CLEAN_FILE = SAMPLES_PATH.join('clean.rb')
4
+ SMELLY_FILE = SAMPLES_PATH.join('smelly.rb')
File without changes
data/samples/smelly.rb ADDED
@@ -0,0 +1,7 @@
1
+ # Smelly class
2
+ class Smelly
3
+ # This will reek of UncommunicativeMethodName
4
+ def x
5
+ y = 10 # This will reek of UncommunicativeVariableName
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ # Smelly class
2
+ # disables :reek:UncommunicativeVariableName
3
+ class Smelly
4
+ # This will reek of UncommunicativeMethodName
5
+ def x
6
+ y = 10 # This will NOT reek of UncommunicativeVariableName
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ # Smelly class for testing purposes
2
+ #
3
+ # Not necessary for the feature per se but for
4
+ # removing distracting output. :reek:UnusedPrivateMethod
5
+ #
6
+ class Klass
7
+ def public_method(arg) arg.to_s; end
8
+ protected
9
+ def protected_method(arg) arg.to_s; end
10
+ private
11
+ def private_method(arg) arg.to_s; end
12
+ end
@@ -19,7 +19,7 @@ RSpec.describe Reek::CLI::Application do
19
19
  SAMPLES_PATH.join('source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb')
20
20
  end
21
21
 
22
- let(:configuration) { test_configuration_for(SAMPLES_PATH.join('configuration/with_excluded_paths.reek')) }
22
+ let(:configuration) { test_configuration_for(CONFIG_PATH.join('with_excluded_paths.reek')) }
23
23
 
24
24
  describe '#execute' do
25
25
  let(:command) { double 'reek_command' }
@@ -10,9 +10,6 @@ RSpec.describe Reek::CLI::Command::ReportCommand do
10
10
  let(:configuration) { double 'configuration' }
11
11
  let(:sources) { [source_file] }
12
12
 
13
- let(:clean_file) { Pathname.glob("#{SAMPLES_PATH}/three_clean_files/*.rb").first }
14
- let(:smelly_file) { Pathname.glob("#{SAMPLES_PATH}/two_smelly_files/*.rb").first }
15
-
16
13
  let(:command) do
17
14
  described_class.new(options: options,
18
15
  sources: sources,
@@ -24,7 +21,7 @@ RSpec.describe Reek::CLI::Command::ReportCommand do
24
21
  end
25
22
 
26
23
  context 'when no smells are found' do
27
- let(:source_file) { clean_file }
24
+ let(:source_file) { CLEAN_FILE }
28
25
 
29
26
  it 'returns a success code' do
30
27
  result = command.execute
@@ -33,7 +30,7 @@ RSpec.describe Reek::CLI::Command::ReportCommand do
33
30
  end
34
31
 
35
32
  context 'when smells are found' do
36
- let(:source_file) { smelly_file }
33
+ let(:source_file) { SMELLY_FILE }
37
34
 
38
35
  it 'returns a failure code' do
39
36
  result = Reek::CLI::Silencer.silently do
@@ -11,11 +11,13 @@ RSpec.describe Reek::Configuration::AppConfiguration do
11
11
  [SAMPLES_PATH.join('two_smelly_files'),
12
12
  SAMPLES_PATH.join('source_with_non_ruby_files')]
13
13
  end
14
+
14
15
  let(:expected_default_directive) do
15
16
  { Reek::Smells::IrresponsibleModule => { 'enabled' => false } }
16
17
  end
18
+
17
19
  let(:expected_directory_directives) do
18
- { Pathname.new('spec/samples/three_clean_files') =>
20
+ { SAMPLES_PATH.join('three_clean_files') =>
19
21
  { Reek::Smells::UtilityFunction => { 'enabled' => false } } }
20
22
  end
21
23
 
@@ -24,13 +26,13 @@ RSpec.describe Reek::Configuration::AppConfiguration do
24
26
  end
25
27
 
26
28
  let(:directory_directives_value) do
27
- { 'spec/samples/three_clean_files' =>
29
+ { 'samples/three_clean_files' =>
28
30
  { 'UtilityFunction' => { 'enabled' => false } } }
29
31
  end
30
32
 
31
33
  let(:exclude_paths_value) do
32
- ['spec/samples/two_smelly_files',
33
- 'spec/samples/source_with_non_ruby_files']
34
+ ['samples/two_smelly_files',
35
+ 'samples/source_with_non_ruby_files']
34
36
  end
35
37
 
36
38
  let(:combined_value) do
@@ -40,7 +42,7 @@ RSpec.describe Reek::Configuration::AppConfiguration do
40
42
  end
41
43
 
42
44
  describe '#from_path' do
43
- let(:full_configuration_path) { SAMPLES_PATH.join('configuration/full_configuration.reek') }
45
+ let(:full_configuration_path) { CONFIG_PATH.join('full_configuration.reek') }
44
46
 
45
47
  it 'properly loads configuration and processes it' do
46
48
  config = described_class.from_path full_configuration_path
@@ -74,14 +76,14 @@ RSpec.describe Reek::Configuration::AppConfiguration do
74
76
 
75
77
  describe '#directive_for' do
76
78
  context 'multiple directory directives and no default directive present' do
77
- let(:source_via) { 'spec/samples/three_clean_files/dummy.rb' }
79
+ let(:source_via) { 'samples/three_clean_files/dummy.rb' }
78
80
  let(:baz_config) { { Reek::Smells::IrresponsibleModule => { enabled: false } } }
79
81
  let(:bang_config) { { Reek::Smells::Attribute => { enabled: true } } }
80
82
 
81
83
  let(:directory_directives) do
82
84
  {
83
- 'spec/samples/two_smelly_files' => baz_config,
84
- 'spec/samples/three_clean_files' => bang_config
85
+ 'samples/two_smelly_files' => baz_config,
86
+ 'samples/three_clean_files' => bang_config
85
87
  }
86
88
  end
87
89
 
@@ -25,47 +25,57 @@ RSpec.describe Reek::Configuration::ConfigurationFileFinder do
25
25
  end
26
26
 
27
27
  it 'returns the file in a parent dir if none in current dir' do
28
- found = described_class.find(current: SAMPLES_PATH.join('no_config_file'))
29
- expect(found).to eq(SAMPLES_PATH.join('exceptions.reek'))
28
+ Dir.mktmpdir(nil, SAMPLES_PATH) do |tempdir|
29
+ found = described_class.find(current: Pathname.new(tempdir))
30
+ expect(found).to eq(SAMPLES_PATH.join('exceptions.reek'))
31
+ end
30
32
  end
31
33
 
32
34
  it 'returns the file even if it’s just ‘.reek’' do
33
- found = described_class.find(current: SAMPLES_PATH.join('masked_by_dotfile'))
34
- expect(found).to eq(SAMPLES_PATH.join('masked_by_dotfile/.reek'))
35
+ found = described_class.find(current: CONFIG_PATH)
36
+ expect(found).to eq(CONFIG_PATH.join('.reek'))
35
37
  end
36
38
 
37
39
  it 'returns the file in home if traversing from the current dir fails' do
38
40
  skip_if_a_config_in_tempdir
39
- Dir.mktmpdir do |tempdir|
40
- current = Pathname.new(tempdir)
41
- found = described_class.find(current: current, home: SAMPLES_PATH)
41
+
42
+ Dir.mktmpdir(nil, SAMPLES_PATH) do |tempdir|
43
+ found = described_class.find(current: Pathname.new(tempdir))
42
44
  expect(found).to eq(SAMPLES_PATH.join('exceptions.reek'))
43
45
  end
44
46
  end
45
47
 
46
48
  it 'prefers the file in :current over one in :home' do
47
- found = described_class.find(current: SAMPLES_PATH, home: SAMPLES_PATH.join('masked_by_dotfile'))
48
- file_in_home = SAMPLES_PATH.join('masked_by_dotfile/.reek')
49
+ found = described_class.find(current: SAMPLES_PATH, home: CONFIG_PATH)
49
50
  file_in_current = SAMPLES_PATH.join('exceptions.reek')
50
- expect(found).not_to eq(file_in_home)
51
+
51
52
  expect(found).to eq(file_in_current)
52
53
  end
53
54
 
54
55
  it 'returns nil when there are no files to find' do
55
56
  skip_if_a_config_in_tempdir
57
+
56
58
  Dir.mktmpdir do |tempdir|
57
59
  current = Pathname.new(tempdir)
58
- home = Pathname.new(tempdir)
60
+ home = Pathname.new(tempdir)
61
+
59
62
  found = described_class.find(current: current, home: home)
63
+
60
64
  expect(found).to be_nil
61
65
  end
62
66
  end
63
67
 
64
68
  it 'does not traverse up from :home' do
65
69
  skip_if_a_config_in_tempdir
70
+
66
71
  Dir.mktmpdir do |tempdir|
67
- current = Pathname.new(tempdir)
68
- found = described_class.find(current: current, home: SAMPLES_PATH.join('no_config_file'))
72
+ dir = Pathname.new(tempdir)
73
+ subdir = dir.join('subdir')
74
+
75
+ FileUtils.mkdir(subdir)
76
+
77
+ found = described_class.find(current: subdir, home: dir)
78
+
69
79
  expect(found).to be_nil
70
80
  end
71
81
  end
@@ -82,9 +92,6 @@ RSpec.describe Reek::Configuration::ConfigurationFileFinder do
82
92
  end
83
93
 
84
94
  describe '.load_from_file' do
85
- let(:sample_configuration_path) do
86
- SAMPLES_PATH.join('configuration/simple_configuration.reek')
87
- end
88
95
  let(:sample_configuration_loaded) do
89
96
  {
90
97
  'UncommunicativeVariableName' => { 'enabled' => false },
@@ -93,7 +100,7 @@ RSpec.describe Reek::Configuration::ConfigurationFileFinder do
93
100
  end
94
101
 
95
102
  it 'loads the configuration from given file' do
96
- configuration = described_class.load_from_file(sample_configuration_path)
103
+ configuration = described_class.load_from_file(CONFIG_PATH.join('full_mask.reek'))
97
104
  expect(configuration).to eq(sample_configuration_loaded)
98
105
  end
99
106
  end