reek 3.2.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Rakefile +0 -1
  4. data/config/defaults.reek +1 -1
  5. data/features/samples.feature +17 -16
  6. data/lib/reek.rb +0 -1
  7. data/lib/reek/ast/ast_node_class_map.rb +5 -1
  8. data/lib/reek/ast/node.rb +10 -3
  9. data/lib/reek/ast/object_refs.rb +11 -5
  10. data/lib/reek/ast/reference_collector.rb +6 -2
  11. data/lib/reek/ast/sexp_extensions.rb +42 -1
  12. data/lib/reek/ast/sexp_formatter.rb +2 -1
  13. data/lib/reek/cli/application.rb +12 -9
  14. data/lib/reek/cli/command.rb +6 -0
  15. data/lib/reek/cli/input.rb +4 -4
  16. data/lib/reek/cli/option_interpreter.rb +11 -7
  17. data/lib/reek/cli/options.rb +42 -40
  18. data/lib/reek/cli/reek_command.rb +3 -3
  19. data/lib/reek/cli/silencer.rb +12 -3
  20. data/lib/reek/cli/warning_collector.rb +8 -3
  21. data/lib/reek/code_comment.rb +6 -1
  22. data/lib/reek/configuration/app_configuration.rb +65 -100
  23. data/lib/reek/configuration/configuration_file_finder.rb +4 -13
  24. data/lib/reek/configuration/configuration_validator.rb +35 -0
  25. data/lib/reek/configuration/default_directive.rb +12 -0
  26. data/lib/reek/configuration/directory_directives.rb +54 -0
  27. data/lib/reek/configuration/excluded_paths.rb +18 -0
  28. data/lib/reek/context/code_context.rb +19 -17
  29. data/lib/reek/examiner.rb +9 -7
  30. data/lib/reek/rake/task.rb +12 -22
  31. data/lib/reek/report/formatter.rb +6 -1
  32. data/lib/reek/report/report.rb +22 -13
  33. data/lib/reek/smells/attribute.rb +6 -53
  34. data/lib/reek/smells/control_parameter.rb +21 -13
  35. data/lib/reek/smells/data_clump.rb +17 -9
  36. data/lib/reek/smells/duplicate_method_call.rb +12 -6
  37. data/lib/reek/smells/long_parameter_list.rb +2 -2
  38. data/lib/reek/smells/long_yield_list.rb +4 -4
  39. data/lib/reek/smells/nested_iterators.rb +4 -2
  40. data/lib/reek/smells/nil_check.rb +6 -2
  41. data/lib/reek/smells/repeated_conditional.rb +3 -3
  42. data/lib/reek/smells/smell_configuration.rb +17 -7
  43. data/lib/reek/smells/smell_detector.rb +24 -11
  44. data/lib/reek/smells/smell_repository.rb +1 -1
  45. data/lib/reek/smells/smell_warning.rb +6 -6
  46. data/lib/reek/smells/too_many_instance_variables.rb +2 -2
  47. data/lib/reek/smells/too_many_methods.rb +4 -4
  48. data/lib/reek/smells/too_many_statements.rb +4 -4
  49. data/lib/reek/smells/uncommunicative_method_name.rb +5 -5
  50. data/lib/reek/smells/uncommunicative_module_name.rb +6 -6
  51. data/lib/reek/smells/uncommunicative_parameter_name.rb +8 -4
  52. data/lib/reek/smells/uncommunicative_variable_name.rb +9 -5
  53. data/lib/reek/smells/utility_function.rb +1 -1
  54. data/lib/reek/source/source_code.rb +5 -1
  55. data/lib/reek/source/source_locator.rb +3 -2
  56. data/lib/reek/spec.rb +3 -3
  57. data/lib/reek/spec/should_reek.rb +10 -5
  58. data/lib/reek/spec/should_reek_of.rb +9 -6
  59. data/lib/reek/spec/should_reek_only_of.rb +13 -8
  60. data/lib/reek/tree_dresser.rb +6 -2
  61. data/lib/reek/tree_walker.rb +40 -32
  62. data/lib/reek/version.rb +1 -1
  63. data/reek.gemspec +1 -1
  64. data/spec/reek/ast/node_spec.rb +1 -2
  65. data/spec/reek/ast/object_refs_spec.rb +40 -42
  66. data/spec/reek/ast/sexp_extensions_spec.rb +98 -104
  67. data/spec/reek/cli/warning_collector_spec.rb +8 -12
  68. data/spec/reek/code_comment_spec.rb +3 -5
  69. data/spec/reek/configuration/app_configuration_spec.rb +43 -57
  70. data/spec/reek/configuration/configuration_file_finder_spec.rb +5 -7
  71. data/spec/reek/configuration/default_directive_spec.rb +13 -0
  72. data/spec/reek/configuration/directory_directives_spec.rb +89 -0
  73. data/spec/reek/configuration/excluded_paths_spec.rb +30 -0
  74. data/spec/reek/context/code_context_spec.rb +63 -62
  75. data/spec/reek/context/method_context_spec.rb +8 -12
  76. data/spec/reek/context/module_context_spec.rb +1 -1
  77. data/spec/reek/context/root_context_spec.rb +3 -7
  78. data/spec/reek/examiner_spec.rb +14 -25
  79. data/spec/reek/smells/attribute_spec.rb +2 -4
  80. data/spec/reek/smells/boolean_parameter_spec.rb +5 -7
  81. data/spec/reek/smells/class_variable_spec.rb +29 -44
  82. data/spec/reek/smells/control_parameter_spec.rb +7 -9
  83. data/spec/reek/smells/data_clump_spec.rb +25 -32
  84. data/spec/reek/smells/duplicate_method_call_spec.rb +8 -7
  85. data/spec/reek/smells/feature_envy_spec.rb +16 -17
  86. data/spec/reek/smells/irresponsible_module_spec.rb +2 -4
  87. data/spec/reek/smells/long_parameter_list_spec.rb +6 -9
  88. data/spec/reek/smells/long_yield_list_spec.rb +6 -9
  89. data/spec/reek/smells/nested_iterators_spec.rb +14 -16
  90. data/spec/reek/smells/repeated_conditional_spec.rb +25 -25
  91. data/spec/reek/smells/smell_configuration_spec.rb +32 -27
  92. data/spec/reek/smells/smell_detector_shared.rb +12 -13
  93. data/spec/reek/smells/smell_warning_spec.rb +54 -58
  94. data/spec/reek/smells/too_many_instance_variables_spec.rb +9 -9
  95. data/spec/reek/smells/too_many_methods_spec.rb +13 -14
  96. data/spec/reek/smells/too_many_statements_spec.rb +8 -10
  97. data/spec/reek/smells/uncommunicative_method_name_spec.rb +8 -9
  98. data/spec/reek/smells/uncommunicative_module_name_spec.rb +12 -13
  99. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +7 -10
  100. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +16 -20
  101. data/spec/reek/smells/utility_function_spec.rb +11 -15
  102. data/spec/reek/source/source_code_spec.rb +6 -11
  103. data/spec/reek/spec/should_reek_of_spec.rb +19 -30
  104. data/spec/reek/spec/should_reek_only_of_spec.rb +28 -34
  105. data/spec/reek/tree_walker_spec.rb +14 -2
  106. data/spec/spec_helper.rb +2 -3
  107. data/tasks/test.rake +0 -5
  108. metadata +10 -6
  109. data/docs/Configuration-Files.md +0 -49
  110. data/spec/gem/updates_spec.rb +0 -25
  111. data/spec/gem/yard_spec.rb +0 -11
  112. data/spec/reek/smells/behaves_like_variable_detector.rb +0 -39
