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
@@ -3,6 +3,14 @@ require_lib 'reek/context/module_context'
3
3
  require_relative 'smell_detector_shared'
4
4
 
5
5
  RSpec.describe Reek::Smells::PrimaDonnaMethod do
6
+ it 'reports the right values' do
7
+ src = 'class C; def m!; end; end'
8
+ expect(src).to reek_of :PrimaDonnaMethod,
9
+ lines: [1],
10
+ message: 'has prima donna method `m!`',
11
+ name: :m!
12
+ end
13
+
6
14
  it 'should report nothing when method and bang counterpart exist' do
7
15
  expect('class C; def m; end; def m!; end; end').not_to reek_of(:PrimaDonnaMethod)
8
16
  end
@@ -20,7 +28,7 @@ RSpec.describe Reek::Smells::PrimaDonnaMethod do
20
28
  end
21
29
 
22
30
  it 'should be reported' do
23
- smells = detector.inspect(ctx)
31
+ smells = detector.sniff(ctx)
24
32
  warning = smells[0]
25
33
 
26
34
  expect(warning.smell_type).to eq('PrimaDonnaMethod')
@@ -85,7 +85,7 @@ RSpec.describe Reek::Smells::TooManyInstanceVariables do
85
85
  end
86
86
  EOS
87
87
  ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
88
- detector.inspect(ctx).first
88
+ detector.sniff(ctx).first
89
89
  end
90
90
 
91
91
  it_should_behave_like 'common fields set correctly'
@@ -18,7 +18,7 @@ RSpec.describe Reek::Smells::TooManyMethods do
18
18
  EOS
19
19
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
20
20
  ctx = Reek::Context::ModuleContext.new(nil, syntax_tree)
21
- expect(detector.inspect(ctx)).to be_empty
21
+ expect(detector.sniff(ctx)).to be_empty
22
22
  end
23
23
 
24
24
  it 'should report if we exceed max_methods' do
@@ -31,7 +31,7 @@ RSpec.describe Reek::Smells::TooManyMethods do
31
31
  EOS
32
32
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
33
33
  ctx = Reek::Context::ModuleContext.new(nil, syntax_tree)
34
- smells = detector.inspect(ctx)
34
+ smells = detector.sniff(ctx)
35
35
  expect(smells.length).to eq(1)
36
36
  expect(smells[0].smell_type).to eq(described_class.smell_type)
37
37
  expect(smells[0].parameters[:count]).to eq(3)
@@ -54,7 +54,7 @@ RSpec.describe Reek::Smells::TooManyMethods do
54
54
  EOS
55
55
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
56
56
  ctx = Reek::Context::ModuleContext.new(nil, syntax_tree)
57
- expect(detector.inspect(ctx)).to be_empty
57
+ expect(detector.sniff(ctx)).to be_empty
58
58
  end
59
59
  end
60
60
 
@@ -69,7 +69,7 @@ RSpec.describe Reek::Smells::TooManyMethods do
69
69
 
70
70
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
71
71
  ctx = Reek::Context::ModuleContext.new(nil, syntax_tree)
72
- warning = detector.inspect(ctx)[0]
72
+ warning = detector.sniff(ctx)[0]
73
73
  expect(warning.source).to eq(source_name)
74
74
  expect(warning.smell_type).to eq(described_class.smell_type)
75
75
  expect(warning.parameters[:count]).to eq(3)
@@ -51,7 +51,7 @@ RSpec.describe Reek::Smells::TooManyStatements do
51
51
  ctx = double('method_context').as_null_object
52
52
  expect(ctx).to receive(:number_of_statements).and_return(number_of_statements)
53
53
  expect(ctx).to receive(:config_for).with(described_class).and_return({})
54
- detector.inspect(ctx)
54
+ detector.sniff(ctx)
55
55
  end
56
56
 
57
57
  it 'reports only 1 smell' do
@@ -26,19 +26,19 @@ RSpec.describe Reek::Smells::UncommunicativeMethodName do
26
26
  end
27
27
  end
28
28
 
29
- describe 'inspect' do
29
+ describe 'sniff' do
30
30
  let(:source) { 'def x; end' }
31
31
  let(:context) { code_context(source) }
32
32
  let(:detector) { build(:smell_detector, smell_type: :UncommunicativeMethodName) }
33
33
 
