reek 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +9 -0
  3. data/README.md +54 -5
  4. data/Rakefile +1 -1
  5. data/features/command_line_interface/smell_selection.feature +4 -4
  6. data/features/command_line_interface/smells_count.feature +9 -8
  7. data/features/configuration_files/masking_smells.feature +16 -51
  8. data/features/configuration_files/overrides_defaults.feature +1 -1
  9. data/features/rake_task/rake_task.feature +14 -14
  10. data/features/reports/reports.feature +21 -19
  11. data/features/reports/yaml.feature +35 -63
  12. data/features/samples.feature +55 -54
  13. data/features/support/env.rb +8 -1
  14. data/lib/reek/cli/application.rb +22 -7
  15. data/lib/reek/cli/command.rb +4 -2
  16. data/lib/reek/cli/help_command.rb +1 -1
  17. data/lib/reek/cli/options.rb +3 -3
  18. data/lib/reek/cli/reek_command.rb +4 -8
  19. data/lib/reek/cli/report/formatter.rb +8 -5
  20. data/lib/reek/cli/report/report.rb +6 -5
  21. data/lib/reek/cli/report/strategy.rb +3 -2
  22. data/lib/reek/cli/version_command.rb +1 -1
  23. data/lib/reek/configuration/app_configuration.rb +75 -0
  24. data/lib/reek/configuration/configuration_file_finder.rb +56 -0
  25. data/lib/reek/core/code_context.rb +2 -6
  26. data/lib/reek/core/module_context.rb +4 -0
  27. data/lib/reek/core/smell_repository.rb +5 -3
  28. data/lib/reek/core/sniffer.rb +12 -8
  29. data/lib/reek/examiner.rb +7 -6
  30. data/lib/reek/rake/task.rb +10 -12
  31. data/lib/reek/smell_warning.rb +25 -43
  32. data/lib/reek/smells/attribute.rb +7 -12
  33. data/lib/reek/smells/boolean_parameter.rb +9 -9
  34. data/lib/reek/smells/class_variable.rb +7 -13
  35. data/lib/reek/smells/control_parameter.rb +8 -11
  36. data/lib/reek/smells/data_clump.rb +16 -21
  37. data/lib/reek/smells/duplicate_method_call.rb +11 -18
  38. data/lib/reek/smells/feature_envy.rb +8 -8
  39. data/lib/reek/smells/irresponsible_module.rb +6 -10
  40. data/lib/reek/smells/long_parameter_list.rb +7 -15
  41. data/lib/reek/smells/long_yield_list.rb +13 -15
  42. data/lib/reek/smells/module_initialize.rb +4 -7
  43. data/lib/reek/smells/nested_iterators.rb +6 -13
  44. data/lib/reek/smells/nil_check.rb +9 -7
  45. data/lib/reek/smells/prima_donna_method.rb +5 -7
  46. data/lib/reek/smells/repeated_conditional.rb +19 -15
  47. data/lib/reek/smells/smell_detector.rb +21 -1
  48. data/lib/reek/smells/too_many_instance_variables.rb +9 -16
  49. data/lib/reek/smells/too_many_methods.rb +10 -17
  50. data/lib/reek/smells/too_many_statements.rb +14 -14
  51. data/lib/reek/smells/uncommunicative_method_name.rb +9 -10
  52. data/lib/reek/smells/uncommunicative_module_name.rb +9 -10
  53. data/lib/reek/smells/uncommunicative_parameter_name.rb +9 -9
  54. data/lib/reek/smells/uncommunicative_variable_name.rb +9 -9
  55. data/lib/reek/smells/unused_parameters.rb +8 -20
  56. data/lib/reek/smells/utility_function.rb +12 -10
  57. data/lib/reek/source.rb +0 -1
  58. data/lib/reek/source/code_comment.rb +1 -0
  59. data/lib/reek/source/source_code.rb +3 -13
  60. data/lib/reek/source/source_file.rb +0 -14
  61. data/lib/reek/source/source_repository.rb +7 -0
  62. data/lib/reek/spec/should_reek_of.rb +3 -3
  63. data/lib/reek/spec/should_reek_only_of.rb +2 -2
  64. data/lib/reek/version.rb +1 -1
  65. data/reek.gemspec +4 -2
  66. data/spec/factories/factories.rb +32 -0
  67. data/spec/matchers/smell_of_matcher.rb +3 -2
  68. data/spec/reek/cli/report_spec.rb +2 -1
  69. data/spec/reek/configuration/app_configuration_spec.rb +67 -0
  70. data/spec/reek/configuration/configuration_file_finder_spec.rb +35 -0
  71. data/spec/reek/core/code_context_spec.rb +1 -1
  72. data/spec/reek/core/module_context_spec.rb +5 -1
  73. data/spec/reek/core/smell_configuration_spec.rb +21 -13
  74. data/spec/reek/core/warning_collector_spec.rb +4 -1
  75. data/spec/reek/examiner_spec.rb +19 -1
  76. data/spec/reek/smell_warning_spec.rb +42 -36
  77. data/spec/reek/smells/attribute_spec.rb +6 -2
  78. data/spec/reek/smells/boolean_parameter_spec.rb +11 -12
  79. data/spec/reek/smells/class_variable_spec.rb +16 -6
  80. data/spec/reek/smells/control_parameter_spec.rb +17 -19
  81. data/spec/reek/smells/data_clump_spec.rb +25 -15
  82. data/spec/reek/smells/duplicate_method_call_spec.rb +18 -12
  83. data/spec/reek/smells/feature_envy_spec.rb +29 -10
  84. data/spec/reek/smells/irresponsible_module_spec.rb +7 -7
  85. data/spec/reek/smells/long_parameter_list_spec.rb +16 -10
  86. data/spec/reek/smells/long_yield_list_spec.rb +2 -2
  87. data/spec/reek/smells/module_initialize_spec.rb +26 -0
  88. data/spec/reek/smells/nested_iterators_spec.rb +21 -10
  89. data/spec/reek/smells/nil_check_spec.rb +0 -2
  90. data/spec/reek/smells/prima_donna_method_spec.rb +3 -3
  91. data/spec/reek/smells/repeated_conditional_spec.rb +0 -26
  92. data/spec/reek/smells/smell_detector_shared.rb +4 -4
  93. data/spec/reek/smells/too_many_instance_variables_spec.rb +3 -3
  94. data/spec/reek/smells/too_many_methods_spec.rb +16 -11
  95. data/spec/reek/smells/too_many_statements_spec.rb +55 -18
  96. data/spec/reek/smells/uncommunicative_method_name_spec.rb +3 -2
  97. data/spec/reek/smells/uncommunicative_module_name_spec.rb +5 -5
  98. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +4 -4
  99. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +28 -21
  100. data/spec/reek/smells/unused_parameters_spec.rb +3 -5
  101. data/spec/reek/smells/utility_function_spec.rb +2 -1
  102. data/spec/reek/source/code_comment_spec.rb +7 -2
  103. data/spec/reek/source/reference_collector_spec.rb +0 -1
  104. data/spec/reek/source/sexp_extensions_spec.rb +0 -15
  105. data/spec/reek/source/source_code_spec.rb +13 -1
  106. data/spec/reek/spec/should_reek_only_of_spec.rb +22 -10
  107. data/spec/reek/spec/should_reek_spec.rb +6 -2
  108. data/spec/samples/minimal_smelly_and_masked/config.reek +7 -0
  109. data/spec/samples/minimal_smelly_and_masked/minimal_dirty.rb +4 -0
  110. data/spec/samples/simple_configuration.reek +5 -0
  111. data/spec/samples/standard_smelly/dirty.rb +8 -0
  112. data/spec/samples/standard_smelly/minimal_dirty.rb +4 -0
  113. data/spec/spec_helper.rb +20 -0
  114. data/tasks/develop.rake +1 -1
  115. data/tasks/rubocop.rake +5 -0
  116. metadata +41 -6
  117. data/lib/reek/config_file_exception.rb +0 -7
  118. data/lib/reek/smell_description.rb +0 -26
  119. data/lib/reek/source/config_file.rb +0 -88
  120. data/spec/reek/smell_description_spec.rb +0 -43
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'reek/cli/application'
3
+
4
+ include Reek::Cli
5
+ include Reek::Configuration
6
+
7
+ describe ConfigurationFileFinder do
8
+ describe '.find' do
9
+ let(:sample_config_path) { Pathname.new('spec/samples/simple_configuration.reek') }
10
+ let(:config_path_same_level) { Pathname.new('spec/samples/simple_configuration.reek') }
11
+ let(:options) { double(config_file: sample_config_path) }
12
+ let(:application_with_options) { double(options: options) }
13
+ let(:application_without_options) { nil }
14
+
15
+ it 'should return the config file we passed as cli option if given' do
16
+ expect(ConfigurationFileFinder.find(application_with_options)).to eq(sample_config_path)
17
+ end
18
+
19
+ it 'should return the first configuration file it can find in the current directory' do
20
+ allow(ConfigurationFileFinder).to receive(:detect_or_traverse_up).
21
+ and_return config_path_same_level
22
+
23
+ expect(ConfigurationFileFinder.find(application_without_options)).
24
+ to eq(config_path_same_level)
25
+ end
26
+
27
+ it 'should look in the HOME directory lastly' do
28
+ allow(ConfigurationFileFinder).to receive(:configuration_by_cli).and_return nil
29
+ allow(ConfigurationFileFinder).to receive(:configuration_in_file_system).and_return nil
30
+ expect(ConfigurationFileFinder).to receive(:configuration_in_home_directory).once
31
+
32
+ ConfigurationFileFinder.find application_without_options
33
+ end
34
+ end
35
+ end
@@ -164,7 +164,7 @@ EOS
164
164
  let(:sniffer) { double('sniffer') }