@@ -6,9 +6,10 @@ require_relative 'smell_detector_shared'
6
6
 
7
7
  RSpec.describe Reek::Smells::DuplicateMethodCall do
8
8
  context 'when a smell is reported' do
9
- before :each do
10
- @source_name = 'dummy_source'
11
- @detector = build(:smell_detector, smell_type: :DuplicateMethodCall, source: @source_name)
9
+ let(:detector) { build(:smell_detector, smell_type: :DuplicateMethodCall, source: source_name) }
10
+ let(:source_name) { 'dummy_source' }
11
+
12
+ let(:warning) do
12
13
  src = <<-EOS
13
14
  def double_thing(other)
14
15
  other[@thing]
@@ -17,20 +18,20 @@ RSpec.describe Reek::Smells::DuplicateMethodCall do
17
18
  end
18
19
  EOS
19
20
  ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
20
- smells = @detector.examine_context(ctx)
21
+ smells = detector.examine_context(ctx)
21
22
  expect(smells.length).to eq(1)
22
- @warning = smells[0]
23
+ smells.first
23
24
  end
24
25
 
25
26
  it_should_behave_like 'SmellDetector'
26
27
  it_should_behave_like 'common fields set correctly'
27
28
 
28
29
  it 'reports the call' do
29
- expect(@warning.parameters[:name]).to eq('other[@thing]')
30
+ expect(warning.parameters[:name]).to eq('other[@thing]')
30
31
  end