34
34
  it 'returns an array of smell warnings' do
35
- smells = detector.inspect(context)
35
+ smells = detector.sniff(context)
36
36
  expect(smells.length).to eq(1)
37
37
  expect(smells[0]).to be_a_kind_of(Reek::Smells::SmellWarning)
38
38
  end
39
39
 
40
40
  it 'contains proper smell warnings' do
41
- smells = detector.inspect(context)
41
+ smells = detector.sniff(context)
42
42
  warning = smells[0]
43
43
 
44
44
  expect(warning.smell_type).to eq(Reek::Smells::UncommunicativeMethodName.smell_type)
@@ -27,19 +27,19 @@ RSpec.describe Reek::Smells::UncommunicativeModuleName do
27
27
  end
28
28
  end
29
29
 
30
- describe 'inspect' do
30
+ describe 'sniff' do
31
31
  let(:source) { 'class Foo::X; end' }
32
32
  let(:context) { code_context(source) }
33
33
  let(:detector) { build(:smell_detector, smell_type: :UncommunicativeModuleName) }
34
34
 
35
35
  it 'returns an array of smell warnings' do
36
- smells = detector.inspect(context)
36
+ smells = detector.sniff(context)
37
37
  expect(smells.length).to eq(1)
38
38
  expect(smells[0]).to be_a_kind_of(Reek::Smells::SmellWarning)
39
39
  end
40
40
 
41
41
  it 'contains proper smell warnings' do
42
- smells = detector.inspect(context)
42
+ smells = detector.sniff(context)
43
43
  warning = smells[0]
44
44
 
45
45
  expect(warning.smell_type).to eq(Reek::Smells::UncommunicativeModuleName.smell_type)
@@ -72,19 +72,19 @@ RSpec.describe Reek::Smells::UncommunicativeParameterName do
72
72
  end
73
73
  end
74
74
 
75
- describe 'inspect' do
75
+ describe 'sniff' do
76
76
  let(:source) { 'def foo(bar2); baz(bar2); end' }
77
77
  let(:context) { method_context(source) }
78
78
  let(:detector) { build(:smell_detector, smell_type: :UncommunicativeParameterName) }
79
79
 
80
80
  it 'returns an array of smell warnings' do
81
- smells = detector.inspect(context)
81
+ smells = detector.sniff(context)
82
82
  expect(smells.length).to eq(1)
83
83
  expect(smells[0]).to be_a_kind_of(Reek::Smells::SmellWarning)
84
84
  end
85
85
 
86
86
  it 'contains proper smell warnings' do
87
- smells = detector.inspect(context)
87
+ smells = detector.sniff(context)
88
88
  warning = smells[0]
89
89
 
90
90
  expect(warning.smell_type).to eq(Reek::Smells::UncommunicativeParameterName.smell_type)
@@ -51,7 +51,7 @@ RSpec.describe Reek::Smells::UncommunicativeVariableName do
51
51
  src = 'def simple(fred) x = jim(45); x = y end'
52
52
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
53
53
  ctx = Reek::Context::CodeContext.new(nil, syntax_tree)
54
- smells = detector.inspect(ctx)
54
+ smells = detector.sniff(ctx)
55
55
  expect(smells.length).to eq(1)
56
56
  expect(smells[0].smell_type).to eq(described_class.smell_type)
57
57
  expect(smells[0].parameters[:name]).to eq('x')
@@ -164,7 +164,7 @@ RSpec.describe Reek::Smells::UncommunicativeVariableName do
164
164
  EOS
165
165
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
166
166
  ctx = Reek::Context::CodeContext.new(nil, syntax_tree)
167
- detector.inspect(ctx).first
167
+ detector.sniff(ctx).first
168
168
  end
169
169
 
170
170
  it_should_behave_like 'common fields set correctly'
@@ -180,7 +180,7 @@ RSpec.describe Reek::Smells::UncommunicativeVariableName do
180
180
  src = 'def self.bad() x2 = 4; end'
181
181
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
182
182
  ctx = Reek::Context::CodeContext.new(nil, syntax_tree)
183
- detector.inspect(ctx).first
183
+ detector.sniff(ctx).first
184
184
  end
185
185
 
186
186
  it_should_behave_like 'common fields set correctly'
@@ -24,6 +24,10 @@ RSpec.describe Reek::Smells::UtilityFunction do
24
24
  it 'reports the line number of the method' do