165
165
 
166
166
  before :each do
167
- allow(sniffer).to receive(:smell_class_name).and_return('DuplicateMethodCall')
167
+ allow(sniffer).to receive(:smell_type).and_return('DuplicateMethodCall')
168
168
  allow(exp).to receive(:comments).and_return(
169
169
  ':reek:DuplicateMethodCall: { allow_calls: [ puts ] }')
170
170
  end
@@ -6,7 +6,11 @@ include Reek::Core
6
6
 
7
7
  describe ModuleContext do
8
8
  it 'should report module name for smell in method' do
9
- expect('module Fred; def simple(x) x + 1; end; end').to reek_of(:UncommunicativeParameterName, /x/, /simple/)
9
+ expect('
10
+ module Fred
11
+ def simple(x) x + 1; end
12
+ end
13
+ ').to reek_of(:UncommunicativeParameterName, /x/, /simple/)
10
14
  end
11
15
 
12
16
  it 'should not report module with empty class' do
@@ -12,8 +12,8 @@ describe SmellConfiguration do
12
12
  context 'when overriding default configs' do
13
13
  before(:each) do
14
14
  @base_config = { 'enabled' => true, 'exclude' => [],
15
- 'reject' => [/^.$/, /[0-9]$/, /[A-Z]/],
16
- 'accept' => ['_'] }
15
+ 'reject' => [/^.$/, /[0-9]$/, /[A-Z]/],
16
+ 'accept' => ['_'] }
17
17
  @smell_config = SmellConfiguration.new(@base_config)