31
32
 
32
33
  it 'reports the correct lines' do
33
- expect(@warning.lines).to eq([2, 4])
34
+ expect(warning.lines).to eq([2, 4])
34
35
  end
35
36
  end
36
37
 
@@ -213,53 +213,52 @@ RSpec.describe Reek::Smells::FeatureEnvy do
213
213
  end
214
214
 
215
215
  RSpec.describe Reek::Smells::FeatureEnvy do
216
- before(:each) do
217
- @source_name = 'string'
218
- @detector = build(:smell_detector, smell_type: :FeatureEnvy, source: @source_name)
219
- end
216
+ let(:detector) { build(:smell_detector, smell_type: :FeatureEnvy, source: source_name) }
217
+ let(:source_name) { 'string' }
220
218
 
221
219
  it_should_behave_like 'SmellDetector'
222
220
 
223
221
  context 'when a smell is reported' do
224
- before :each do
225
- @receiver = 'other'
222
+ let(:receiver) { 'other' }
223
+
224
+ let(:smells) do
226
225
  src = <<-EOS
227
226
  def envious(other)
228
- #{@receiver}.call
227
+ #{receiver}.call
229
228
  self.do_nothing
230
- #{@receiver}.other
231
- #{@receiver}.fred
229
+ #{receiver}.other
230
+ #{receiver}.fred
232
231
  end
233
232
  EOS
234
- @smells = Reek::Examiner.new(src, ['FeatureEnvy']).smells
233
+ Reek::Examiner.new(src, ['FeatureEnvy']).smells
235
234
  end
236
235
 
237
236
  it 'reports only that smell' do
238
- expect(@smells.length).to eq(1)
237
+ expect(smells.length).to eq(1)
239
238
  end
240
239
 
241
240
  it 'reports the source' do
242
- expect(@smells[0].source).to eq(@source_name)
241
+ expect(smells[0].source).to eq(source_name)
243
242
  end
244
243
 
245
244
  it 'reports the smell class' do
246
- expect(@smells[0].smell_category).to eq(described_class.smell_category)
245
+ expect(smells[0].smell_category).to eq(described_class.smell_category)
247
246
  end
248
247
 
249
248
  it 'reports the smell sub class' do
250
- expect(@smells[0].smell_type).to eq(described_class.smell_type)
249
+ expect(smells[0].smell_type).to eq(described_class.smell_type)
251
250
  end
252
251
 
253
252
  it 'reports the envious receiver' do
254
- expect(@smells[0].parameters[:name]).to eq(@receiver)
253
+ expect(smells[0].parameters[:name]).to eq(receiver)
255
254
  end
256
255
 
257
256
  it 'reports the number of references' do
258
- expect(@smells[0].parameters[:count]).to eq(3)
257
+ expect(smells[0].parameters[:count]).to eq(3)
259
258
  end
260
259
 
261
260
  it 'reports the referring lines' do
262
- expect(@smells[0].lines).to eq([2, 4, 5])
261
+ expect(smells[0].lines).to eq([2, 4, 5])
263
262
  end
264
263
  end
265
264
  end
@@ -184,10 +184,8 @@ RSpec.describe Reek::Smells::IrresponsibleModule do
184
184
  end
185
185
 
186
186
  context 'when a smell is reported' do
187
- before do
188
- @source_name = 'dummy_source'
189
- @detector = build(:smell_detector, smell_type: :IrresponsibleModule, source: @source_name)
190
- end
187
+ let(:detector) { build(:smell_detector, smell_type: :IrresponsibleModule, source: source_name) }
188
+ let(:source_name) { 'dummy_source' }
191
189
 