25
25
  expect(warning.lines).to eq([1])
26
26
  end
27
+
28
+ it 'has the right message' do
29
+ expect(warning.message).to eq("doesn't depend on instance state (maybe move it to another class?)")
30
+ end
27
31
  end
28
32
  end
29
33
 
@@ -92,7 +96,7 @@ RSpec.describe Reek::Smells::UtilityFunction do
92
96
  def simple(a) a.to_s; end
93
97
  end
94
98
  EOF
95
- expect(src).to reek_of(:UtilityFunction)
99
+ expect(src).to reek_of(:UtilityFunction, context: 'M#simple')
96
100
  end
97
101
 
98
102
  it 'does not report when module_function is called in separate scope' do
@@ -153,18 +157,18 @@ RSpec.describe Reek::Smells::UtilityFunction do
153
157
 
154
158
  context 'with only one call' do
155
159
  it 'reports a call to a parameter' do
156
- expect('def simple(arga) arga.to_s end').to reek_of(:UtilityFunction, name: 'simple')
160
+ expect('def simple(arga) arga.to_s end').to reek_of(:UtilityFunction, context: 'simple')
157
161
  end
158
162
 
159
163
  it 'reports a call to a constant' do
160
- expect('def simple(arga) FIELDS[arga] end').to reek_of(:UtilityFunction)
164
+ expect('def simple(arga) FIELDS[arga] end').to reek_of(:UtilityFunction, context: 'simple')
161
165
  end
162
166
  end
163
167
 
164
168
  context 'with two or more calls' do
165
169
  it 'reports two calls' do
166
170
  src = 'def simple(arga) arga.to_s + arga.to_i end'
167
- expect(src).to reek_of(:UtilityFunction, name: 'simple')
171
+ expect(src).to reek_of(:UtilityFunction, context: 'simple')
168
172
  expect(src).not_to reek_of(:FeatureEnvy)
169
173
  end
170
174
 
@@ -189,7 +193,7 @@ RSpec.describe Reek::Smells::UtilityFunction do
189
193
 
190
194
  it 'should report message chain' do
191
195
  src = 'def simple(arga) arga.b.c end'
192
- expect(src).to reek_of(:UtilityFunction, name: 'simple')
196
+ expect(src).to reek_of(:UtilityFunction, context: 'simple')
193
197
  expect(src).not_to reek_of(:FeatureEnvy)
194
198
  end
195
199
 
@@ -225,7 +229,7 @@ RSpec.describe Reek::Smells::UtilityFunction do
225
229
  def m1(a) a.to_s; end
226
230
  end
227
231
  EOS
228
- expect(src).to reek_of(:UtilityFunction)
232
+ expect(src).to reek_of(:UtilityFunction, context: 'C#m1')
229
233
  end
230
234
 
231
235
  it 'reports protected methods' do
@@ -235,7 +239,7 @@ RSpec.describe Reek::Smells::UtilityFunction do
235
239
  def m1(a) a.to_s; end
236
240
  end
237
241
  EOS
238
- expect(src).to reek_of(:UtilityFunction)
242
+ expect(src).to reek_of(:UtilityFunction, context: 'C#m1')
239
243
  end
240
244
  end
241
245
 
@@ -251,7 +255,7 @@ RSpec.describe Reek::Smells::UtilityFunction do
251
255
  def m1(a) a.to_s; end
252
256
  end
253
257
  EOS
254
- expect(src).to reek_of(:UtilityFunction, name: 'C#m1').with_config(config)
258
+ expect(src).to reek_of(:UtilityFunction, context: 'C#m1').with_config(config)
255
259
  end
256
260
  end
257
261
 
@@ -7,9 +7,11 @@ RSpec.describe Reek::Source::SourceLocator do
7
7
  describe '#sources' do
8
8
  context 'applied to hidden directories' do
9
9
  let(:path) { SAMPLES_PATH.join('source_with_hidden_directories') }
10
+
10
11
  let(:expected_paths) do
11
12
  [SAMPLES_PATH.join('source_with_hidden_directories/uncommunicative_parameter_name.rb')]
12
13
  end
14
+
13
15
  let(:paths_that_are_expected_to_be_ignored) do