18
18
  end
19
19
 
@@ -21,27 +21,35 @@ describe SmellConfiguration do
21
21
  it { expect(@smell_config.merge!('enabled' => true)).to eq(@base_config) }
22
22
  it { expect(@smell_config.merge!('exclude' => [])).to eq(@base_config) }
23
23
  it { expect(@smell_config.merge!('accept' => ['_'])).to eq(@base_config) }
24
- it { expect(@smell_config.merge!('reject' => [/^.$/, /[0-9]$/, /[A-Z]/])).to eq(@base_config) }
25
- it { expect(@smell_config.merge!('enabled' => true, 'accept' => ['_'])).to eq(@base_config) }
24
+ it do
25
+ @smell_config = @smell_config.merge!('reject' => [/^.$/, /[0-9]$/, /[A-Z]/])
26
+ expect(@smell_config).to eq(@base_config)
27
+ end
28
+ it do
29
+ @smell_config = @smell_config.merge!('enabled' => true, 'accept' => ['_'])
30
+ expect(@smell_config).to eq(@base_config)
31
+ end
26
32
 
27
33
  it 'should override single values' do
28
- expect(@smell_config.merge!('enabled' => false)).to eq('enabled' => false, 'exclude' => [],
29
- 'reject' => [/^.$/, /[0-9]$/, /[A-Z]/],
30
- 'accept' => ['_'])
34
+ @smell_config = @smell_config.merge!('enabled' => false)
35
+ expect(@smell_config).to eq('enabled' => false, 'exclude' => [],
36
+ 'reject' => [/^.$/, /[0-9]$/, /[A-Z]/],
37
+ 'accept' => ['_'])
31
38
  end
