reek 4.4.1 → 4.4.2
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/.rubocop.yml +46 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +5 -1
- data/docs/Duplicate-Method-Call.md +96 -0
- data/docs/How-To-Write-New-Detectors.md +16 -0
- data/docs/Large-Class.md +2 -1
- data/docs/Simulated-Polymorphism.md +1 -1
- data/features/configuration_via_source_comments/erroneous_source_comments.feature +39 -0
- data/lib/reek/ast/node.rb +4 -0
- data/lib/reek/code_comment.rb +11 -3
- data/lib/reek/context/code_context.rb +3 -1
- data/lib/reek/context/module_context.rb +1 -1
- data/lib/reek/errors.rb +32 -0
- data/lib/reek/examiner.rb +6 -1
- data/lib/reek/rake/task.rb +0 -2
- data/lib/reek/smells/boolean_parameter.rb +1 -1
- data/lib/reek/smells/class_variable.rb +2 -2
- data/lib/reek/smells/instance_variable_assumption.rb +1 -1
- data/lib/reek/smells/prima_donna_method.rb +18 -17
- data/lib/reek/smells/smell_detector.rb +19 -2
- data/lib/reek/smells/unused_private_method.rb +1 -1
- data/lib/reek/spec/should_reek_of.rb +2 -0
- data/lib/reek/version.rb +1 -1
- data/spec/factories/factories.rb +11 -0
- data/spec/quality/reek_source_spec.rb +1 -1
- data/spec/reek/ast/node_spec.rb +40 -0
- data/spec/reek/ast/object_refs_spec.rb +20 -59
- data/spec/reek/ast/sexp_extensions_spec.rb +16 -19
- data/spec/reek/cli/application_spec.rb +25 -25
- data/spec/reek/cli/command/report_command_spec.rb +1 -2
- data/spec/reek/cli/command/todo_list_command_spec.rb +1 -1
- data/spec/reek/cli/options_spec.rb +7 -5
- data/spec/reek/code_comment_spec.rb +74 -44
- data/spec/reek/configuration/default_directive_spec.rb +3 -3
- data/spec/reek/configuration/directory_directives_spec.rb +10 -10
- data/spec/reek/configuration/excluded_paths_spec.rb +2 -2
- data/spec/reek/context/code_context_spec.rb +22 -26
- data/spec/reek/context/ghost_context_spec.rb +1 -1
- data/spec/reek/context/method_context_spec.rb +13 -7
- data/spec/reek/context/module_context_spec.rb +4 -4
- data/spec/reek/context/root_context_spec.rb +1 -1
- data/spec/reek/context_builder_spec.rb +34 -38
- data/spec/reek/examiner_spec.rb +43 -22
- data/spec/reek/rake/task_spec.rb +3 -3
- data/spec/reek/report/code_climate_formatter_spec.rb +42 -40
- data/spec/reek/report/code_climate_report_spec.rb +1 -1
- data/spec/reek/report/html_report_spec.rb +1 -1
- data/spec/reek/report/json_report_spec.rb +1 -1
- data/spec/reek/report/location_formatter_spec.rb +18 -16
- data/spec/reek/report/text_report_spec.rb +12 -8
- data/spec/reek/report/xml_report_spec.rb +1 -1
- data/spec/reek/report/yaml_report_spec.rb +1 -1
- data/spec/reek/report_spec.rb +4 -4
- data/spec/reek/smells/attribute_spec.rb +7 -10
- data/spec/reek/smells/boolean_parameter_spec.rb +14 -20
- data/spec/reek/smells/class_variable_spec.rb +6 -5
- data/spec/reek/smells/control_parameter_spec.rb +3 -2
- data/spec/reek/smells/data_clump_spec.rb +3 -6
- data/spec/reek/smells/duplicate_method_call_spec.rb +10 -14
- data/spec/reek/smells/feature_envy_spec.rb +34 -25
- data/spec/reek/smells/instance_variable_assumption_spec.rb +6 -9
- data/spec/reek/smells/irresponsible_module_spec.rb +3 -6
- data/spec/reek/smells/long_parameter_list_spec.rb +5 -7
- data/spec/reek/smells/long_yield_list_spec.rb +3 -6
- data/spec/reek/smells/manual_dispatch_spec.rb +3 -6
- data/spec/reek/smells/nested_iterators_spec.rb +10 -8
- data/spec/reek/smells/nil_check_spec.rb +2 -1
- data/spec/reek/smells/prima_donna_method_spec.rb +5 -8
- data/spec/reek/smells/smell_configuration_spec.rb +3 -3
- data/spec/reek/smells/smell_detector_spec.rb +10 -0
- data/spec/reek/smells/smell_repository_spec.rb +6 -6
- data/spec/reek/smells/smell_warning_spec.rb +35 -39
- data/spec/reek/smells/subclassed_from_core_class_spec.rb +5 -5
- data/spec/reek/smells/too_many_constants_spec.rb +10 -10
- data/spec/reek/smells/too_many_instance_variables_spec.rb +1 -1
- data/spec/reek/smells/too_many_methods_spec.rb +1 -1
- data/spec/reek/smells/too_many_statements_spec.rb +3 -6
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +9 -6
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +3 -3
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +6 -9
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +20 -24
- data/spec/reek/smells/unused_parameters_spec.rb +35 -24
- data/spec/reek/smells/unused_private_method_spec.rb +25 -33
- data/spec/reek/smells/utility_function_spec.rb +27 -14
- data/spec/reek/source/source_code_spec.rb +6 -6
- data/spec/reek/source/source_locator_spec.rb +34 -17
- data/spec/reek/spec/should_reek_of_spec.rb +17 -12
- data/spec/reek/spec/should_reek_only_of_spec.rb +5 -5
- data/spec/reek/spec/should_reek_spec.rb +3 -3
- data/spec/reek/tree_dresser_spec.rb +6 -4
- data/spec/spec_helper.rb +3 -0
- data/tasks/rubocop.rake +9 -3
- metadata +4 -2
|
@@ -30,30 +30,31 @@ module Reek
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def sniff(ctx)
|
|
33
|
-
ctx.node_instance_methods.
|
|
34
|
-
|
|
35
|
-
end.
|
|
33
|
+
ctx.node_instance_methods.select do |method_sexp|
|
|
34
|
+
prima_donna_method?(method_sexp, ctx)
|
|
35
|
+
end.map do |method_sexp|
|
|
36
|
+
name = method_sexp.name
|
|
37
|
+
smell_warning(
|
|
38
|
+
context: ctx,
|
|
39
|
+
lines: [ctx.exp.line],
|
|
40
|
+
message: "has prima donna method '#{name}'",
|
|
41
|
+
parameters: { name: name.to_s })
|
|
42
|
+
end
|
|
36
43
|
end
|
|
37
44
|
|
|
38
45
|
private
|
|
39
46
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
def prima_donna_method?(method_sexp, ctx)
|
|
48
|
+
return false unless method_sexp.ends_with_bang?
|
|
49
|
+
return false if version_without_bang_exists?(method_sexp, ctx)
|
|
50
|
+
true
|
|
51
|
+
end
|
|
44
52
|
|
|
45
|
-
|
|
53
|
+
# :reek:UtilityFunction
|
|
54
|
+
def version_without_bang_exists?(method_sexp, ctx)
|
|
55
|
+
ctx.node_instance_methods.find do |sexp_item|
|
|
46
56
|
sexp_item.name.to_s == method_sexp.name_without_bang
|
|
47
57
|
end
|
|
48
|
-
|
|
49
|
-
return if version_without_bang
|
|
50
|
-
|
|
51
|
-
name = method_sexp.name
|
|
52
|
-
smell_warning(
|
|
53
|
-
context: ctx,
|
|
54
|
-
lines: [ctx.exp.line],
|
|
55
|
-
message: "has prima donna method '#{name}'",
|
|
56
|
-
parameters: { name: name })
|
|
57
58
|
end
|
|
58
59
|
end
|
|
59
60
|
end
|
|
@@ -72,9 +72,8 @@ module Reek
|
|
|
72
72
|
def smell_warning(options = {})
|
|
73
73
|
context = options.fetch(:context)
|
|
74
74
|
exp = context.exp
|
|
75
|
-
ctx_source = exp.loc.expression.source_buffer.name
|
|
76
75
|
SmellWarning.new(self,
|
|
77
|
-
source:
|
|
76
|
+
source: exp.source,
|
|
78
77
|
context: context.full_name,
|
|
79
78
|
lines: options.fetch(:lines),
|
|
80
79
|
message: options.fetch(:message),
|
|
@@ -102,9 +101,27 @@ module Reek
|
|
|
102
101
|
descendants << subclass
|
|
103
102
|
end
|
|
104
103
|
|
|
104
|
+
#
|
|
105
|
+
# Returns all descendants of SmellDetector
|
|
106
|
+
#
|
|
107
|
+
# @return [Array<Constant>], e.g.:
|
|
108
|
+
# [Reek::Smells::Attribute,
|
|
109
|
+
# Reek::Smells::BooleanParameter,
|
|
110
|
+
# Reek::Smells::ClassVariable,
|
|
111
|
+
# ...]
|
|
112
|
+
#
|
|
105
113
|
def descendants
|
|
106
114
|
@descendants ||= []
|
|
107
115
|
end
|
|
116
|
+
|
|
117
|
+
#
|
|
118
|
+
# @param detector [String] the detector in question, e.g. 'DuplicateMethodCall'
|
|
119
|
+
# @return [Boolean]
|
|
120
|
+
#
|
|
121
|
+
def valid_detector?(detector)
|
|
122
|
+
descendants.map { |descendant| descendant.to_s.split('::').last }.
|
|
123
|
+
include?(detector)
|
|
124
|
+
end
|
|
108
125
|
end
|
|
109
126
|
end
|
|
110
127
|
end
|
data/lib/reek/version.rb
CHANGED
data/spec/factories/factories.rb
CHANGED
|
@@ -52,4 +52,15 @@ FactoryGirl.define do
|
|
|
52
52
|
parameters: parameters)
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
|
+
|
|
56
|
+
factory :code_comment, class: Reek::CodeComment do
|
|
57
|
+
comment ''
|
|
58
|
+
line 1
|
|
59
|
+
source 'string'
|
|
60
|
+
initialize_with do
|
|
61
|
+
new comment: comment,
|
|
62
|
+
line: line,
|
|
63
|
+
source: source
|
|
64
|
+
end
|
|
65
|
+
end
|
|
55
66
|
end
|
data/spec/reek/ast/node_spec.rb
CHANGED
|
@@ -75,4 +75,44 @@ RSpec.describe Reek::AST::Node do
|
|
|
75
75
|
expect(sexp(:foo).length).to eq 1
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
|
+
|
|
79
|
+
describe '#line' do
|
|
80
|
+
context 'source from file' do
|
|
81
|
+
let(:file) { SAMPLES_PATH.join('smelly.rb') }
|
|
82
|
+
let(:ast) { Reek::Source::SourceCode.from(file).syntax_tree }
|
|
83
|
+
|
|
84
|
+
it 'returns the right line number' do
|
|
85
|
+
expect(ast.line).to eq(2)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context 'source from string' do
|
|
90
|
+
let(:source) { File.read(SAMPLES_PATH.join('smelly.rb')) }
|
|
91
|
+
let(:ast) { Reek::Source::SourceCode.from(source).syntax_tree }
|
|
92
|
+
|
|
93
|
+
it 'returns the right line number' do
|
|
94
|
+
expect(ast.line).to eq(2)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe '#source' do
|
|
100
|
+
context 'source from file' do
|
|
101
|
+
let(:file) { SAMPLES_PATH.join('smelly.rb') }
|
|
102
|
+
let(:ast) { Reek::Source::SourceCode.from(file).syntax_tree }
|
|
103
|
+
|
|
104
|
+
it 'returns the file name' do
|
|
105
|
+
expect(ast.source).to eq(SAMPLES_PATH.join('smelly.rb').to_s)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context 'source from string' do
|
|
110
|
+
let(:source) { File.read(SAMPLES_PATH.join('smelly.rb')) }
|
|
111
|
+
let(:ast) { Reek::Source::SourceCode.from(source).syntax_tree }
|
|
112
|
+
|
|
113
|
+
it 'returns "string"' do
|
|
114
|
+
expect(ast.source).to eq('string')
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
78
118
|
end
|
|
@@ -2,57 +2,16 @@ require_relative '../../spec_helper'
|
|
|
2
2
|
require_lib 'reek/ast/object_refs'
|
|
3
3
|
|
|
4
4
|
RSpec.describe Reek::AST::ObjectRefs do
|
|
5
|
-
let(:refs) {
|
|
5
|
+
let(:refs) { described_class.new }
|
|
6
6
|
|
|
7
7
|
context 'when empty' do
|
|
8
|
-
it '
|
|
8
|
+
it 'reports no refs to self' do
|
|
9
9
|
expect(refs.references_to(:self)).to be_empty
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
context 'with references to a, b, and a' do
|
|
14
|
-
context 'with no refs to self' do
|
|
15
|
-
before(:each) do
|
|
16
|
-
refs.record_reference(name: :a)
|
|
17
|
-
refs.record_reference(name: :b)
|
|
18
|
-
refs.record_reference(name: :a)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it 'should report no refs to self' do
|
|
22
|
-
expect(refs.references_to(:self)).to be_empty
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it 'should report :a as the max' do
|
|
26
|
-
expect(refs.most_popular).to include(:a)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it 'should not report self as the max' do
|
|
30
|
-
expect(refs.self_is_max?).to eq(false)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'with one reference to self' do
|
|
34
|
-
before(:each) do
|
|
35
|
-
refs.record_reference(name: :self)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'should report 1 ref to self' do
|
|
39
|
-
expect(refs.references_to(:self).size).to eq(1)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it 'should not report self among the max' do
|
|
43
|
-
expect(refs.most_popular).to include(:a)
|
|
44
|
-
expect(refs.most_popular).not_to include(:self)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it 'should not report self as the max' do
|
|
48
|
-
expect(refs.self_is_max?).to eq(false)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
13
|
context 'with many refs to self' do
|
|
55
|
-
before
|
|
14
|
+
before do
|
|
56
15
|
refs.record_reference(name: :self)
|
|
57
16
|
refs.record_reference(name: :self)
|
|
58
17
|
refs.record_reference(name: :a)
|
|
@@ -62,21 +21,21 @@ RSpec.describe Reek::AST::ObjectRefs do
|
|
|
62
21
|
refs.record_reference(name: :self)
|
|
63
22
|
end
|
|
64
23
|
|
|
65
|
-
it '
|
|
24
|
+
it 'reports all refs to self' do
|
|
66
25
|
expect(refs.references_to(:self).size).to eq(4)
|
|
67
26
|
end
|
|
68
27
|
|
|
69
|
-
it '
|
|
28
|
+
it 'reports self among the max' do
|
|
70
29
|
expect(refs.most_popular).to include(:self)
|
|
71
30
|
end
|
|
72
31
|
|
|
73
|
-
it '
|
|
32
|
+
it 'reports self as the max' do
|
|
74
33
|
expect(refs.self_is_max?).to eq(true)
|
|
75
34
|
end
|
|
76
35
|
end
|
|
77
36
|
|
|
78
37
|
context 'when self is not the only max' do
|
|
79
|
-
before
|
|
38
|
+
before do
|
|
80
39
|
refs.record_reference(name: :a)
|
|
81
40
|
refs.record_reference(name: :self)
|
|
82
41
|
refs.record_reference(name: :self)
|
|
@@ -84,38 +43,40 @@ RSpec.describe Reek::AST::ObjectRefs do
|
|
|
84
43
|
refs.record_reference(name: :a)
|
|
85
44
|
end
|
|
86
45
|
|
|
87
|
-
it '
|
|
46
|
+
it 'reports all refs to self' do
|
|
88
47
|
expect(refs.references_to(:self).size).to eq(2)
|
|
89
48
|
end
|
|
90
49
|
|
|
91
|
-
it '
|
|
92
|
-
expect(refs.most_popular).to include(:a)
|
|
50
|
+
it 'reports self among the max' do
|
|
93
51
|
expect(refs.most_popular).to include(:self)
|
|
94
52
|
end
|
|
95
53
|
|
|
96
|
-
it '
|
|
54
|
+
it 'reports the other max among the max' do
|
|
55
|
+
expect(refs.most_popular).to include(:a)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'reports self as the max' do
|
|
97
59
|
expect(refs.self_is_max?).to eq(true)
|
|
98
60
|
end
|
|
99
61
|
end
|
|
100
62
|
|
|
101
|
-
context 'when self is not
|
|
102
|
-
before
|
|
63
|
+
context 'when self is not recorded' do
|
|
64
|
+
before do
|
|
103
65
|
refs.record_reference(name: :a)
|
|
104
66
|
refs.record_reference(name: :b)
|
|
105
67
|
refs.record_reference(name: :a)
|
|
106
68
|
refs.record_reference(name: :b)
|
|
107
69
|
end
|
|
108
70
|
|
|
109
|
-
it '
|
|
71
|
+
it 'reports no refs to self' do
|
|
110
72
|
expect(refs.references_to(:self).size).to eq(0)
|
|
111
73
|
end
|
|
112
74
|
|
|
113
|
-
it '
|
|
114
|
-
expect(refs.most_popular).
|
|
115
|
-
expect(refs.most_popular).to include(:b)
|
|
75
|
+
it 'does not report self among the max' do
|
|
76
|
+
expect(refs.most_popular).not_to include(:self)
|
|
116
77
|
end
|
|
117
78
|
|
|
118
|
-
it '
|
|
79
|
+
it 'does not report self as the max' do
|
|
119
80
|
expect(refs.self_is_max?).to eq(false)
|
|
120
81
|
end
|
|
121
82
|
end
|
|
@@ -402,60 +402,60 @@ end
|
|
|
402
402
|
|
|
403
403
|
RSpec.describe Reek::AST::SexpExtensions::ModuleNode do
|
|
404
404
|
context 'with a simple name' do
|
|
405
|
-
|
|
405
|
+
let(:exp) do
|
|
406
406
|
Reek::Source::SourceCode.from('module Fred; end').syntax_tree
|
|
407
407
|
end
|
|
408
408
|
|
|
409
409
|
it 'has the correct #name' do
|
|
410
|
-
expect(
|
|
410
|
+
expect(exp.name).to eq 'Fred'
|
|
411
411
|
end
|
|
412
412
|
|
|
413
413
|
it 'has the correct #simple_name' do
|
|
414
|
-
expect(
|
|
414
|
+
expect(exp.simple_name).to eq 'Fred'
|
|
415
415
|
end
|
|
416
416
|
|
|
417
417
|
it 'has a simple full_name' do
|
|
418
|
-
expect(
|
|
418
|
+
expect(exp.full_name('')).to eq 'Fred'
|
|
419
419
|
end
|
|
420
420
|
|
|
421
421
|
it 'has a fq full_name' do
|
|
422
|
-
expect(
|
|
422
|
+
expect(exp.full_name('Blimey::O::Reilly')).to eq 'Blimey::O::Reilly::Fred'
|
|
423
423
|
end
|
|
424
424
|
end
|
|
425
425
|
|
|
426
426
|
context 'with a scoped name' do
|
|
427
|
-
|
|
427
|
+
let(:exp) do
|
|
428
428
|
Reek::Source::SourceCode.from('module Foo::Bar; end').syntax_tree
|
|
429
429
|
end
|
|
430
430
|
|
|
431
431
|
it 'has the correct #name' do
|
|
432
|
-
expect(
|
|
432
|
+
expect(exp.name).to eq 'Foo::Bar'
|
|
433
433
|
end
|
|
434
434
|
|
|
435
435
|
it 'has the correct #simple_name' do
|
|
436
|
-
expect(
|
|
436
|
+
expect(exp.simple_name).to eq 'Bar'
|
|
437
437
|
end
|
|
438
438
|
|
|
439
439
|
it 'has a simple full_name' do
|
|
440
|
-
expect(
|
|
440
|
+
expect(exp.full_name('')).to eq 'Foo::Bar'
|
|
441
441
|
end
|
|
442
442
|
|
|
443
|
-
it 'has a
|
|
444
|
-
expect(
|
|
443
|
+
it 'has a fully qualified full_name' do
|
|
444
|
+
expect(exp.full_name('Blimey::O::Reilly')).to eq 'Blimey::O::Reilly::Foo::Bar'
|
|
445
445
|
end
|
|
446
446
|
end
|
|
447
447
|
|
|
448
448
|
context 'with a name scoped in a namespace that is not a constant' do
|
|
449
|
-
|
|
449
|
+
let(:exp) do
|
|
450
450
|
Reek::Source::SourceCode.from('module foo::Bar; end').syntax_tree
|
|
451
451
|
end
|
|
452
452
|
|
|
453
453
|
it 'has the correct #name' do
|
|
454
|
-
expect(
|
|
454
|
+
expect(exp.name).to eq 'foo::Bar'
|
|
455
455
|
end
|
|
456
456
|
|
|
457
457
|
it 'has the correct #simple_name' do
|
|
458
|
-
expect(
|
|
458
|
+
expect(exp.simple_name).to eq 'Bar'
|
|
459
459
|
end
|
|
460
460
|
end
|
|
461
461
|
end
|
|
@@ -463,12 +463,9 @@ end
|
|
|
463
463
|
RSpec.describe Reek::AST::SexpExtensions::CasgnNode do
|
|
464
464
|
describe '#defines_module?' do
|
|
465
465
|
context 'with single assignment' do
|
|
466
|
-
subject do
|
|
467
|
-
sexp(:casgn, nil, :Foo)
|
|
468
|
-
end
|
|
469
|
-
|
|
470
466
|
it 'does not define a module' do
|
|
471
|
-
|
|
467
|
+
exp = sexp(:casgn, nil, :Foo)
|
|
468
|
+
expect(exp.defines_module?).to be_falsey
|
|
472
469
|
end
|
|
473
470
|
end
|
|
474
471
|
|
|
@@ -6,7 +6,7 @@ RSpec.describe Reek::CLI::Application do
|
|
|
6
6
|
it 'exits with default error code on invalid options' do
|
|
7
7
|
call = lambda do
|
|
8
8
|
Reek::CLI::Silencer.silently do
|
|
9
|
-
|
|
9
|
+
described_class.new ['--foo']
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
expect(call).to raise_error(SystemExit) do |error|
|
|
@@ -22,8 +22,8 @@ RSpec.describe Reek::CLI::Application do
|
|
|
22
22
|
let(:configuration) { test_configuration_for(CONFIG_PATH.join('with_excluded_paths.reek')) }
|
|
23
23
|
|
|
24
24
|
describe '#execute' do
|
|
25
|
-
let(:command) {
|
|
26
|
-
let(:app) {
|
|
25
|
+
let(:command) { instance_double 'Reek::CLI::Command::ReportCommand' }
|
|
26
|
+
let(:app) { described_class.new [] }
|
|
27
27
|
|
|
28
28
|
before do
|
|
29
29
|
allow(Reek::CLI::Command::ReportCommand).to receive(:new).and_return command
|
|
@@ -40,7 +40,7 @@ RSpec.describe Reek::CLI::Application do
|
|
|
40
40
|
allow_any_instance_of(IO).to receive(:tty?).and_return(false)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
it '
|
|
43
|
+
it 'uses source form pipe' do
|
|
44
44
|
app.execute
|
|
45
45
|
expect(Reek::CLI::Command::ReportCommand).to have_received(:new).
|
|
46
46
|
with(sources: [$stdin],
|
|
@@ -54,7 +54,7 @@ RSpec.describe Reek::CLI::Application do
|
|
|
54
54
|
allow_any_instance_of(IO).to receive(:tty?).and_return(true)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
it '
|
|
57
|
+
it 'uses working directory as source' do
|
|
58
58
|
expected_sources = Reek::Source::SourceLocator.new(['.']).sources
|
|
59
59
|
app.execute
|
|
60
60
|
expect(Reek::CLI::Command::ReportCommand).to have_received(:new).
|
|
@@ -62,37 +62,37 @@ RSpec.describe Reek::CLI::Application do
|
|
|
62
62
|
configuration: Reek::Configuration::AppConfiguration,
|
|
63
63
|
options: Reek::CLI::Options)
|
|
64
64
|
end
|
|
65
|
-
end
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
context 'when source files are excluded through configuration' do
|
|
67
|
+
let(:app) { described_class.new ['--config', 'some_file.reek'] }
|
|
69
68
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
before do
|
|
70
|
+
allow(Reek::Configuration::AppConfiguration).
|
|
71
|
+
to receive(:from_path).
|
|
72
|
+
with(Pathname.new('some_file.reek')).
|
|
73
|
+
and_return configuration
|
|
74
|
+
end
|
|
76
75
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
it 'uses configuration for excluded paths' do
|
|
77
|
+
expected_sources = Reek::Source::SourceLocator.
|
|
78
|
+
new(['.'], configuration: configuration).sources
|
|
79
|
+
expect(expected_sources).not_to include(path_excluded_in_configuration)
|
|
81
80
|
|
|
82
|
-
|
|
81
|
+
app.execute
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
expect(Reek::CLI::Command::ReportCommand).to have_received(:new).
|
|
84
|
+
with(sources: expected_sources,
|
|
85
|
+
configuration: configuration,
|
|
86
|
+
options: Reek::CLI::Options)
|
|
87
|
+
end
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
context 'when source files given' do
|
|
93
|
-
let(:app) {
|
|
93
|
+
let(:app) { described_class.new ['.'] }
|
|
94
94
|
|
|
95
|
-
it '
|
|
95
|
+
it 'uses sources from argv' do
|
|
96
96
|
expected_sources = Reek::Source::SourceLocator.new(['.']).sources
|
|
97
97
|
app.execute
|
|
98
98
|
expect(Reek::CLI::Command::ReportCommand).to have_received(:new).
|