14
16
  [SAMPLES_PATH.join('source_with_hidden_directories/.hidden/\
15
17
  uncommunicative_parameter_nameicative_method_name.rb')]
@@ -25,9 +27,11 @@ RSpec.describe Reek::Source::SourceLocator do
25
27
 
26
28
  context 'exclude paths' do
27
29
  let(:configuration) do
28
- test_configuration_for(SAMPLES_PATH.join('configuration/with_excluded_paths.reek'))
30
+ test_configuration_for(CONFIG_PATH.join('with_excluded_paths.reek'))
29
31
  end
32
+
30
33
  let(:path) { SAMPLES_PATH.join('source_with_exclude_paths') }
34
+
31
35
  let(:paths_that_are_expected_to_be_ignored) do
32
36
  [
33
37
  SAMPLES_PATH.join('source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb'),
@@ -1,6 +1,8 @@
1
1
  require 'pathname'
2
2
  require_relative '../../spec_helper'
3
3
  require_lib 'reek/spec'
4
+ require 'active_support/core_ext/string/strip'
5
+ require 'active_support/core_ext/hash/except'
4
6
 
5
7
  RSpec.describe Reek::Spec::ShouldReekOf do
6
8
  describe 'smell type selection' do
@@ -40,16 +42,14 @@ RSpec.describe Reek::Spec::ShouldReekOf do
40
42
  end
41
43
 
42
44
  context 'checking code in a File' do
43
- let(:clean_file) { Pathname.glob("#{SAMPLES_PATH}/three_clean_files/*.rb").first }
44
- let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: '@s') }
45
- let(:smelly_file) { Pathname.glob("#{SAMPLES_PATH}/two_smelly_files/*.rb").first }
45
+ let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeMethodName, name: 'x') }
46
46
 
47
47
  it 'matches a smelly file' do
48
- expect(matcher.matches?(smelly_file)).to be_truthy
48
+ expect(matcher.matches?(SMELLY_FILE)).to be_truthy
49
49
  end
50
50
 
51
51
  it 'doesnt match a fragrant file' do
52
- expect(matcher.matches?(clean_file)).to be_falsey
52
+ expect(matcher.matches?(CLEAN_FILE)).to be_falsey
53
53
  end
54
54
  end
55
55
  end
@@ -65,8 +65,8 @@ RSpec.describe Reek::Spec::ShouldReekOf do
65
65
  end
66
66
 
67
67
  context 'both are matching' do
68
- let(:smelly_code) { 'def x() y = 4; end' }
69
68
  let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: 'y') }
69
+ let(:smelly_code) { 'def x() y = 4; end' }
70
70
 
71
71
  it 'is truthy' do
72
72
  expect(matcher.matches?(smelly_code)).to be_truthy
@@ -99,8 +99,8 @@ RSpec.describe Reek::Spec::ShouldReekOf do
99
99
  end
100
100
 
101
101
  context 'smell type is matching but smell details are not' do
102
- let(:smelly_code) { 'def dummy() y = 4; end' }
103
- let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: 'x') }
102
+ let(:smelly_code) { 'def double_thing() @other.thing.foo + @other.thing.foo end' }
103
+ let(:matcher) { Reek::Spec::ShouldReekOf.new(:DuplicateMethodCall, name: 'foo', count: 15) }
104
104
 
105
105
  it 'is falsey' do
106
106
  expect(matcher.matches?(smelly_code)).to be_falsey
@@ -108,17 +108,24 @@ RSpec.describe Reek::Spec::ShouldReekOf do
108
108
 
109
109
  it 'sets the proper error message' do
110
110
  matcher.matches?(smelly_code)
111
- expect(matcher.failure_message).to\
112
- match('Expected string to reek of UncommunicativeVariableName (which it did) with '\
113
- 'smell details {:name=>"x"}, which it didn\'t')
111
+ expected = <<-EOS.strip_heredoc
112
+ Expected string to reek of DuplicateMethodCall (which it did) with smell details {:name=>"foo", :count=>15}, which it didn't.
113
+ The number of smell details I had to compare with the given one was 2 and here they are:
114
+ 1.)
115
+ {"context"=>"double_thing", "lines"=>[1, 1], "message"=>"calls @other.thing 2 times", "source"=>"string", "name"=>"@other.thing", "count"=>2}
116
+ 2.)
117
+ {"context"=>"double_thing", "lines"=>[1, 1], "message"=>"calls @other.thing.foo 2 times", "source"=>"string", "name"=>"@other.thing.foo", "count"=>2}
118
+ EOS
119
+
120
+ expect(matcher.failure_message).to eq(expected)
114
121
  end