32
39
 
33
40
  it 'should override arrays of values' do
34
- expect(@smell_config.merge!('reject' => [/^.$/, /[3-9]$/])).to eq('enabled' => true,
35
- 'exclude' => [],
36
- 'reject' => [/^.$/, /[3-9]$/],
37
- 'accept' => ['_'])
41
+ @smell_config = @smell_config.merge!('reject' => [/^.$/, /[3-9]$/])
42
+ expect(@smell_config).to eq('enabled' => true,
43
+ 'exclude' => [],
44
+ 'reject' => [/^.$/, /[3-9]$/],
45
+ 'accept' => ['_'])
38
46
  end
39
47
 
40
48
  it 'should override multiple values' do
41
49
  expect(@smell_config.merge!('enabled' => false, 'accept' => [/[A-Z]$/])).to eq(
42
50
  'enabled' => false, 'exclude' => [],
43
- 'reject' => [/^.$/, /[0-9]$/, /[A-Z]/],
44
- 'accept' => [/[A-Z]$/]
51
+ 'reject' => [/^.$/, /[0-9]$/, /[A-Z]/],
52
+ 'accept' => [/[A-Z]$/]
45
53
  )
46
54
  end
47
55
  end
@@ -17,7 +17,10 @@ describe WarningCollector do
17
17
 
18
18
  context 'with one warning' do
19
19
  before :each do
20
- @warning = Reek::SmellWarning.new('ControlCouple', 'fred', [1, 2, 3], 'hello')
20
+ @warning = Reek::SmellWarning.new(Reek::Smells::FeatureEnvy.new(''),
21
+ context: 'fred',
22
+ lines: [1, 2, 3],
23
+ message: 'hello')
21
24
  @collector.found_smell(@warning)
22
25
  end
23
26
  it 'reports that warning' do
@@ -37,7 +37,7 @@ shared_examples_for 'one smell found' do
37
37
  expect(@examiner.smells.length).to eq(1)
38
38
  end
39
39
  it 'reports the correct smell' do
40
- expect(@examiner.smells[0].smell_class).to eq(@expected_first_smell)
40
+ expect(@examiner.smells[0].smell_category).to eq(@expected_first_smell)
41
41
  end
42
42
 
43
43
  it_should_behave_like 'supports the deprecated api'
@@ -66,6 +66,12 @@ describe Examiner do
66
66
  end
67
67
 
68
68
  context 'with a partially masked smelly Dir' do
69
+ around(:each) do |example|
70
+ with_test_config('spec/samples/all_but_one_masked/masked.reek') do
71
+ example.run
72
+ end
73
+ end
74
+
69
75
  before :each do
70
76
  smelly_dir = Dir['spec/samples/all_but_one_masked/*.rb']
71
77
  @examiner = Examiner.new(smelly_dir)
@@ -84,6 +90,12 @@ describe Examiner do
84
90
  end
85
91
 
86
92
  context 'with a smelly Dir masked by a dotfile' do
93
+ around(:each) do |example|
94
+ with_test_config('spec/samples/masked_by_dotfile/.reek') do
95
+ example.run
96
+ end
97
+ end
98
+
87
99
  before :each do
88
100
  smelly_dir = Dir['spec/samples/masked_by_dotfile/*.rb']
89
101
  @examiner = Examiner.new(smelly_dir)
@@ -93,6 +105,12 @@ describe Examiner do
93
105
  end
94
106
 
95
107
  context 'with a partially masked smelly File' do
108
+ around(:each) do |example|
109
+ with_test_config('spec/samples/all_but_one_masked/masked.reek') do
110
+ example.run
111
+ end
112
+ end
113
+
96
114
  before :each do
97
115
  smelly_file = File.new(Dir['spec/samples/all_but_one_masked/d*.rb'][0])
98
116
  @examiner = Examiner.new(smelly_file)
@@ -4,6 +4,10 @@ require 'reek/smell_warning'
4
4
  include Reek
5
5
 
6
6
  describe SmellWarning do
7
+ let(:duplication_detector) { build(:smell_detector, smell_type: 'DuplicateMethodCall') }
8
+ let(:feature_envy_detector) { build(:smell_detector, smell_type: 'FeatureEnvy') }
9
+ let(:utility_function_detector) { build(:smell_detector, smell_type: 'UtilityFunction') }
10
+
7
11
  context 'sort order' do