192
190
  it_should_behave_like 'SmellDetector'
193
191
  end
@@ -74,15 +74,13 @@ RSpec.describe Reek::Smells::LongParameterList do
74
74
  end
75
75
 
76
76
  RSpec.describe Reek::Smells::LongParameterList do
77
- before(:each) do
78
- @source_name = 'dummy_source'
79
- @detector = build(:smell_detector, smell_type: :LongParameterList, source: @source_name)
80
- end
77
+ let(:detector) { build(:smell_detector, smell_type: :LongParameterList, source: source_name) }
78
+ let(:source_name) { 'dummy_source' }
81
79
 
82
80
  it_should_behave_like 'SmellDetector'
83
81
 
84
82
  context 'when a smell is reported' do
85
- before :each do
83
+ let(:warning) do
86
84
  src = <<-EOS
87
85
  def badguy(arga, argb, argc, argd)
88
86
  f(3)
@@ -90,18 +88,17 @@ RSpec.describe Reek::Smells::LongParameterList do
90
88
  end
91
89
  EOS
92
90
  ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
93
- @smells = @detector.examine_context(ctx)
94
- @warning = @smells[0]
91
+ detector.examine_context(ctx).first
95
92
  end
96
93
 
97
94
  it_should_behave_like 'common fields set correctly'
98
95
 
99
96
  it 'reports the number of parameters' do
100
- expect(@warning.parameters[:count]).to eq(4)
97
+ expect(warning.parameters[:count]).to eq(4)
101
98
  end
102
99
 
103
100
  it 'reports the line number of the method' do
104
- expect(@warning.lines).to eq([1])
101
+ expect(warning.lines).to eq([1])
105
102
  end
106
103
  end
107
104
  end
@@ -4,10 +4,8 @@ require_relative '../../../lib/reek/smells/long_yield_list'
4
4
  require_relative 'smell_detector_shared'
5
5
 
6
6
  RSpec.describe Reek::Smells::LongYieldList do
7
- before(:each) do
8
- @source_name = 'dummy_source'
9
- @detector = build(:smell_detector, smell_type: :LongYieldList, source: @source_name)
10
- end
7
+ let(:detector) { build(:smell_detector, smell_type: :LongYieldList, source: source_name) }
8
+ let(:source_name) { 'dummy_source' }
11
9
 
12
10
  it_should_behave_like 'SmellDetector'
13
11
 
@@ -31,7 +29,7 @@ RSpec.describe Reek::Smells::LongYieldList do
31
29
  end
32
30
 
33
31
  context 'when a smells is reported' do
34
- before :each do
32
+ let(:warning) do
35
33
  src = <<-EOS
36
34
  def simple(arga, argb, &blk)
37
35
  f(3)
@@ -39,15 +37,14 @@ RSpec.describe Reek::Smells::LongYieldList do
39
37
  end
40
38
  EOS
41
39
  ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
42
- @smells = @detector.examine_context(ctx)
43
- @warning = @smells[0]
40
+ detector.examine_context(ctx).first
44
41
  end
45
42
 
46
43
  it_should_behave_like 'common fields set correctly'
47
44
 
48
45
  it 'reports the correct values' do
49
- expect(@warning.parameters[:count]).to eq(4)
50
- expect(@warning.lines).to eq([3])
46
+ expect(warning.parameters[:count]).to eq(4)
47
+ expect(warning.lines).to eq([3])
51
48
  end
52
49
  end
53
50
  end
@@ -123,11 +123,11 @@ RSpec.describe Reek::Smells::NestedIterators do
123
123
  end
124
124
 
125
125
  context 'when the allowed nesting depth is 3' do
126
- before :each do
127
- @config = { Reek::Smells::NestedIterators =>
128
- { Reek::Smells::NestedIterators::MAX_ALLOWED_NESTING_KEY => 3 } }
126
+ let(:configuration) do
127
+ config = { Reek::Smells::NestedIterators =>
128
+ { Reek::Smells::NestedIterators::MAX_ALLOWED_NESTING_KEY => 3 } }
129
+ test_configuration_for(config)
129
130
  end