115
122
 
116
123
  it 'sets the proper error message when negated' do
117
124
  matcher.matches?(smelly_code)
118
125
 
119
126
  expect(matcher.failure_message_when_negated).to\
120
- match('Expected string not to reek of UncommunicativeVariableName with smell '\
121
- 'details {:name=>"x"}, but it did')
127
+ match('Expected string not to reek of DuplicateMethodCall with smell '\
128
+ 'details {:name=>"foo", :count=>15}, but it did')
122
129
  end
123
130
  end
124
131
  end
@@ -22,35 +22,30 @@ RSpec.describe Reek::Spec::ShouldReek do
22
22
  end
23
23
 
24
24
  describe 'checking code in a File' do
25
- let(:clean_file) { SAMPLES_PATH.join('three_clean_files/clean_one.rb') }
26
- let(:smelly_file) { SAMPLES_PATH.join('two_smelly_files/dirty_one.rb') }
27
- let(:masked_file) { SAMPLES_PATH.join('clean_due_to_masking/dirty_one.rb') }
28
-
29
25
  context 'matcher without masking' do
30
26
  let(:matcher) { Reek::Spec::ShouldReek.new }
31
27
 
32
28
  it 'matches a smelly File' do
33
- expect(matcher.matches?(smelly_file)).to be_truthy
29
+ expect(matcher.matches?(SMELLY_FILE)).to be_truthy
34
30
  end
35
31
 
36
32
  it 'doesnt match a fragrant File' do
37
- expect(matcher.matches?(clean_file)).to be_falsey
33
+ expect(matcher.matches?(CLEAN_FILE)).to be_falsey
38
34
  end
39
35
 
40
36
  it 'reports the smells when should_not fails' do
41
- matcher.matches?(smelly_file)
42
- expect(matcher.failure_message_when_negated).to match('UncommunicativeVariableName')
37
+ matcher.matches?(SMELLY_FILE)
38
+ expect(matcher.failure_message_when_negated).to match('UncommunicativeMethodName')
43
39
  end
44
40
  end
45
41
 
46
42
  context 'matcher without masking' do
47
- let(:path) { SAMPLES_PATH.join('clean_due_to_masking/masked.reek') }
43
+ let(:path) { CONFIG_PATH.join('full_mask.reek') }
48
44
  let(:configuration) { test_configuration_for(path) }
49
45
  let(:matcher) { Reek::Spec::ShouldReek.new(configuration: configuration) }
50
- let(:masked_file) { SAMPLES_PATH.join('clean_due_to_masking/dirty_one.rb') }
51
46
 
52
47
  it 'masks smells using the relevant configuration' do
53
- expect(matcher.matches?(masked_file)).to be_falsey
48
+ expect(matcher.matches?(SMELLY_FILE)).to be_falsey
54
49
  end
55
50
  end
56
51
  end
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,8 @@ require_relative '../lib/reek/spec'
4
4
  require_relative '../lib/reek/ast/ast_node_class_map'
5
5
  require_relative '../lib/reek/configuration/app_configuration'
6
6
 
7
+ require_relative '../samples/paths'
8
+
7
9
  Reek::CLI::Silencer.silently do
8
10
  begin
9
11
  require 'pry-byebug'
@@ -14,8 +16,6 @@ end
14
16
  require 'factory_girl'
15
17
  FactoryGirl.find_definitions
16
18
 
17
- SAMPLES_PATH = Pathname.new("#{__dir__}/samples").relative_path_from(Pathname.pwd)
18
-
19
19
  # Simple helpers for our specs.
20
20
  module Helpers
21
21
  def test_configuration_for(config)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reek
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.3
4
+ version: 4.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Rutherford
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-08-05 00:00:00.000000000 Z
14
+ date: 2016-08-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: codeclimate-engine-rb
@@ -275,6 +275,32 @@ files:
275
275
  - logo/reek.text.png
276
276
  - logo/reek.text.svg
277
277
  - reek.gemspec
