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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Rakefile +0 -1
- data/config/defaults.reek +1 -1
- data/features/samples.feature +17 -16
- data/lib/reek.rb +0 -1
- data/lib/reek/ast/ast_node_class_map.rb +5 -1
- data/lib/reek/ast/node.rb +10 -3
- data/lib/reek/ast/object_refs.rb +11 -5
- data/lib/reek/ast/reference_collector.rb +6 -2
- data/lib/reek/ast/sexp_extensions.rb +42 -1
- data/lib/reek/ast/sexp_formatter.rb +2 -1
- data/lib/reek/cli/application.rb +12 -9
- data/lib/reek/cli/command.rb +6 -0
- data/lib/reek/cli/input.rb +4 -4
- data/lib/reek/cli/option_interpreter.rb +11 -7
- data/lib/reek/cli/options.rb +42 -40
- data/lib/reek/cli/reek_command.rb +3 -3
- data/lib/reek/cli/silencer.rb +12 -3
- data/lib/reek/cli/warning_collector.rb +8 -3
- data/lib/reek/code_comment.rb +6 -1
- data/lib/reek/configuration/app_configuration.rb +65 -100
- data/lib/reek/configuration/configuration_file_finder.rb +4 -13
- data/lib/reek/configuration/configuration_validator.rb +35 -0
- data/lib/reek/configuration/default_directive.rb +12 -0
- data/lib/reek/configuration/directory_directives.rb +54 -0
- data/lib/reek/configuration/excluded_paths.rb +18 -0
- data/lib/reek/context/code_context.rb +19 -17
- data/lib/reek/examiner.rb +9 -7
- data/lib/reek/rake/task.rb +12 -22
- data/lib/reek/report/formatter.rb +6 -1
- data/lib/reek/report/report.rb +22 -13
- data/lib/reek/smells/attribute.rb +6 -53
- data/lib/reek/smells/control_parameter.rb +21 -13
- data/lib/reek/smells/data_clump.rb +17 -9
- data/lib/reek/smells/duplicate_method_call.rb +12 -6
- data/lib/reek/smells/long_parameter_list.rb +2 -2
- data/lib/reek/smells/long_yield_list.rb +4 -4
- data/lib/reek/smells/nested_iterators.rb +4 -2
- data/lib/reek/smells/nil_check.rb +6 -2
- data/lib/reek/smells/repeated_conditional.rb +3 -3
- data/lib/reek/smells/smell_configuration.rb +17 -7
- data/lib/reek/smells/smell_detector.rb +24 -11
- data/lib/reek/smells/smell_repository.rb +1 -1
- data/lib/reek/smells/smell_warning.rb +6 -6
- data/lib/reek/smells/too_many_instance_variables.rb +2 -2
- data/lib/reek/smells/too_many_methods.rb +4 -4
- data/lib/reek/smells/too_many_statements.rb +4 -4
- data/lib/reek/smells/uncommunicative_method_name.rb +5 -5
- data/lib/reek/smells/uncommunicative_module_name.rb +6 -6
- data/lib/reek/smells/uncommunicative_parameter_name.rb +8 -4
- data/lib/reek/smells/uncommunicative_variable_name.rb +9 -5
- data/lib/reek/smells/utility_function.rb +1 -1
- data/lib/reek/source/source_code.rb +5 -1
- data/lib/reek/source/source_locator.rb +3 -2
- data/lib/reek/spec.rb +3 -3
- data/lib/reek/spec/should_reek.rb +10 -5
- data/lib/reek/spec/should_reek_of.rb +9 -6
- data/lib/reek/spec/should_reek_only_of.rb +13 -8
- data/lib/reek/tree_dresser.rb +6 -2
- data/lib/reek/tree_walker.rb +40 -32
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +1 -1
- data/spec/reek/ast/node_spec.rb +1 -2
- data/spec/reek/ast/object_refs_spec.rb +40 -42
- data/spec/reek/ast/sexp_extensions_spec.rb +98 -104
- data/spec/reek/cli/warning_collector_spec.rb +8 -12
- data/spec/reek/code_comment_spec.rb +3 -5
- data/spec/reek/configuration/app_configuration_spec.rb +43 -57
- data/spec/reek/configuration/configuration_file_finder_spec.rb +5 -7
- data/spec/reek/configuration/default_directive_spec.rb +13 -0
- data/spec/reek/configuration/directory_directives_spec.rb +89 -0
- data/spec/reek/configuration/excluded_paths_spec.rb +30 -0
- data/spec/reek/context/code_context_spec.rb +63 -62
- data/spec/reek/context/method_context_spec.rb +8 -12
- data/spec/reek/context/module_context_spec.rb +1 -1
- data/spec/reek/context/root_context_spec.rb +3 -7
- data/spec/reek/examiner_spec.rb +14 -25
- data/spec/reek/smells/attribute_spec.rb +2 -4
- data/spec/reek/smells/boolean_parameter_spec.rb +5 -7
- data/spec/reek/smells/class_variable_spec.rb +29 -44
- data/spec/reek/smells/control_parameter_spec.rb +7 -9
- data/spec/reek/smells/data_clump_spec.rb +25 -32
- data/spec/reek/smells/duplicate_method_call_spec.rb +8 -7
- data/spec/reek/smells/feature_envy_spec.rb +16 -17
- data/spec/reek/smells/irresponsible_module_spec.rb +2 -4
- data/spec/reek/smells/long_parameter_list_spec.rb +6 -9
- data/spec/reek/smells/long_yield_list_spec.rb +6 -9
- data/spec/reek/smells/nested_iterators_spec.rb +14 -16
- data/spec/reek/smells/repeated_conditional_spec.rb +25 -25
- data/spec/reek/smells/smell_configuration_spec.rb +32 -27
- data/spec/reek/smells/smell_detector_shared.rb +12 -13
- data/spec/reek/smells/smell_warning_spec.rb +54 -58
- data/spec/reek/smells/too_many_instance_variables_spec.rb +9 -9
- data/spec/reek/smells/too_many_methods_spec.rb +13 -14
- data/spec/reek/smells/too_many_statements_spec.rb +8 -10
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +8 -9
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +12 -13
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +7 -10
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +16 -20
- data/spec/reek/smells/utility_function_spec.rb +11 -15
- data/spec/reek/source/source_code_spec.rb +6 -11
- data/spec/reek/spec/should_reek_of_spec.rb +19 -30
- data/spec/reek/spec/should_reek_only_of_spec.rb +28 -34
- data/spec/reek/tree_walker_spec.rb +14 -2
- data/spec/spec_helper.rb +2 -3
- data/tasks/test.rake +0 -5
- metadata +10 -6
- data/docs/Configuration-Files.md +0 -49
- data/spec/gem/updates_spec.rb +0 -25
- data/spec/gem/yard_spec.rb +0 -11
- data/spec/reek/smells/behaves_like_variable_detector.rb +0 -39
@@ -4,12 +4,10 @@ require_relative 'smell_detector_shared'
|
|
4
4
|
require_relative '../../../lib/reek/context/method_context'
|
5
5
|
|
6
6
|
RSpec.describe Reek::Smells::UncommunicativeParameterName do
|
7
|
-
|
8
|
-
|
9
|
-
@detector = build(:smell_detector,
|
10
|
-
smell_type: :UncommunicativeParameterName,
|
11
|
-
source: @source_name)
|
7
|
+
let(:detector) do
|
8
|
+
build(:smell_detector, smell_type: :UncommunicativeParameterName, source: source_name)
|
12
9
|
end
|
10
|
+
let(:source_name) { 'dummy_source' }
|
13
11
|
|
14
12
|
it_should_behave_like 'SmellDetector'
|
15
13
|
|
@@ -79,18 +77,17 @@ RSpec.describe Reek::Smells::UncommunicativeParameterName do
|
|
79
77
|
end
|
80
78
|
|
81
79
|
context 'looking at the smell result fields' do
|
82
|
-
|
80
|
+
let(:warning) do
|
83
81
|
src = 'def bad(good, bad2, good_again); basics(good, bad2, good_again); end'
|
84
82
|
ctx = Reek::Context::MethodContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
|
85
|
-
|
86
|
-
@warning = @smells[0]
|
83
|
+
detector.examine_context(ctx).first
|
87
84
|
end
|
88
85
|
|
89
86
|
it_should_behave_like 'common fields set correctly'
|
90
87
|
|
91
88
|
it 'reports the correct values' do
|
92
|
-
expect(
|
93
|
-
expect(
|
89
|
+
expect(warning.parameters[:name]).to eq('bad2')
|
90
|
+
expect(warning.lines).to eq([1])
|
94
91
|
end
|
95
92
|
end
|
96
93
|
end
|
@@ -3,11 +3,9 @@ require_relative '../../../lib/reek/smells/uncommunicative_variable_name'
|
|
3
3
|
require_relative 'smell_detector_shared'
|
4
4
|
|
5
5
|
RSpec.describe Reek::Smells::UncommunicativeVariableName do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
smell_type: :UncommunicativeVariableName,
|
10
|
-
source: @source_name)
|
6
|
+
let(:source_name) { 'dummy_source' }
|
7
|
+
let(:detector) do
|
8
|
+
build(:smell_detector, smell_type: :UncommunicativeVariableName, source: source_name)
|
11
9
|
end
|
12
10
|
|
13
11
|
it_should_behave_like 'SmellDetector'
|
@@ -19,7 +17,7 @@ RSpec.describe Reek::Smells::UncommunicativeVariableName do
|
|
19
17
|
end
|
20
18
|
it 'reports one-letter fieldname in assignment' do
|
21
19
|
src = 'class Thing; def simple(fred) @x = fred end end'
|
22
|
-
expect(src).to reek_of(:UncommunicativeVariableName,
|
20
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: '@x')
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
@@ -44,17 +42,17 @@ RSpec.describe Reek::Smells::UncommunicativeVariableName do
|
|
44
42
|
end
|
45
43
|
|
46
44
|
it 'reports long name ending in a number' do
|
47
|
-
|
48
|
-
src = "def simple(fred) #{
|
45
|
+
bad_var = 'var123'
|
46
|
+
src = "def simple(fred) #{bad_var} = jim(45) end"
|
49
47
|
expect(src).to reek_of(:UncommunicativeVariableName,
|
50
|
-
name:
|
48
|
+
name: bad_var)
|
51
49
|
end
|
52
50
|
|
53
51
|
it 'reports variable name only once' do
|
54
52
|
src = 'def simple(fred) x = jim(45); x = y end'
|
55
53
|
syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
|
56
54
|
ctx = Reek::Context::CodeContext.new(nil, syntax_tree)
|
57
|
-
smells =
|
55
|
+
smells = detector.examine_context(ctx)
|
58
56
|
expect(smells.length).to eq(1)
|
59
57
|
expect(smells[0].smell_type).to eq(described_class.smell_type)
|
60
58
|
expect(smells[0].parameters[:name]).to eq('x')
|
@@ -67,7 +65,7 @@ RSpec.describe Reek::Smells::UncommunicativeVariableName do
|
|
67
65
|
end
|
68
66
|
|
69
67
|
it 'reports variable name outside any method' do
|
70
|
-
expect('class Simple; x = jim(45); end').to reek_of(:UncommunicativeVariableName,
|
68
|
+
expect('class Simple; x = jim(45); end').to reek_of(:UncommunicativeVariableName, name: 'x')
|
71
69
|
end
|
72
70
|
end
|
73
71
|
|
@@ -154,7 +152,7 @@ RSpec.describe Reek::Smells::UncommunicativeVariableName do
|
|
154
152
|
end
|
155
153
|
|
156
154
|
context 'when a smell is reported' do
|
157
|
-
|
155
|
+
let(:warning) do
|
158
156
|
src = <<-EOS
|
159
157
|
def bad
|
160
158
|
unless @mod then
|
@@ -166,31 +164,29 @@ RSpec.describe Reek::Smells::UncommunicativeVariableName do
|
|
166
164
|
EOS
|
167
165
|
syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
|
168
166
|
ctx = Reek::Context::CodeContext.new(nil, syntax_tree)
|
169
|
-
|
170
|
-
@warning = @smells[0]
|
167
|
+
detector.examine_context(ctx).first
|
171
168
|
end
|
172
169
|
|
173
170
|
it_should_behave_like 'common fields set correctly'
|
174
171
|
|
175
172
|
it 'reports the correct values' do
|
176
|
-
expect(
|
177
|
-
expect(
|
173
|
+
expect(warning.parameters[:name]).to eq('x2')
|
174
|
+
expect(warning.lines).to eq([3, 5])
|
178
175
|
end
|
179
176
|
end
|
180
177
|
|
181
178
|
context 'when a smell is reported in a singleton method' do
|
182
|
-
|
179
|
+
let(:warning) do
|
183
180
|
src = 'def self.bad() x2 = 4; end'
|
184
181
|
syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
|
185
182
|
ctx = Reek::Context::CodeContext.new(nil, syntax_tree)
|
186
|
-
|
187
|
-
@warning = @smells[0]
|
183
|
+
detector.examine_context(ctx).first
|
188
184
|
end
|
189
185
|
|
190
186
|
it_should_behave_like 'common fields set correctly'
|
191
187
|
|
192
188
|
it 'reports the fq context' do
|
193
|
-
expect(
|
189
|
+
expect(warning.context).to eq('self.bad')
|
194
190
|
end
|
195
191
|
end
|
196
192
|
end
|
@@ -5,29 +5,25 @@ require_relative 'smell_detector_shared'
|
|
5
5
|
|
6
6
|
RSpec.describe Reek::Smells::UtilityFunction do
|
7
7
|
describe 'a detector' do
|
8
|
-
|
9
|
-
|
10
|
-
@detector = build(:smell_detector,
|
11
|
-
smell_type: :UtilityFunction,
|
12
|
-
source: @source_name)
|
13
|
-
end
|
8
|
+
let(:detector) { build(:smell_detector, smell_type: :UtilityFunction, source: source_name) }
|
9
|
+
let(:source_name) { 'string' }
|
14
10
|
|
15
11
|
it_should_behave_like 'SmellDetector'
|
16
12
|
|
17
13
|
context 'when a smells is reported' do
|
18
|
-
|
14
|
+
let(:warning) do
|
19
15
|
src = <<-EOS
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
def simple(arga)
|
17
|
+
arga.b.c
|
18
|
+
end
|
23
19
|
EOS
|
24
|
-
|
20
|
+
Reek::Examiner.new(src, ['UtilityFunction']).smells[0]
|
25
21
|
end
|
26
22
|
|
27
23
|
it_should_behave_like 'common fields set correctly'
|
28
24
|
|
29
25
|
it 'reports the line number of the method' do
|
30
|
-
expect(
|
26
|
+
expect(warning.lines).to eq([1])
|
31
27
|
end
|
32
28
|
end
|
33
29
|
end
|
@@ -158,7 +154,7 @@ RSpec.describe Reek::Smells::UtilityFunction do
|
|
158
154
|
|
159
155
|
context 'with only one call' do
|
160
156
|
it 'reports a call to a parameter' do
|
161
|
-
expect('def simple(arga) arga.to_s end').to reek_of(:UtilityFunction,
|
157
|
+
expect('def simple(arga) arga.to_s end').to reek_of(:UtilityFunction, name: 'simple')
|
162
158
|
end
|
163
159
|
|
164
160
|
it 'reports a call to a constant' do
|
@@ -169,7 +165,7 @@ RSpec.describe Reek::Smells::UtilityFunction do
|
|
169
165
|
context 'with two or more calls' do
|
170
166
|
it 'reports two calls' do
|
171
167
|
src = 'def simple(arga) arga.to_s + arga.to_i end'
|
172
|
-
expect(src).to reek_of(:UtilityFunction,
|
168
|
+
expect(src).to reek_of(:UtilityFunction, name: 'simple')
|
173
169
|
expect(src).not_to reek_of(:FeatureEnvy)
|
174
170
|
end
|
175
171
|
|
@@ -194,7 +190,7 @@ RSpec.describe Reek::Smells::UtilityFunction do
|
|
194
190
|
|
195
191
|
it 'should report message chain' do
|
196
192
|
src = 'def simple(arga) arga.b.c end'
|
197
|
-
expect(src).to reek_of(:UtilityFunction,
|
193
|
+
expect(src).to reek_of(:UtilityFunction, name: 'simple')
|
198
194
|
expect(src).not_to reek_of(:FeatureEnvy)
|
199
195
|
end
|
200
196
|
|
@@ -26,16 +26,13 @@ RSpec.describe Reek::Source::SourceCode do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
context 'when the parser fails' do
|
29
|
+
let(:catcher) { StringIO.new }
|
29
30
|
let(:source_name) { 'Test source' }
|
30
31
|
let(:error_message) { 'Error message' }
|
31
32
|
let(:parser) { double('parser') }
|
32
33
|
let(:src) { Reek::Source::SourceCode.new('', source_name, parser) }
|
33
34
|
|
34
|
-
before
|
35
|
-
@catcher = StringIO.new
|
36
|
-
@old_std_err = $stderr
|
37
|
-
$stderr = @catcher
|
38
|
-
end
|
35
|
+
before { $stderr = catcher }
|
39
36
|
|
40
37
|
shared_examples_for 'handling and recording the error' do
|
41
38
|
it 'does not raise an error' do
|
@@ -48,17 +45,17 @@ RSpec.describe Reek::Source::SourceCode do
|
|
48
45
|
|
49
46
|
it 'records the syntax error' do
|
50
47
|
src.syntax_tree
|
51
|
-
expect(
|
48
|
+
expect(catcher.string).to match(error_class.name)
|
52
49
|
end
|
53
50
|
|
54
51
|
it 'records the source name' do
|
55
52
|
src.syntax_tree
|
56
|
-
expect(
|
53
|
+
expect(catcher.string).to match(source_name)
|
57
54
|
end
|
58
55
|
|
59
56
|
it 'records the error message' do
|
60
57
|
src.syntax_tree
|
61
|
-
expect(
|
58
|
+
expect(catcher.string).to match(error_message)
|
62
59
|
end
|
63
60
|
end
|
64
61
|
|
@@ -98,8 +95,6 @@ RSpec.describe Reek::Source::SourceCode do
|
|
98
95
|
end
|
99
96
|
end
|
100
97
|
|
101
|
-
after
|
102
|
-
$stderr = @old_std_err
|
103
|
-
end
|
98
|
+
after { $stderr = STDERR }
|
104
99
|
end
|
105
100
|
end
|
@@ -4,71 +4,60 @@ require_relative '../../../lib/reek/spec'
|
|
4
4
|
|
5
5
|
RSpec.describe Reek::Spec::ShouldReekOf do
|
6
6
|
context 'rdoc demo example' do
|
7
|
-
|
8
|
-
@ruby = 'def double_thing() @other.thing.foo + @other.thing.foo end'
|
9
|
-
end
|
7
|
+
let(:ruby) { 'def double_thing() @other.thing.foo + @other.thing.foo end' }
|
10
8
|
|
11
9
|
it 'reports duplicate calls to @other.thing' do
|
12
|
-
expect(
|
10
|
+
expect(ruby).to reek_of(:Duplication, name: '@other.thing')
|
13
11
|
end
|
14
12
|
|
15
13
|
it 'reports duplicate calls to @other.thing.foo' do
|
16
|
-
expect(
|
14
|
+
expect(ruby).to reek_of(:Duplication, name: '@other.thing.foo')
|
17
15
|
end
|
18
16
|
|
19
17
|
it 'does not report any feature envy' do
|
20
|
-
expect(
|
18
|
+
expect(ruby).not_to reek_of(:FeatureEnvy)
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
22
|
context 'checking code in a string' do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@matcher = Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName,
|
29
|
-
name: 'y')
|
30
|
-
end
|
23
|
+
let(:clean_code) { 'def good() true; end' }
|
24
|
+
let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: 'y') }
|
25
|
+
let(:smelly_code) { 'def x() y = 4; end' }
|
31
26
|
|
32
27
|
it 'matches a smelly String' do
|
33
|
-
expect(
|
28
|
+
expect(matcher.matches?(smelly_code)).to be_truthy
|
34
29
|
end
|
35
30
|
|
36
31
|
it 'doesnt match a fragrant String' do
|
37
|
-
expect(
|
32
|
+
expect(matcher.matches?(clean_code)).to be_falsey
|
38
33
|
end
|
39
34
|
|
40
35
|
it 'reports the smells when should_not fails' do
|
41
|
-
expect(
|
42
|
-
expect(
|
36
|
+
expect(matcher.matches?(smelly_code)).to be_truthy
|
37
|
+
expect(matcher.failure_message_when_negated).to match('UncommunicativeVariableName')
|
43
38
|
end
|
44
39
|
end
|
45
40
|
|
46
41
|
context 'passing in smell_details with unknown parameter name' do
|
47
|
-
|
48
|
-
|
49
|
-
@matcher = Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName,
|
50
|
-
foo: 'y')
|
51
|
-
end
|
42
|
+
let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, foo: 'y') }
|
43
|
+
let(:smelly_code) { 'def x() y = 4; end' }
|
52
44
|
|
53
45
|
it 'raises ArgumentError' do
|
54
|
-
expect {
|
46
|
+
expect { matcher.matches?(smelly_code) }.to raise_error(ArgumentError)
|
55
47
|
end
|
56
48
|
end
|
57
49
|
|
58
50
|
context 'checking code in a File' do
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
@matcher = Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName,
|
63
|
-
name: '@s')
|
64
|
-
end
|
51
|
+
let(:clean_file) { Pathname.glob("#{SAMPLES_PATH}/three_clean_files/*.rb").first }
|
52
|
+
let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: '@s') }
|
53
|
+
let(:smelly_file) { Pathname.glob("#{SAMPLES_PATH}/two_smelly_files/*.rb").first }
|
65
54
|
|
66
55
|
it 'matches a smelly String' do
|
67
|
-
expect(
|
56
|
+
expect(matcher.matches?(smelly_file)).to be_truthy
|
68
57
|
end
|
69
58
|
|
70
59
|
it 'doesnt match a fragrant String' do
|
71
|
-
expect(
|
60
|
+
expect(matcher.matches?(clean_file)).to be_falsey
|
72
61
|
end
|
73
62
|
end
|
74
63
|
end
|
@@ -2,50 +2,46 @@ require_relative '../../spec_helper'
|
|
2
2
|
require_relative '../../../lib/reek/spec'
|
3
3
|
|
4
4
|
RSpec.describe Reek::Spec::ShouldReekOnlyOf do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
let(:examiner) { double('examiner').as_null_object }
|
6
|
+
let(:expected_context_name) { 'SmellyClass#big_method' }
|
7
|
+
let(:expected_smell_type) { :NestedIterators }
|
8
|
+
let(:matcher) { Reek::Spec::ShouldReekOnlyOf.new(expected_smell_type) }
|
9
|
+
let(:matcher_matches) { matcher.matches_examiner?(examiner) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
expect(examiner).to receive(:smells) { smells }
|
13
|
+
matcher_matches
|
12
14
|
end
|
13
15
|
|
14
16
|
shared_examples_for 'no match' do
|
15
17
|
it 'does not match' do
|
16
|
-
expect(
|
18
|
+
expect(matcher_matches).to be_falsey
|
17
19
|
end
|
18
20
|
|
19
21
|
context 'when a match was expected' do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
22
|
+
let(:source) { 'the_path/to_a/source_file.rb' }
|
23
|
+
|
24
|
+
before { expect(examiner).to receive(:description).and_return(source) }
|
24
25
|
|
25
26
|
it 'reports the source' do
|
26
|
-
expect(
|
27
|
+
expect(matcher.failure_message).to match(source)
|
27
28
|
end
|
28
29
|
|
29
30
|
it 'reports the expected smell class' do
|
30
|
-
expect(
|
31
|
+
expect(matcher.failure_message).to match(expected_smell_type.to_s)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
36
|
context 'with no smells' do
|
36
|
-
|
37
|
-
[]
|
38
|
-
end
|
37
|
+
let(:smells) { [] }
|
39
38
|
|
40
39
|
it_should_behave_like 'no match'
|
41
40
|
end
|
42
41
|
|
43
42
|
context 'with 1 non-matching smell' do
|
44
43
|
let(:control_couple_detector) { build(:smell_detector, smell_type: 'ControlParameter') }
|
45
|
-
|
46
|
-
def smells
|
47
|
-
[build(:smell_warning, smell_detector: control_couple_detector)]
|
48
|
-
end
|
44
|
+
let(:smells) { [build(:smell_warning, smell_detector: control_couple_detector)] }
|
49
45
|
|
50
46
|
it_should_behave_like 'no match'
|
51
47
|
end
|
@@ -53,8 +49,7 @@ RSpec.describe Reek::Spec::ShouldReekOnlyOf do
|
|
53
49
|
context 'with 2 non-matching smells' do
|
54
50
|
let(:control_couple_detector) { build(:smell_detector, smell_type: 'ControlParameter') }
|
55
51
|
let(:feature_envy_detector) { build(:smell_detector, smell_type: 'FeatureEnvy') }
|
56
|
-
|
57
|
-
def smells
|
52
|
+
let(:smells) do
|
58
53
|
[
|
59
54
|
build(:smell_warning, smell_detector: control_couple_detector),
|
60
55
|
build(:smell_warning, smell_detector: feature_envy_detector)
|
@@ -66,13 +61,12 @@ RSpec.describe Reek::Spec::ShouldReekOnlyOf do
|
|
66
61
|
|
67
62
|
context 'with 1 non-matching and 1 matching smell' do
|
68
63
|
let(:control_couple_detector) { build(:smell_detector, smell_type: 'ControlParameter') }
|
69
|
-
|
70
|
-
|
71
|
-
detector = build(:smell_detector, smell_type: @expected_smell_type.to_s)
|
64
|
+
let(:smells) do
|
65
|
+
detector = build(:smell_detector, smell_type: expected_smell_type.to_s)
|
72
66
|
[
|
73
67
|
build(:smell_warning, smell_detector: control_couple_detector),
|
74
68
|
build(:smell_warning, smell_detector: detector,
|
75
|
-
message: "message mentioning #{
|
69
|
+
message: "message mentioning #{expected_context_name}")
|
76
70
|
]
|
77
71
|
end
|
78
72
|
|
@@ -80,25 +74,25 @@ RSpec.describe Reek::Spec::ShouldReekOnlyOf do
|
|
80
74
|
end
|
81
75
|
|
82
76
|
context 'with 1 matching smell' do
|
83
|
-
|
84
|
-
detector = build(:smell_detector, smell_type:
|
77
|
+
let(:smells) do
|
78
|
+
detector = build(:smell_detector, smell_type: expected_smell_type.to_s)
|
85
79
|
|
86
80
|
[build(:smell_warning, smell_detector: detector,
|
87
|
-
message: "message mentioning #{
|
81
|
+
message: "message mentioning #{expected_context_name}")]
|
88
82
|
end
|
89
83
|
|
90
84
|
it 'matches' do
|
91
|
-
expect(
|
85
|
+
expect(matcher_matches).to be_truthy
|
92
86
|
end
|
93
87
|
|
94
88
|
it 'reports the expected smell when no match was expected' do
|
95
|
-
expect(
|
89
|
+
expect(matcher.failure_message_when_negated).to match(expected_smell_type.to_s)
|
96
90
|
end
|
97
91
|
|
98
92
|
it 'reports the source when no match was expected' do
|
99
93
|
source = 'the_path/to_a/source_file.rb'
|
100
|
-
expect(
|
101
|
-
expect(
|
94
|
+
expect(examiner).to receive(:description).and_return(source)
|
95
|
+
expect(matcher.failure_message_when_negated).to match(source)
|
102
96
|
end
|
103
97
|
end
|
104
98
|
end
|