130
- let(:configuration) { test_configuration_for(@config) }
131
131
 
132
132
  it 'should not report nested iterators 2 levels deep' do
133
133
  src = <<-EOS
@@ -161,11 +161,11 @@ RSpec.describe Reek::Smells::NestedIterators do
161
161
  end
162
162
 
163
163
  context 'when ignoring iterators' do
164
- before :each do
165
- @config = { Reek::Smells::NestedIterators =>
166
- { Reek::Smells::NestedIterators::IGNORE_ITERATORS_KEY => ['ignore_me'] } }
164
+ let(:configuration) do
165
+ config = { Reek::Smells::NestedIterators =>
166
+ { Reek::Smells::NestedIterators::IGNORE_ITERATORS_KEY => ['ignore_me'] } }
167
+ test_configuration_for(config)
167
168
  end
168
- let(:configuration) { test_configuration_for(@config) }
169
169
 
170
170
  it 'should not report nesting the ignored iterator inside another' do
171
171
  src = 'def bad(fred) @fred.each {|item| item.ignore_me {|ting| ting.ting} } end'
@@ -207,15 +207,13 @@ RSpec.describe Reek::Smells::NestedIterators do
207
207
  end
208
208
 
209
209
  RSpec.describe Reek::Smells::NestedIterators do
210
- before(:each) do
211
- @source_name = 'dummy_source'
212
- @detector = build(:smell_detector, smell_type: :NestedIterators, source: @source_name)
213
- end
210
+ let(:detector) { build(:smell_detector, smell_type: :NestedIterators, source: source_name) }
211
+ let(:source_name) { 'dummy_source' }
214
212
 
215
213
  it_should_behave_like 'SmellDetector'
216
214
 
217
215
  context 'when a smell is reported' do
218
- before :each do
216
+ let(:warning) do
219
217
  src = <<-EOS
220
218
  def fred()
221
219
  nothing.each do |item|
@@ -224,14 +222,14 @@ RSpec.describe Reek::Smells::NestedIterators do
224
222
  end
225
223
  EOS
226
224
  ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
227
- @warning = @detector.examine_context(ctx)[0]
225
+ detector.examine_context(ctx).first
228
226
  end
229
227
 
230
228
  it_should_behave_like 'common fields set correctly'
231
229
 
232
230
  it 'reports correct values' do
233
- expect(@warning.parameters[:count]).to eq(2)
234
- expect(@warning.lines).to eq([3])
231
+ expect(warning.parameters[:count]).to eq(2)
232
+ expect(warning.lines).to eq([3])
235
233
  end
236
234
  end
237
235
  end
@@ -5,10 +5,8 @@ require_relative 'smell_detector_shared'
5
5
  require_relative '../../../lib/reek/source/source_code'
6
6
 
7
7
  RSpec.describe Reek::Smells::RepeatedConditional do
8
- before(:each) do
9
- @source_name = 'dummy_source'
10
- @detector = build(:smell_detector, smell_type: :RepeatedConditional, source: @source_name)
11
- end
8
+ let(:detector) { build(:smell_detector, smell_type: :RepeatedConditional, source: source_name) }
9
+ let(:source_name) { 'dummy_source' }
12
10
 
13
11
  it_should_behave_like 'SmellDetector'
14
12
 
@@ -16,7 +14,7 @@ RSpec.describe Reek::Smells::RepeatedConditional do
16
14
  it 'gathers an empty hash' do
17
15
  ast = Reek::Source::SourceCode.from('module Stable; end').syntax_tree
18
16
  ctx = Reek::Context::CodeContext.new(nil, ast)
19
- expect(@detector.conditional_counts(ctx).length).to eq(0)
17
+ expect(detector.conditional_counts(ctx).length).to eq(0)
20
18
  end
21
19
  end
22
20
 
@@ -24,7 +22,7 @@ RSpec.describe Reek::Smells::RepeatedConditional do
24
22
  it 'does not record the condition' do
25
23
  ast = Reek::Source::SourceCode.from('def fred() yield(3) if block_given?; end').syntax_tree
26
24
  ctx = Reek::Context::CodeContext.new(nil, ast)
27
- expect(@detector.conditional_counts(ctx).length).to eq(0)
25
+ expect(detector.conditional_counts(ctx).length).to eq(0)
28
26
  end
29
27
  end
30
28
 
@@ -32,53 +30,55 @@ RSpec.describe Reek::Smells::RepeatedConditional do
32
30
  it 'does not record the condition' do
33
31
  ast = Reek::Source::SourceCode.from('def fred() case; when 3; end; end').syntax_tree
34
32
  ctx = Reek::Context::CodeContext.new(nil, ast)
35
- expect(@detector.conditional_counts(ctx).length).to eq(0)
33
+ expect(detector.conditional_counts(ctx).length).to eq(0)
36
34
  end
37
35
  end
38
36
 
39
37
  context 'with three identical conditionals' do
40
- before :each do
41
- @cond = '@field == :sym'
42
- @cond_expr = Reek::Source::SourceCode.from(@cond).syntax_tree
38
+ let(:cond) { '@field == :sym' }
39
+ let(:cond_expr) { Reek::Source::SourceCode.from(cond).syntax_tree }
40
+
41
+ let(:conds) do
43
42
  src = <<-EOS
44
43
  class Scrunch
45
44
  def first
46
45
  puts "hello" if @debug
47
- return #{@cond} ? 0 : 3;
46
+ return #{cond} ? 0 : 3;
48
47
  end
49
48
  def second
50
- if #{@cond}
49
+ if #{cond}
51
50
  @other += " quarts"
52
51
  end
53
52
  end
54
53
  def third
55
- raise 'flu!' unless #{@cond}
54
+ raise 'flu!' unless #{cond}
56
55
  end
57
56
  end
58
57
  EOS
59
58
 
60
59
  ast = Reek::Source::SourceCode.from(src).syntax_tree
61
- @ctx = Reek::Context::CodeContext.new(nil, ast)
62
- @conds = @detector.conditional_counts(@ctx)
60
+ ctx = Reek::Context::CodeContext.new(nil, ast)
61
+ detector.conditional_counts(ctx)
63
62
  end
64
63
 
65
64
  it 'finds both conditionals' do
66
- expect(@conds.length).to eq(2)
65
+ expect(conds.length).to eq(2)
67
66
  end
68
67
 
69
68
  it 'returns the condition expr' do
70
- expect(@conds.keys[1]).to eq(@cond_expr)
69
+ expect(conds.keys[1]).to eq(cond_expr)
71
70
  end
72
71
 
73
72
  it 'knows there are three copies' do
74
- expect(@conds.values[1].length).to eq(3)
73
+ expect(conds.values[1].length).to eq(3)
75
74
  end
76
75
  end
77
76
 
78
77
  context 'with a matching if and case' do
79
- before :each do
80
- cond = '@field == :sym'
81
- @cond_expr = Reek::Source::SourceCode.from(cond).syntax_tree
78
+ let(:cond) { '@field == :sym' }
79
+ let(:cond_expr) { Reek::Source::SourceCode.from(cond).syntax_tree }
80
+
81
+ let(:conds) do
82
82
  src = <<-EOS
83
83
  class Scrunch
84
84
  def alpha
@@ -95,19 +95,19 @@ RSpec.describe Reek::Smells::RepeatedConditional do
95
95
 
96
96
  ast = Reek::Source::SourceCode.from(src).syntax_tree
97
97
  ctx = Reek::Context::CodeContext.new(nil, ast)
98
- @conds = @detector.conditional_counts(ctx)
98
+ detector.conditional_counts(ctx)
99
99
  end
100
100
 
101
101
  it 'finds exactly one conditional' do
102
- expect(@conds.length).to eq(1)
102
+ expect(conds.length).to eq(1)
103
103
  end
104
104
 
105
105
  it 'returns the condition expr' do
106
- expect(@conds.keys[0]).to eq(@cond_expr)
106
+ expect(conds.keys[0]).to eq(cond_expr)
107
107
  end
108
108
 
109
109
  it 'knows there are two copies' do
110
- expect(@conds.values[0].length).to eq(2)
110
+ expect(conds.values[0].length).to eq(2)
111
111
  end
112
112
  end
113
113
  end
@@ -8,47 +8,52 @@ RSpec.describe Reek::Smells::SmellConfiguration do
8
8
  end
9
9
 
10
10
  context 'when overriding default configs' do
11
- before(:each) do
12
- @base_config = { 'enabled' => true, 'exclude' => [],
13
- 'reject' => [/^.$/, /[0-9]$/, /[A-Z]/],
14
- 'accept' => ['_'] }
15
- @smell_config = described_class.new(@base_config)
11
+ let(:base_config) do
12
+ {
13
+ 'accept' => ['_'],
14
+ 'enabled' => true,
15
+ 'exclude' => [],
16
+ 'reject' => [/^.$/, /[0-9]$/, /[A-Z]/]
17
+ }
16
18
  end
17
19
 
18
- it { expect(@smell_config.merge!({})).to eq(@base_config) }
19
- it { expect(@smell_config.merge!('enabled' => true)).to eq(@base_config) }
20
- it { expect(@smell_config.merge!('exclude' => [])).to eq(@base_config) }
21
- it { expect(@smell_config.merge!('accept' => ['_'])).to eq(@base_config) }
20
+ let(:smell_config) { described_class.new(base_config) }
21
+
22
+ it { expect(smell_config.merge!({})).to eq(base_config) }
23
+ it { expect(smell_config.merge!('enabled' => true)).to eq(base_config) }
24
+ it { expect(smell_config.merge!('exclude' => [])).to eq(base_config) }
25
+ it { expect(smell_config.merge!('accept' => ['_'])).to eq(base_config) }
22
26
  it do
23
- @smell_config = @smell_config.merge!('reject' => [/^.$/, /[0-9]$/, /[A-Z]/])
24
- expect(@smell_config).to eq(@base_config)
27
+ updated = smell_config.merge!('reject' => [/^.$/, /[0-9]$/, /[A-Z]/])
28
+ expect(updated).to eq(base_config)
25
29
  end
26
30
  it do
27
- @smell_config = @smell_config.merge!('enabled' => true, 'accept' => ['_'])
28
- expect(@smell_config).to eq(@base_config)
31
+ updated = smell_config.merge!('accept' => ['_'], 'enabled' => true)
32
+ expect(updated).to eq(base_config)
29
33
  end
30
34
 
31
35
  it 'should override single values' do
32
- @smell_config = @smell_config.merge!('enabled' => false)
33
- expect(@smell_config).to eq('enabled' => false, 'exclude' => [],
34
- 'reject' => [/^.$/, /[0-9]$/, /[A-Z]/],
35
- 'accept' => ['_'])
36
+ updated = smell_config.merge!('enabled' => false)
37
+ expect(updated).to eq('accept' => ['_'],
38
+ 'enabled' => false,
39
+ 'exclude' => [],
40
+ 'reject' => [/^.$/, /[0-9]$/, /[A-Z]/])
36
41
  end
37
42
 
38
43
  it 'should override arrays of values' do
39
- @smell_config = @smell_config.merge!('reject' => [/^.$/, /[3-9]$/])
40
- expect(@smell_config).to eq('enabled' => true,
41
- 'exclude' => [],
42
- 'reject' => [/^.$/, /[3-9]$/],
43
- 'accept' => ['_'])
44
+ updated = smell_config.merge!('reject' => [/^.$/, /[3-9]$/])
45
+ expect(updated).to eq('accept' => ['_'],
46
+ 'enabled' => true,
47
+ 'exclude' => [],
48
+ 'reject' => [/^.$/, /[3-9]$/])
44
49
  end
45
50
 
46
51
  it 'should override multiple values' do
47
- expect(@smell_config.merge!('enabled' => false, 'accept' => [/[A-Z]$/])).to eq(
48
- 'enabled' => false, 'exclude' => [],
49
- 'reject' => [/^.$/, /[0-9]$/, /[A-Z]/],
50
- 'accept' => [/[A-Z]$/]
51
- )
52
+ updated = smell_config.merge!('accept' => [/[A-Z]$/], 'enabled' => false)
53
+ expect(updated).to eq('accept' => [/[A-Z]$/],
54
+ 'enabled' => false,
55
+ 'exclude' => [],
56
+ 'reject' => [/^.$/, /[0-9]$/, /[A-Z]/])
52
57
  end
53
58
  end
54
59
  end