278
+ - samples/checkstyle.xml
279
+ - samples/clean.rb
280
+ - samples/configuration/.reek
281
+ - samples/configuration/corrupt.reek
282
+ - samples/configuration/empty.reek
283
+ - samples/configuration/full_configuration.reek
284
+ - samples/configuration/full_mask.reek
285
+ - samples/configuration/non_public_modifiers_mask.reek
286
+ - samples/configuration/partial_mask.reek
287
+ - samples/configuration/with_excluded_paths.reek
288
+ - samples/exceptions.reek
289
+ - samples/inline.rb
290
+ - samples/optparse.rb
291
+ - samples/paths.rb
292
+ - samples/redcloth.rb
293
+ - samples/smelly.rb
294
+ - samples/smelly_with_inline_mask.rb
295
+ - samples/smelly_with_modifiers.rb
296
+ - samples/source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb
297
+ - samples/source_with_exclude_paths/nested/ignore_me_as_well/irresponsible_module.rb
298
+ - samples/source_with_exclude_paths/nested/uncommunicative_parameter_name.rb
299
+ - samples/source_with_hidden_directories/.hidden/uncommunicative_method_name.rb
300
+ - samples/source_with_hidden_directories/uncommunicative_parameter_name.rb
301
+ - samples/source_with_non_ruby_files/gibberish
302
+ - samples/source_with_non_ruby_files/python_source.py
303
+ - samples/source_with_non_ruby_files/uncommunicative_parameter_name.rb
278
304
  - spec/factories/factories.rb
279
305
  - spec/quality/reek_source_spec.rb
280
306
  - spec/reek/ast/node_spec.rb
@@ -349,39 +375,6 @@ files:
349
375
  - spec/reek/spec/should_reek_spec.rb
350
376
  - spec/reek/spec/smell_matcher_spec.rb
351
377
  - spec/reek/tree_dresser_spec.rb
352
- - spec/samples/all_but_one_masked/clean_one.rb
353
- - spec/samples/all_but_one_masked/dirty.rb
354
- - spec/samples/all_but_one_masked/masked.reek
355
- - spec/samples/checkstyle.xml
356
- - spec/samples/clean_due_to_masking/clean_one.rb
357
- - spec/samples/clean_due_to_masking/clean_three.rb
358
- - spec/samples/clean_due_to_masking/clean_two.rb
359
- - spec/samples/clean_due_to_masking/dirty_one.rb
360
- - spec/samples/clean_due_to_masking/dirty_two.rb
361
- - spec/samples/clean_due_to_masking/masked.reek
362
- - spec/samples/configuration/full_configuration.reek
363
- - spec/samples/configuration/simple_configuration.reek
364
- - spec/samples/configuration/with_excluded_paths.reek
365
- - spec/samples/exceptions.reek
366
- - spec/samples/inline.rb
367
- - spec/samples/masked_by_dotfile/.reek
368
- - spec/samples/masked_by_dotfile/dirty.rb
369
- - spec/samples/no_config_file/dirty.rb
370
- - spec/samples/optparse.rb
371
- - spec/samples/redcloth.rb
372
- - spec/samples/source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb
373
- - spec/samples/source_with_exclude_paths/nested/ignore_me_as_well/irresponsible_module.rb
374
- - spec/samples/source_with_exclude_paths/nested/uncommunicative_parameter_name.rb
375
- - spec/samples/source_with_hidden_directories/.hidden/uncommunicative_method_name.rb
376
- - spec/samples/source_with_hidden_directories/uncommunicative_parameter_name.rb
377
- - spec/samples/source_with_non_ruby_files/gibberish
378
- - spec/samples/source_with_non_ruby_files/python_source.py
379
- - spec/samples/source_with_non_ruby_files/uncommunicative_parameter_name.rb
380
- - spec/samples/three_clean_files/clean_one.rb
381
- - spec/samples/three_clean_files/clean_three.rb
382
- - spec/samples/three_clean_files/clean_two.rb
383
- - spec/samples/two_smelly_files/dirty_one.rb
384
- - spec/samples/two_smelly_files/dirty_two.rb
385
378
  - spec/spec_helper.rb
386
379
  - tasks/ataru.rake
387
380
  - tasks/configuration.rake
@@ -419,4 +412,3 @@ signing_key:
419
412
  specification_version: 4
420
413
  summary: Code smell detector for Ruby
421
414
  test_files: []
422
- has_rdoc: