reek 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +44 -4
- data/License.txt +20 -0
- data/README.rdoc +83 -0
- data/Rakefile +0 -1
- data/bin/reek +3 -11
- data/config/defaults.reek +20 -1
- data/features/masking_smells.feature +111 -0
- data/features/options.feature +49 -0
- data/features/reports.feature +90 -0
- data/features/samples.feature +284 -0
- data/features/stdin.feature +43 -0
- data/features/step_definitions/reek_steps.rb +35 -0
- data/features/support/env.rb +38 -0
- data/lib/reek.rb +1 -1
- data/lib/reek/adapters/application.rb +47 -0
- data/lib/reek/adapters/config_file.rb +31 -0
- data/lib/reek/adapters/core_extras.rb +72 -0
- data/lib/reek/{object_source.rb → adapters/object_source.rb} +15 -19
- data/lib/reek/{rake_task.rb → adapters/rake_task.rb} +2 -2
- data/lib/reek/adapters/report.rb +91 -0
- data/lib/reek/adapters/source.rb +53 -0
- data/lib/reek/{spec.rb → adapters/spec.rb} +45 -60
- data/lib/reek/block_context.rb +1 -1
- data/lib/reek/class_context.rb +26 -6
- data/lib/reek/code_context.rb +8 -0
- data/lib/reek/code_parser.rb +82 -39
- data/lib/reek/command_line.rb +85 -0
- data/lib/reek/configuration.rb +51 -0
- data/lib/reek/detector_stack.rb +39 -0
- data/lib/reek/exceptions.reek +8 -1
- data/lib/reek/method_context.rb +53 -11
- data/lib/reek/module_context.rb +1 -2
- data/lib/reek/name.rb +8 -2
- data/lib/reek/sexp_formatter.rb +2 -0
- data/lib/reek/smell_warning.rb +26 -8
- data/lib/reek/smells/control_couple.rb +8 -4
- data/lib/reek/smells/data_clump.rb +88 -0
- data/lib/reek/smells/duplication.rb +11 -9
- data/lib/reek/smells/feature_envy.rb +3 -4
- data/lib/reek/smells/large_class.rb +17 -17
- data/lib/reek/smells/long_method.rb +10 -8
- data/lib/reek/smells/long_parameter_list.rb +16 -10
- data/lib/reek/smells/long_yield_list.rb +1 -1
- data/lib/reek/smells/nested_iterators.rb +3 -3
- data/lib/reek/smells/simulated_polymorphism.rb +58 -0
- data/lib/reek/smells/smell_detector.rb +94 -27
- data/lib/reek/smells/uncommunicative_name.rb +23 -23
- data/lib/reek/smells/utility_function.rb +27 -11
- data/lib/reek/sniffer.rb +183 -0
- data/reek.gemspec +5 -5
- data/spec/quality/reek_source_spec.rb +15 -0
- data/spec/reek/adapters/report_spec.rb +49 -0
- data/spec/reek/adapters/should_reek_of_spec.rb +108 -0
- data/spec/reek/adapters/should_reek_only_of_spec.rb +87 -0
- data/spec/reek/adapters/should_reek_spec.rb +92 -0
- data/spec/reek/block_context_spec.rb +7 -1
- data/spec/reek/class_context_spec.rb +39 -16
- data/spec/reek/code_context_spec.rb +7 -7
- data/spec/reek/code_parser_spec.rb +6 -1
- data/spec/reek/config_spec.rb +3 -3
- data/spec/reek/configuration_spec.rb +12 -0
- data/spec/reek/method_context_spec.rb +2 -2
- data/spec/reek/name_spec.rb +24 -0
- data/spec/reek/object_source_spec.rb +23 -0
- data/spec/reek/singleton_method_context_spec.rb +2 -2
- data/spec/reek/smell_warning_spec.rb +53 -0
- data/spec/reek/smells/data_clump_spec.rb +87 -0
- data/spec/reek/smells/duplication_spec.rb +13 -17
- data/spec/reek/smells/feature_envy_spec.rb +23 -28
- data/spec/reek/smells/large_class_spec.rb +109 -34
- data/spec/reek/smells/long_method_spec.rb +140 -3
- data/spec/reek/smells/long_parameter_list_spec.rb +1 -2
- data/spec/reek/smells/simulated_polymorphism_spec.rb +50 -0
- data/spec/reek/smells/smell_detector_spec.rb +53 -0
- data/spec/reek/smells/uncommunicative_name_spec.rb +20 -7
- data/spec/reek/smells/utility_function_spec.rb +76 -67
- data/spec/reek/sniffer_spec.rb +10 -0
- data/spec/samples/all_but_one_masked/clean_one.rb +6 -0
- data/spec/samples/all_but_one_masked/dirty.rb +7 -0
- data/spec/samples/all_but_one_masked/masked.reek +5 -0
- data/spec/samples/clean_due_to_masking/clean_one.rb +6 -0
- data/spec/samples/clean_due_to_masking/clean_three.rb +6 -0
- data/spec/samples/clean_due_to_masking/clean_two.rb +6 -0
- data/spec/samples/clean_due_to_masking/dirty_one.rb +7 -0
- data/spec/samples/clean_due_to_masking/dirty_two.rb +7 -0
- data/spec/samples/clean_due_to_masking/masked.reek +7 -0
- data/spec/samples/corrupt_config_file/corrupt.reek +1 -0
- data/spec/samples/corrupt_config_file/dirty.rb +7 -0
- data/spec/samples/empty_config_file/dirty.rb +7 -0
- data/spec/samples/empty_config_file/empty.reek +0 -0
- data/spec/samples/exceptions.reek +4 -0
- data/spec/{slow/samples → samples}/inline.rb +0 -0
- data/spec/samples/masked/dirty.rb +7 -0
- data/spec/samples/masked/masked.reek +3 -0
- data/spec/samples/mixed_results/clean_one.rb +6 -0
- data/spec/samples/mixed_results/clean_three.rb +6 -0
- data/spec/samples/mixed_results/clean_two.rb +6 -0
- data/spec/samples/mixed_results/dirty_one.rb +7 -0
- data/spec/samples/mixed_results/dirty_two.rb +7 -0
- data/spec/samples/not_quite_masked/dirty.rb +8 -0
- data/spec/samples/not_quite_masked/masked.reek +5 -0
- data/spec/{slow/samples → samples}/optparse.rb +0 -0
- data/spec/samples/overrides/masked/dirty.rb +7 -0
- data/spec/samples/overrides/masked/lower.reek +5 -0
- data/spec/samples/overrides/upper.reek +5 -0
- data/spec/{slow/samples → samples}/redcloth.rb +0 -0
- data/spec/samples/three_clean_files/clean_one.rb +6 -0
- data/spec/samples/three_clean_files/clean_three.rb +6 -0
- data/spec/samples/three_clean_files/clean_two.rb +6 -0
- data/spec/samples/two_smelly_files/dirty_one.rb +7 -0
- data/spec/samples/two_smelly_files/dirty_two.rb +7 -0
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +4 -4
- data/tasks/reek.rake +8 -5
- data/tasks/test.rake +51 -0
- metadata +75 -25
- data/README.txt +0 -6
- data/lib/reek/options.rb +0 -92
- data/lib/reek/report.rb +0 -81
- data/lib/reek/smells/smells.rb +0 -81
- data/lib/reek/source.rb +0 -127
- data/spec/reek/options_spec.rb +0 -13
- data/spec/reek/report_spec.rb +0 -48
- data/spec/reek/smells/smell_spec.rb +0 -24
- data/spec/slow/inline_spec.rb +0 -43
- data/spec/slow/optparse_spec.rb +0 -108
- data/spec/slow/redcloth_spec.rb +0 -101
- data/spec/slow/reek_source_spec.rb +0 -20
- data/spec/slow/script_spec.rb +0 -55
- data/spec/slow/source_list_spec.rb +0 -40
- data/tasks/rspec.rake +0 -21
@@ -0,0 +1,92 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
|
3
|
+
require 'reek/adapters/report'
|
4
|
+
require 'reek/adapters/spec'
|
5
|
+
|
6
|
+
include Reek
|
7
|
+
include Reek::Spec
|
8
|
+
|
9
|
+
describe ShouldReek, 'checking code in a string' do
|
10
|
+
before :each do
|
11
|
+
@clean_code = 'def good() true; end'
|
12
|
+
@smelly_code = 'def x() y = 4; end'
|
13
|
+
@matcher = ShouldReek.new
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'matches a smelly String' do
|
17
|
+
@matcher.matches?(@smelly_code).should be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'doesnt match a fragrant String' do
|
21
|
+
@matcher.matches?(@clean_code).should be_false
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'reports the smells when should_not fails' do
|
25
|
+
@matcher.matches?(@smelly_code).should be_true
|
26
|
+
@matcher.failure_message_for_should_not.should include(Report.new(@smelly_code.sniff).quiet_report)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ShouldReek, 'checking code in a Dir' do
|
31
|
+
before :each do
|
32
|
+
@clean_dir = Dir['spec/samples/three_clean_files/*.rb']
|
33
|
+
@smelly_dir = Dir['spec/samples/two_smelly_files/*.rb']
|
34
|
+
@matcher = ShouldReek.new
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'matches a smelly String' do
|
38
|
+
@matcher.matches?(@smelly_dir).should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'doesnt match a fragrant String' do
|
42
|
+
@matcher.matches?(@clean_dir).should be_false
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'reports the smells when should_not fails' do
|
46
|
+
@matcher.matches?(@smelly_dir).should be_true
|
47
|
+
@matcher.failure_message_for_should_not.should include(Report.new(@smelly_dir.sniff.sniffers).quiet_report)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe ShouldReek, 'checking code in a File' do
|
52
|
+
before :each do
|
53
|
+
@clean_file = File.new(Dir['spec/samples/three_clean_files/*.rb'][0])
|
54
|
+
@smelly_file = File.new(Dir['spec/samples/two_smelly_files/*.rb'][0])
|
55
|
+
@matcher = ShouldReek.new
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'matches a smelly String' do
|
59
|
+
@matcher.matches?(@smelly_file).should be_true
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'doesnt match a fragrant String' do
|
63
|
+
@matcher.matches?(@clean_file).should be_false
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'reports the smells when should_not fails' do
|
67
|
+
@matcher.matches?(@smelly_file).should be_true
|
68
|
+
@matcher.failure_message_for_should_not.should include(Report.new(@smelly_file.sniff).quiet_report)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe ShouldReek, 'report formatting' do
|
73
|
+
before :each do
|
74
|
+
sn_clean = 'def clean() @thing = 4; end'.sniff
|
75
|
+
sn_dirty = 'def dirty() thing.cool + thing.cool; end'.sniff
|
76
|
+
sniffers = SnifferSet.new([sn_clean, sn_dirty], '')
|
77
|
+
@matcher = ShouldReek.new
|
78
|
+
@matcher.matches?(sniffers)
|
79
|
+
@lines = @matcher.failure_message_for_should_not.split("\n").map {|str| str.chomp}
|
80
|
+
@error_message = @lines.shift
|
81
|
+
@smells = @lines.grep(/^ /)
|
82
|
+
@headers = (@lines - @smells)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'mentions every smell in the report' do
|
86
|
+
@smells.should have(2).warnings
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'doesnt mention the clean files' do
|
90
|
+
@headers.should have(1).headers
|
91
|
+
end
|
92
|
+
end
|
@@ -27,7 +27,7 @@ describe BlockContext do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should not pass parameters upward" do
|
30
|
-
mc = MethodContext.new(StopContext.new, s(:defn, :help))
|
30
|
+
mc = MethodContext.new(StopContext.new, s(:defn, :help, s(:args)))
|
31
31
|
element = BlockContext.new(mc, s(s(:lasgn, :x)))
|
32
32
|
mc.variable_names.should be_empty
|
33
33
|
end
|
@@ -37,4 +37,10 @@ describe BlockContext do
|
|
37
37
|
bctx.record_local_variable(:q2)
|
38
38
|
bctx.variable_names.should include(Name.new(:q2))
|
39
39
|
end
|
40
|
+
|
41
|
+
it 'copes with a yield to an ivar' do
|
42
|
+
scope = BlockContext.new(StopContext.new, [s(:iasgn, :@list), s(:self)])
|
43
|
+
scope.record_instance_variable(:@list)
|
44
|
+
scope.variable_names.should == [:@list]
|
45
|
+
end
|
40
46
|
end
|
@@ -20,6 +20,7 @@ class Fred
|
|
20
20
|
def simply(arga, argb, argc, argd) f(3);false end
|
21
21
|
end
|
22
22
|
EOEX
|
23
|
+
|
23
24
|
src.should reek_of(:LongParameterList, /Fred/, /simple/)
|
24
25
|
src.should reek_of(:LongParameterList, /Fred/, /simply/)
|
25
26
|
end
|
@@ -33,23 +34,24 @@ class Fred
|
|
33
34
|
def textile_popup_help(name, windowW, windowH) f(3);end
|
34
35
|
end
|
35
36
|
EOEX
|
37
|
+
|
36
38
|
src.should reek_of(:LongParameterList, /Fred/, /textile_bq/)
|
37
39
|
src.should reek_of(:LongParameterList, /Fred/, /textile_fn_/)
|
38
40
|
src.should reek_of(:LongParameterList, /Fred/, /textile_p/)
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
44
|
+
class Above
|
45
|
+
def above() end
|
46
|
+
def both() end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Below < Above
|
50
|
+
def both() end
|
51
|
+
def below() end
|
52
|
+
end
|
53
|
+
|
42
54
|
describe ClassContext, 'overridden methods' do
|
43
|
-
class Above
|
44
|
-
def above() end
|
45
|
-
def both() end
|
46
|
-
end
|
47
|
-
|
48
|
-
class Below < Above
|
49
|
-
def both() end
|
50
|
-
def below() end
|
51
|
-
end
|
52
|
-
|
53
55
|
describe 'of loaded class' do
|
54
56
|
before :each do
|
55
57
|
@ctx = ClassContext.create(StopContext.new, [0, :Below])
|
@@ -97,16 +99,16 @@ describe 'Integration defect:' do
|
|
97
99
|
end
|
98
100
|
end
|
99
101
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
class Klass2
|
105
|
-
end
|
102
|
+
module Mod1
|
103
|
+
class Klass1
|
104
|
+
module Mod2
|
105
|
+
class Klass2
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
109
|
+
end
|
109
110
|
|
111
|
+
describe CodeContext, 'find class' do
|
110
112
|
before :each do
|
111
113
|
@stop = StopContext.new
|
112
114
|
@mod1 = ModuleContext.create(@stop, [0, :Mod1])
|
@@ -166,4 +168,25 @@ describe ClassContext do
|
|
166
168
|
element = ClassContext.create(StopContext.new, [:colon2, [:colon2, [:const, :Treetop], :Runtime], :SyntaxNode])
|
167
169
|
element.num_methods.should == 0
|
168
170
|
end
|
171
|
+
|
172
|
+
it 'counts conditionals correctly' do
|
173
|
+
src = <<EOS
|
174
|
+
class Scrunch
|
175
|
+
def first
|
176
|
+
return @field == :sym ? 0 : 3;
|
177
|
+
end
|
178
|
+
def second
|
179
|
+
if @field == :sym
|
180
|
+
@other += " quarts"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
def third
|
184
|
+
raise 'flu!' unless @field == :sym
|
185
|
+
end
|
186
|
+
end
|
187
|
+
EOS
|
188
|
+
|
189
|
+
ctx = ClassContext.from_s(src)
|
190
|
+
ctx.conditionals.length.should == 3
|
191
|
+
end
|
169
192
|
end
|
@@ -13,7 +13,7 @@ describe CodeContext, 'to_s' do
|
|
13
13
|
|
14
14
|
it "should report full context" do
|
15
15
|
element = StopContext.new
|
16
|
-
element = ModuleContext.new(element,
|
16
|
+
element = ModuleContext.new(element, Name.new(:mod))
|
17
17
|
element = ClassContext.new(element, [0, :klass])
|
18
18
|
element = MethodContext.new(element, [0, :bad])
|
19
19
|
element = BlockContext.new(element, nil)
|
@@ -40,7 +40,7 @@ end
|
|
40
40
|
describe CodeContext, 'instance variables' do
|
41
41
|
it 'should pass instance variables down to the first class' do
|
42
42
|
element = StopContext.new
|
43
|
-
element = ModuleContext.new(element,
|
43
|
+
element = ModuleContext.new(element, Name.new(:mod))
|
44
44
|
class_element = ClassContext.new(element, [0, :klass])
|
45
45
|
element = MethodContext.new(class_element, [0, :bad])
|
46
46
|
element = BlockContext.new(element, nil)
|
@@ -54,7 +54,7 @@ describe CodeContext, 'generics' do
|
|
54
54
|
it 'should pass unknown method calls down the stack' do
|
55
55
|
stop = StopContext.new
|
56
56
|
def stop.bananas(arg1, arg2) arg1 + arg2 + 43 end
|
57
|
-
element = ModuleContext.new(stop,
|
57
|
+
element = ModuleContext.new(stop, Name.new(:mod))
|
58
58
|
class_element = ClassContext.new(element, [0, :klass])
|
59
59
|
element = MethodContext.new(class_element, [0, :bad])
|
60
60
|
element = BlockContext.new(element, nil)
|
@@ -65,19 +65,19 @@ end
|
|
65
65
|
describe CodeContext do
|
66
66
|
it 'should recognise itself in a collection of names' do
|
67
67
|
element = StopContext.new
|
68
|
-
element = ModuleContext.new(element,
|
68
|
+
element = ModuleContext.new(element, Name.new(:mod))
|
69
69
|
element.matches?(['banana', 'mod']).should == true
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'should recognise itself in a collection of REs' do
|
73
73
|
element = StopContext.new
|
74
|
-
element = ModuleContext.new(element,
|
74
|
+
element = ModuleContext.new(element, Name.new(:mod))
|
75
75
|
element.matches?([/banana/, /mod/]).should == true
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'should recognise its fq name in a collection of names' do
|
79
79
|
element = StopContext.new
|
80
|
-
element = ModuleContext.new(element,
|
80
|
+
element = ModuleContext.new(element, Name.new(:mod))
|
81
81
|
element = ClassContext.create(element, [0, :klass])
|
82
82
|
element.matches?(['banana', 'mod']).should == true
|
83
83
|
element.matches?(['banana', 'mod::klass']).should == true
|
@@ -85,7 +85,7 @@ describe CodeContext do
|
|
85
85
|
|
86
86
|
it 'should recognise its fq name in a collection of names' do
|
87
87
|
element = StopContext.new
|
88
|
-
element = ModuleContext.new(element,
|
88
|
+
element = ModuleContext.new(element, Name.new(:mod))
|
89
89
|
element = ClassContext.create(element, [0, :klass])
|
90
90
|
element.matches?([/banana/, /mod/]).should == true
|
91
91
|
element.matches?([/banana/, /mod::klass/]).should == true
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
2
|
|
3
3
|
require 'reek/code_parser'
|
4
|
-
require 'reek/report'
|
5
4
|
|
6
5
|
include Reek
|
7
6
|
|
@@ -32,3 +31,9 @@ end'
|
|
32
31
|
source.should_not reek
|
33
32
|
end
|
34
33
|
end
|
34
|
+
|
35
|
+
describe CodeParser do
|
36
|
+
it 'copes with a yield to an ivar' do
|
37
|
+
'def options() ozz.on { |@list| @prompt = !@list } end'.should_not reek
|
38
|
+
end
|
39
|
+
end
|
data/spec/reek/config_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
2
|
|
3
|
-
require 'reek/
|
3
|
+
require 'reek/sniffer'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
6
|
include Reek
|
7
7
|
|
8
|
-
describe
|
8
|
+
describe Hash do
|
9
9
|
before :each do
|
10
10
|
@first = {
|
11
11
|
'one' => {'two' => 3, 'three' => 4},
|
@@ -32,7 +32,7 @@ describe 'Config' do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe
|
35
|
+
describe Hash, 'merging arrays' do
|
36
36
|
it 'should merge array values' do
|
37
37
|
first = {'key' => {'one' => [1,2,3]}}
|
38
38
|
second = {'key' => {'one' => [4,5]}}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
require 'reek/configuration'
|
4
|
+
|
5
|
+
include Reek
|
6
|
+
|
7
|
+
describe SmellConfiguration do
|
8
|
+
it 'returns the default value when key not found' do
|
9
|
+
cf = SmellConfiguration.new({})
|
10
|
+
cf.value('fred', nil, 27).should == 27
|
11
|
+
end
|
12
|
+
end
|
@@ -24,8 +24,8 @@ end
|
|
24
24
|
describe MethodContext, 'matching fq names' do
|
25
25
|
before :each do
|
26
26
|
element = StopContext.new
|
27
|
-
element = ModuleContext.new(element,
|
28
|
-
element = ClassContext.new(element,
|
27
|
+
element = ModuleContext.new(element, Name.new(:mod))
|
28
|
+
element = ClassContext.new(element, Name.new(:klass))
|
29
29
|
@element = MethodContext.new(element, [0, :meth])
|
30
30
|
end
|
31
31
|
|
data/spec/reek/name_spec.rb
CHANGED
@@ -11,3 +11,27 @@ describe Name, 'resolving symbols' do
|
|
11
11
|
res[1].should == "LargeClass"
|
12
12
|
end
|
13
13
|
end
|
14
|
+
|
15
|
+
describe Name do
|
16
|
+
it 'compares correctly' do
|
17
|
+
a1 = [Name.new('conts'), Name.new('p1'), Name.new('p2'), Name.new('p3')]
|
18
|
+
a2 = [Name.new('name'), Name.new('windowH'), Name.new('windowW')]
|
19
|
+
(a1 & a2).should == []
|
20
|
+
end
|
21
|
+
|
22
|
+
it do
|
23
|
+
[Name.new(:fred)].should include(Name.new(:fred))
|
24
|
+
end
|
25
|
+
|
26
|
+
it do
|
27
|
+
set = Set.new
|
28
|
+
set << Name.new(:fred)
|
29
|
+
set.should include(Name.new(:fred))
|
30
|
+
end
|
31
|
+
|
32
|
+
it do
|
33
|
+
fred = Name.new(:fred)
|
34
|
+
fred.should eql(fred)
|
35
|
+
fred.should eql(Name.new(:fred))
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
include Reek
|
4
|
+
|
5
|
+
describe Dir do
|
6
|
+
it 'reports correct smells via the Dir matcher' do
|
7
|
+
Dir['spec/samples/two_smelly_files/*.rb'].should reek
|
8
|
+
Dir['spec/samples/two_smelly_files/*.rb'].should reek_of(:UncommunicativeName)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'reports correct smells via Dir' do
|
12
|
+
sniffer = Dir['spec/samples/two_smelly_files/*.rb'].sniff
|
13
|
+
sniffer.has_smell?(:UncommunicativeName).should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'copes with daft file specs' do
|
17
|
+
Dir["spec/samples/two_smelly_files/*/.rb"].should_not reek
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'copes with empty array' do
|
21
|
+
[].should_not reek
|
22
|
+
end
|
23
|
+
end
|
@@ -10,8 +10,8 @@ describe SingletonMethodContext, 'outer_name' do
|
|
10
10
|
|
11
11
|
it "should report full context" do
|
12
12
|
element = StopContext.new
|
13
|
-
element = ModuleContext.new(element,
|
14
|
-
element = SingletonMethodContext.new(element,
|
13
|
+
element = ModuleContext.new(element, Name.new(:mod))
|
14
|
+
element = SingletonMethodContext.new(element, s(:defs, s(:call, nil, :a, s(:arglist)), :b, s(:args)))
|
15
15
|
element.outer_name.should match(/mod::a\.b/)
|
16
16
|
end
|
17
17
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
require 'reek/smell_warning'
|
4
|
+
require 'reek/smells/feature_envy'
|
5
|
+
|
6
|
+
include Reek
|
7
|
+
|
8
|
+
describe SmellWarning, 'equality' do
|
9
|
+
before :each do
|
10
|
+
@first = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self", true)
|
11
|
+
@second = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self", false)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should hash equal when the smell is the same' do
|
15
|
+
@first.hash.should == @second.hash
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should compare equal when the smell is the same' do
|
19
|
+
@first.should == @second
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should compare equal when using <=>' do
|
23
|
+
(@first <=> @second).should == 0
|
24
|
+
end
|
25
|
+
|
26
|
+
class CountingReport
|
27
|
+
attr_reader :masked, :non_masked
|
28
|
+
def initialize
|
29
|
+
@masked = @non_masked = 0
|
30
|
+
end
|
31
|
+
def <<(sw)
|
32
|
+
@non_masked += 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def record_masked_smell(sw)
|
36
|
+
@masked += 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'reports as masked when masked' do
|
41
|
+
rpt = CountingReport.new
|
42
|
+
@first.report_on(rpt)
|
43
|
+
rpt.masked.should == 1
|
44
|
+
rpt.non_masked.should == 0
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'reports as non-masked when non-masked' do
|
48
|
+
rpt = CountingReport.new
|
49
|
+
@second.report_on(rpt)
|
50
|
+
rpt.masked.should == 0
|
51
|
+
rpt.non_masked.should == 1
|
52
|
+
end
|
53
|
+
end
|