8
12
  shared_examples_for 'first sorts ahead of second' do
9
13
  it 'hash differently' do
@@ -23,8 +27,8 @@ describe SmellWarning do
23
27
 
24
28
  context 'smells differing only by detector' do
25
29
  before :each do
26
- @first = SmellWarning.new('Duplication', 'self', 27, 'self', false)
27
- @second = SmellWarning.new('FeatureEnvy', 'self', 27, 'self', true)
30
+ @first = build(:smell_warning, smell_detector: duplication_detector)
31
+ @second = build(:smell_warning, smell_detector: feature_envy_detector)
28
32
  end
29
33
 
30
34
  it_should_behave_like 'first sorts ahead of second'
@@ -32,8 +36,10 @@ describe SmellWarning do
32
36
 
33
37
  context 'smells differing only by context' do
34
38
  before :each do
35
- @first = SmellWarning.new('FeatureEnvy', 'first', 27, 'self', true)
36
- @second = SmellWarning.new('FeatureEnvy', 'second', 27, 'self', false)
39
+ @first = build(:smell_warning, smell_detector: duplication_detector,
40
+ context: 'first')
41
+ @second = build(:smell_warning, smell_detector: duplication_detector,
42
+ context: 'second')
37
43
  end
38
44
 
39
45
  it_should_behave_like 'first sorts ahead of second'
@@ -41,8 +47,12 @@ describe SmellWarning do
41
47
 
42
48
  context 'smells differing only by message' do
43
49
  before :each do
44
- @first = SmellWarning.new('FeatureEnvy', 'context', 27, 'first', true)
45
- @second = SmellWarning.new('FeatureEnvy', 'context', 27, 'second', false)
50
+ @first = build(:smell_warning, smell_detector: duplication_detector,
51
+ context: 'ctx',
52
+ message: 'first message')
53
+ @second = build(:smell_warning, smell_detector: duplication_detector,
54
+ context: 'ctx',
55
+ message: 'second message')
46
56
  end
47
57
 
48
58
  it_should_behave_like 'first sorts ahead of second'
@@ -50,8 +60,10 @@ describe SmellWarning do
50
60
 
51
61
  context 'message takes precedence over smell name' do
52
62
  before :each do
53
- @first = SmellWarning.new('UtilityFunction', 'context', 27, 'first', true)
54
- @second = SmellWarning.new('FeatureEnvy', 'context', 27, 'second', false)
63
+ @first = build(:smell_warning, smell_detector: utility_function_detector,
64
+ message: 'first message')
65
+ @second = build(:smell_warning, smell_detector: feature_envy_detector,
66
+ message: 'second message')
55
67
  end
56
68
 
57
69
  it_should_behave_like 'first sorts ahead of second'
@@ -59,8 +71,18 @@ describe SmellWarning do
59
71
 
60
72
  context 'smells differing everywhere' do
61
73
  before :each do
62
- @first = SmellWarning.new('UncommunicativeName', 'Dirty', 27, "has the variable name '@s'", true)
63
- @second = SmellWarning.new('Duplication', 'Dirty#a', 27, 'calls @s.title twice', false)
74
+ uncommunicative_name_detector = build(:smell_detector,
75
+ smell_type: 'UncommunicativeVariableName',
76
+ source: true)
77
+ duplication_detector = build(:smell_detector,
78
+ smell_type: 'DuplicateMethodCall',
79
+ source: false)
80
+ @first = build(:smell_warning, smell_detector: uncommunicative_name_detector,
81
+ context: 'Dirty',
82
+ message: "has the variable name '@s'")
83
+ @second = build(:smell_warning, smell_detector: duplication_detector,
84
+ context: 'Dirty#a',
85
+ message: 'calls @s.title twice')
64
86
  end
65
87
 
66
88
  it_should_behave_like 'first sorts ahead of second'
@@ -77,8 +99,8 @@ describe SmellWarning do
77
99
  end
78
100
 
79
101
  shared_examples_for 'common fields' do
80
- it 'includes the smell class' do
81
- expect(@yaml).to match(/class:\s*FeatureEnvy/)
102
+ it 'includes the smell type' do
103
+ expect(@yaml).to match(/smell_type:\s*FeatureEnvy/)
82
104
  end
83
105
  it 'includes the context' do
84
106
  expect(@yaml).to match(/context:\s*#{@context_name}/)
@@ -96,17 +118,20 @@ describe SmellWarning do
96
118
  context 'with all details specified' do
97
119
  before :each do
98
120
  @source = 'a/ruby/source/file.rb'
99
- @subclass = 'TooManyParties'
121
+ @smell_type = 'FeatureEnvy'
100
122
  @parameters = { 'one' => 34, 'two' => 'second' }
101
- @warning = SmellWarning.new(@class, @context_name, @lines, @message,
102
- @source, @subclass, @parameters)
123
+ @detector = Reek::Smells::FeatureEnvy.new @source
124
+ @warning = SmellWarning.new(@detector, context: @context_name,
125
+ lines: @lines,
126
+ message: @message,
127
+ parameters: @parameters)
103
128
  @yaml = @warning.to_yaml
104
129
  end
105
130
 
106
131
  it_should_behave_like 'common fields'
107
132
 
108
- it 'includes the subclass' do
109
- expect(@yaml).to match(/subclass:\s*#{@subclass}/)
133
+ it 'includes the smell type' do
134
+ expect(@yaml).to match(/smell_type:\s*#{@smell_type}/)
110
135
  end
111
136
  it 'includes the source' do
112
137
  expect(@yaml).to match(/source:\s*#{@source}/)
@@ -117,24 +142,5 @@ describe SmellWarning do
117
142
  end
118
143
  end
119
144
  end
120
-
121
- context 'with all defaults used' do
122
- before :each do
123
- warning = SmellWarning.new(@class, @context_name, @lines, @message)
124
- @yaml = warning.to_yaml
125
- end
126
-
127
- it_should_behave_like 'common fields'
128
-
129
- it 'includes no subclass' do
130
- expect(@yaml).to match(/subclass: ["']{2}/)
131
- end
132
- it 'includes no source' do
133
- expect(@yaml).to match(/source: ["']{2}/)
134
- end
135
- it 'includes empty parameters' do
136
- expect(@yaml).not_to match(/parameter/)
137
- end
138
- end
139
145
  end
140
146
  end
@@ -36,15 +36,19 @@ describe Attribute do
36
36
  it 'records only that attribute' do
37
37
  expect(@smells.length).to eq(1)
38
38
  end
39
+
39
40
  it 'reports the attribute name' do
40
- expect(@smells[0].smell[Attribute::ATTRIBUTE_KEY]).to eq(@attr_name)
41
+ expect(@smells[0].parameters[:name]).to eq(@attr_name)
41
42
  end
43
+
42
44
  it 'reports the declaration line number' do
43
45
  expect(@smells[0].lines).to eq([1])
44
46
  end
47
+
45
48
  it 'reports the correct smell class' do
46
- expect(@smells[0].smell_class).to eq(Attribute::SMELL_CLASS)
49
+ expect(@smells[0].smell_category).to eq(Attribute.smell_category)
47
50
  end
51
+
48
52
  it 'reports the context fq name' do
49
53
  expect(@smells[0].context).to eq('Fred')
50
54
  end
@@ -9,34 +9,34 @@ describe BooleanParameter do
9
9
  context 'in a method' do
10
10
  it 'reports a parameter defaulted to true' do
11
11
  src = 'def cc(arga = true) end'
12
- expect(src).to smell_of(BooleanParameter, BooleanParameter::PARAMETER_KEY => 'arga')
12
+ expect(src).to smell_of(BooleanParameter, name: 'arga')
13
13
  end
14
14
  it 'reports a parameter defaulted to false' do
15
15
  src = 'def cc(arga = false) end'
16
- expect(src).to smell_of(BooleanParameter, BooleanParameter::PARAMETER_KEY => 'arga')
16
+ expect(src).to smell_of(BooleanParameter, name: 'arga')
17
17
  end
18
18
  it 'reports two parameters defaulted to booleans' do
19
19
  src = 'def cc(nowt, arga = true, argb = false, &blk) end'
20
20
  expect(src).to smell_of(BooleanParameter,
21
- { BooleanParameter::PARAMETER_KEY => 'arga' },
22
- BooleanParameter::PARAMETER_KEY => 'argb')
21
+ { name: 'arga' },
22
+ { name: 'argb' })
23
23
  end
24
24
  end
25
25
 
26
26
  context 'in a singleton method' do
27
27
  it 'reports a parameter defaulted to true' do
28
28
  src = 'def self.cc(arga = true) end'
29
- expect(src).to smell_of(BooleanParameter, BooleanParameter::PARAMETER_KEY => 'arga')
29
+ expect(src).to smell_of(BooleanParameter, name: 'arga')
30
30
  end
31
31
  it 'reports a parameter defaulted to false' do
32
32
  src = 'def fred.cc(arga = false) end'
33
- expect(src).to smell_of(BooleanParameter, BooleanParameter::PARAMETER_KEY => 'arga')
33
+ expect(src).to smell_of(BooleanParameter, name: 'arga')
34
34
  end
35
35
  it 'reports two parameters defaulted to booleans' do
36
36
  src = 'def Module.cc(nowt, arga = true, argb = false, &blk) end'
37
37
  expect(src).to smell_of(BooleanParameter,
38
- { BooleanParameter::PARAMETER_KEY => 'arga' },
39
- BooleanParameter::PARAMETER_KEY => 'argb')
38
+ { name: 'arga' },
39
+ { name: 'argb' })
40
40
  end
41
41
  end
42
42
  end
@@ -55,11 +55,10 @@ describe BooleanParameter do
55
55
  @detector.examine(ctx)
56
56
  smells = @detector.smells_found.to_a
57
57
  expect(smells.length).to eq(1)
58
- expect(smells[0].smell_class).to eq(BooleanParameter::SMELL_CLASS)
59
- expect(smells[0].smell[BooleanParameter::PARAMETER_KEY]).to eq('arga')
58
+ expect(smells[0].smell_category).to eq(BooleanParameter.smell_category)
59
+ expect(smells[0].parameters[:name]).to eq('arga')
60
60
  expect(smells[0].source).to eq(@source_name)
61
- expect(smells[0].smell_class).to eq(BooleanParameter::SMELL_CLASS)
62
- expect(smells[0].subclass).to eq(BooleanParameter::SMELL_SUBCLASS)
61
+ expect(smells[0].smell_type).to eq(BooleanParameter.smell_type)
63
62
  expect(smells[0].lines).to eq([1])
64
63
  end
65
64
  end
@@ -36,7 +36,7 @@ describe ClassVariable do
36
36
  expect(@smells.length).to eq(1)
37
37
  end
38
38
  it 'records the variable name' do
39
- expect(@smells[0].smell[ClassVariable::VARIABLE_KEY]).to eq(@class_variable)
39
+ expect(@smells[0].parameters[:name]).to eq(@class_variable)
40
40
  end
41
41
  end
42
42
 
@@ -67,7 +67,12 @@ describe ClassVariable do
67
67
 
68
68
  context "declared and used in a #{scope}" do
69
69
  before :each do
70
- @src = "#{scope} Fred; #{@class_variable} = {}; def jim() #{@class_variable} = {}; end; end"
70
+ @src = "
71
+ #{scope} Fred
72
+ #{@class_variable} = {}
73
+ def jim() #{@class_variable} = {}; end
74
+ end
75
+ "
71
76
  end
72
77
 
73
78
  it_should_behave_like 'one variable found'
@@ -75,7 +80,12 @@ describe ClassVariable do
75
80
 
76
81
  context "used twice in a #{scope}" do
77
82
  before :each do
78
- @src = "#{scope} Fred; def jeff() #{@class_variable} = {}; end; def jim() #{@class_variable} = {}; end; end"
83
+ @src = "
84
+ #{scope} Fred
85
+ def jeff() #{@class_variable} = {}; end
86
+ def jim() #{@class_variable} = {}; end
87
+ end
88
+ "
79
89
  end
80
90
 
81
91
  it_should_behave_like 'one variable found'
@@ -92,9 +102,9 @@ EOS
92
102
  ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
93
103
  @warning = @detector.examine_context(ctx)[0]
94
104
  expect(@warning.source).to eq(@source_name)
95
- expect(@warning.smell_class).to eq(ClassVariable::SMELL_CLASS)
96
- expect(@warning.subclass).to eq(ClassVariable::SMELL_SUBCLASS)
97
- expect(@warning.smell[ClassVariable::VARIABLE_KEY]).to eq(@class_variable)
105
+ expect(@warning.smell_category).to eq(ClassVariable.smell_category)
106
+ expect(@warning.smell_type).to eq(ClassVariable.smell_type)
107
+ expect(@warning.parameters[:name]).to eq(@class_variable)
98
108
  expect(@warning.lines).to eq([2])
99
109
  end
100
110
  end