kevinrutherford-reek 1.1.3.7 → 1.1.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +2 -0
- data/features/masking_smells.feature +2 -2
- data/lib/reek/config_file.rb +31 -0
- data/lib/reek/detector_stack.rb +24 -0
- data/lib/reek/object_source.rb +1 -1
- data/lib/reek/smells/duplication.rb +2 -3
- data/lib/reek/smells/large_class.rb +3 -5
- data/lib/reek/smells/long_method.rb +8 -3
- data/lib/reek/smells/long_parameter_list.rb +3 -4
- data/lib/reek/smells/long_yield_list.rb +1 -1
- data/lib/reek/smells/smell_detector.rb +15 -9
- data/lib/reek/smells/uncommunicative_name.rb +4 -6
- data/lib/reek/sniffer.rb +16 -18
- data/lib/reek.rb +1 -1
- data/reek.gemspec +3 -3
- data/spec/reek/smells/duplication_spec.rb +5 -8
- data/spec/reek/smells/smell_detector_spec.rb +28 -0
- metadata +4 -2
data/History.txt
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
** Output now reports on all files examined, even if they have no smells
|
8
8
|
** Smell warnings are indented in the report; file summary headers are not
|
9
9
|
** Reports for multiple sources are run together; no more blank lines
|
10
|
+
* The smells masked by *.reek config files can now be seen:
|
11
|
+
** The header for each source file now counts masked smells
|
10
12
|
|
11
13
|
=== Minor Changes
|
12
14
|
* Several changes to the LongMethod counting algorithm:
|
@@ -22,7 +22,7 @@ Feature: Masking smells using config files
|
|
22
22
|
Scenario: corrupt config file prevents normal output
|
23
23
|
When I run reek spec/samples/corrupt_config_file/dirty.rb
|
24
24
|
Then it fails with exit status 1
|
25
|
-
And it reports the error 'Error:
|
25
|
+
And it reports the error 'Error: Invalid configuration file "corrupt.reek" -- not a Hash'
|
26
26
|
|
27
27
|
Scenario: missing source file is an error
|
28
28
|
When I run reek no_such_file.rb
|
@@ -34,7 +34,7 @@ Feature: Masking smells using config files
|
|
34
34
|
Then it fails with exit status 2
|
35
35
|
And it reports:
|
36
36
|
"""
|
37
|
-
spec/samples/masked/dirty.rb -- 3 warnings:
|
37
|
+
spec/samples/masked/dirty.rb -- 3 warnings (+3 masked):
|
38
38
|
Dirty#a calls @s.title multiple times (Duplication)
|
39
39
|
Dirty#a calls puts(@s.title) multiple times (Duplication)
|
40
40
|
Dirty#a/block/block is nested (Nested Iterators)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Reek
|
4
|
+
class ConfigFile
|
5
|
+
|
6
|
+
def initialize(file_path)
|
7
|
+
@file_path = file_path
|
8
|
+
@hash = YAML.load_file(@file_path) || {}
|
9
|
+
problem('not a Hash') unless Hash === @hash
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Configure the given sniffer using the contents of the config file.
|
14
|
+
#
|
15
|
+
def configure(sniffer)
|
16
|
+
@hash.each { |klass_name, config|
|
17
|
+
sniffer.configure(find_class(klass_name), config)
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_class(name)
|
22
|
+
klass = Reek::Smells.const_get(name)
|
23
|
+
problem("#{name} is not a code smell") unless klass
|
24
|
+
klass
|
25
|
+
end
|
26
|
+
|
27
|
+
def problem(reason)
|
28
|
+
raise "Invalid configuration file \"#{File.basename(@file_path)}\" -- #{reason}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
module Reek
|
3
|
+
class DetectorStack
|
4
|
+
|
5
|
+
def initialize(default_detector)
|
6
|
+
@detectors = [default_detector]
|
7
|
+
end
|
8
|
+
|
9
|
+
def push(config)
|
10
|
+
det = @detectors[0].copy
|
11
|
+
det.configure_with(config)
|
12
|
+
@detectors.each {|smell| smell.be_masked}
|
13
|
+
@detectors << det
|
14
|
+
end
|
15
|
+
|
16
|
+
def listen_to(hooks)
|
17
|
+
@detectors.each { |smell| smell.listen_to(hooks) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def report_on(report)
|
21
|
+
@detectors.each { |smell| smell.report_on(report) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/reek/object_source.rb
CHANGED
@@ -29,8 +29,7 @@ module Reek
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def initialize(config = Duplication.default_config)
|
32
|
-
super
|
33
|
-
@max_calls = config[MAX_ALLOWED_CALLS_KEY]
|
32
|
+
super(config)
|
34
33
|
end
|
35
34
|
|
36
35
|
def examine_context(method)
|
@@ -41,7 +40,7 @@ module Reek
|
|
41
40
|
|
42
41
|
def smelly_calls(method) # :nodoc:
|
43
42
|
method.calls.select do |key,val|
|
44
|
-
val > @
|
43
|
+
val > @config[MAX_ALLOWED_CALLS_KEY] and key[2] != :new
|
45
44
|
end.map { |call_exp| call_exp[0] }
|
46
45
|
end
|
47
46
|
end
|
@@ -37,20 +37,18 @@ module Reek
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def initialize(config = LargeClass.default_config)
|
40
|
-
super
|
41
|
-
@max_methods = config[MAX_ALLOWED_METHODS_KEY]
|
42
|
-
@max_instance_variables = config[MAX_ALLOWED_IVARS_KEY]
|
40
|
+
super(config)
|
43
41
|
end
|
44
42
|
|
45
43
|
def check_num_methods(klass) # :nodoc:
|
46
44
|
count = klass.num_methods
|
47
|
-
return if count <= @
|
45
|
+
return if count <= @config[MAX_ALLOWED_METHODS_KEY]
|
48
46
|
found(klass, "has at least #{count} methods")
|
49
47
|
end
|
50
48
|
|
51
49
|
def check_num_ivars(klass) # :nodoc:
|
52
50
|
count = klass.variable_names.length
|
53
|
-
return if count <= @
|
51
|
+
return if count <= @config[MAX_ALLOWED_IVARS_KEY]
|
54
52
|
found(klass, "has at least #{count} instance variables")
|
55
53
|
end
|
56
54
|
|
@@ -23,9 +23,14 @@ module Reek
|
|
23
23
|
)
|
24
24
|
end
|
25
25
|
|
26
|
+
attr_reader :max_statements
|
27
|
+
|
26
28
|
def initialize(config = LongMethod.default_config)
|
27
|
-
super
|
28
|
-
|
29
|
+
super(config)
|
30
|
+
end
|
31
|
+
|
32
|
+
def max_statements
|
33
|
+
@config['max_statements']
|
29
34
|
end
|
30
35
|
|
31
36
|
#
|
@@ -34,7 +39,7 @@ module Reek
|
|
34
39
|
#
|
35
40
|
def examine_context(method)
|
36
41
|
num = method.num_statements
|
37
|
-
return false if num <=
|
42
|
+
return false if num <= max_statements
|
38
43
|
found(method, "has approx #{num} statements")
|
39
44
|
end
|
40
45
|
end
|
@@ -22,9 +22,8 @@ module Reek
|
|
22
22
|
super.adopt(MAX_ALLOWED_PARAMS_KEY => 3)
|
23
23
|
end
|
24
24
|
|
25
|
-
def initialize(config)
|
26
|
-
super
|
27
|
-
@max_params = config['max_params']
|
25
|
+
def initialize(config = LongParameterList.default_config)
|
26
|
+
super(config)
|
28
27
|
@action = 'has'
|
29
28
|
end
|
30
29
|
|
@@ -34,7 +33,7 @@ module Reek
|
|
34
33
|
#
|
35
34
|
def examine_context(ctx)
|
36
35
|
num_params = ctx.parameters.length
|
37
|
-
return false if num_params <= @max_params
|
36
|
+
return false if num_params <= @config['max_params']
|
38
37
|
found(ctx, "#{@action} #{num_params} parameters")
|
39
38
|
end
|
40
39
|
end
|
@@ -40,23 +40,26 @@ module Reek
|
|
40
40
|
|
41
41
|
def self.listen(hooks, config)
|
42
42
|
detector = create(config)
|
43
|
-
|
43
|
+
detector.listen_to(hooks)
|
44
44
|
detector
|
45
45
|
end
|
46
46
|
|
47
|
-
def initialize(config)
|
48
|
-
@
|
49
|
-
@exceptions = config[EXCLUDE_KEY]
|
47
|
+
def initialize(config = SmellDetector.default_config)
|
48
|
+
@config = config
|
50
49
|
@smells_found = []
|
51
50
|
@masked = false
|
52
51
|
end
|
53
52
|
|
53
|
+
def listen_to(hooks)
|
54
|
+
self.class.contexts.each { |ctx| hooks[ctx] << self }
|
55
|
+
end
|
56
|
+
|
54
57
|
def be_masked
|
55
58
|
@masked = true
|
56
59
|
end
|
57
60
|
|
58
61
|
def enabled?
|
59
|
-
@
|
62
|
+
@config[ENABLED_KEY]
|
60
63
|
end
|
61
64
|
|
62
65
|
def configure(config)
|
@@ -66,12 +69,16 @@ module Reek
|
|
66
69
|
end
|
67
70
|
|
68
71
|
def configure_with(config)
|
69
|
-
@
|
72
|
+
@config.adopt!(config)
|
73
|
+
end
|
74
|
+
|
75
|
+
def copy
|
76
|
+
self.class.new(@config.deep_copy)
|
70
77
|
end
|
71
78
|
|
72
79
|
def examine(context)
|
73
80
|
before = @smells_found.size
|
74
|
-
examine_context(context) if
|
81
|
+
examine_context(context) if enabled? and !exception?(context)
|
75
82
|
@smells_found.length > before
|
76
83
|
end
|
77
84
|
|
@@ -79,8 +86,7 @@ module Reek
|
|
79
86
|
end
|
80
87
|
|
81
88
|
def exception?(context)
|
82
|
-
|
83
|
-
context.matches?(@exceptions)
|
89
|
+
context.matches?(@config[EXCLUDE_KEY])
|
84
90
|
end
|
85
91
|
|
86
92
|
def found(scope, warning)
|
@@ -40,9 +40,7 @@ module Reek
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def initialize(config = UncommunicativeName.default_config)
|
43
|
-
super
|
44
|
-
@reject = config[REJECT_KEY]
|
45
|
-
@accept = config[ACCEPT_KEY]
|
43
|
+
super(config)
|
46
44
|
end
|
47
45
|
|
48
46
|
#
|
@@ -63,15 +61,15 @@ module Reek
|
|
63
61
|
|
64
62
|
def consider_name(context) # :nodoc:
|
65
63
|
name = context.name
|
66
|
-
return false if @
|
64
|
+
return false if @config[ACCEPT_KEY].include?(context.to_s) # TODO: fq_name() ?
|
67
65
|
return false unless is_bad_name?(name)
|
68
66
|
found(context, "has the name '#{name}'")
|
69
67
|
end
|
70
68
|
|
71
69
|
def is_bad_name?(name) # :nodoc:
|
72
70
|
var = name.effective_name
|
73
|
-
return false if var == '*' or @
|
74
|
-
@
|
71
|
+
return false if var == '*' or @config[ACCEPT_KEY].include?(var)
|
72
|
+
@config[REJECT_KEY].detect {|patt| patt === var}
|
75
73
|
end
|
76
74
|
end
|
77
75
|
end
|
data/lib/reek/sniffer.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'reek/detector_stack'
|
1
2
|
require 'reek/smells/control_couple'
|
2
3
|
require 'reek/smells/duplication'
|
3
4
|
require 'reek/smells/feature_envy'
|
@@ -8,6 +9,7 @@ require 'reek/smells/long_yield_list'
|
|
8
9
|
require 'reek/smells/nested_iterators'
|
9
10
|
require 'reek/smells/uncommunicative_name'
|
10
11
|
require 'reek/smells/utility_function'
|
12
|
+
require 'reek/config_file'
|
11
13
|
require 'yaml'
|
12
14
|
|
13
15
|
class Hash
|
@@ -55,7 +57,9 @@ module Reek
|
|
55
57
|
def initialize
|
56
58
|
defaults_file = File.join(File.dirname(__FILE__), '..', '..', 'config', 'defaults.reek')
|
57
59
|
@config = YAML.load_file(defaults_file)
|
58
|
-
@
|
60
|
+
@typed_detectors = nil
|
61
|
+
@detectors = Hash.new
|
62
|
+
SMELL_CLASSES.each { |klass| @detectors[klass] = DetectorStack.new(klass.new) }
|
59
63
|
@listeners = []
|
60
64
|
end
|
61
65
|
|
@@ -67,27 +71,21 @@ module Reek
|
|
67
71
|
#
|
68
72
|
def configure_along_path(filename)
|
69
73
|
path = File.expand_path(File.dirname(filename))
|
70
|
-
all_reekfiles(path).each { |
|
74
|
+
all_reekfiles(path).each { |config_file| ConfigFile.new(config_file).configure(self) }
|
71
75
|
self
|
72
76
|
end
|
73
77
|
|
74
|
-
|
75
|
-
|
76
|
-
# +config_file+.
|
77
|
-
#
|
78
|
-
def configure_with(config_file)
|
79
|
-
hash = YAML.load_file(config_file)
|
80
|
-
return unless hash
|
81
|
-
raise "invalid configuration file \"#{File.basename(config_file)}\"" unless Hash === hash
|
82
|
-
hash.push_keys(@config)
|
78
|
+
def configure(klass, config)
|
79
|
+
@detectors[klass].push(config)
|
83
80
|
end
|
84
81
|
|
85
|
-
def disable(
|
86
|
-
|
82
|
+
def disable(klass)
|
83
|
+
disabled_config = {Reek::Smells::SmellDetector::ENABLED_KEY => false}
|
84
|
+
@detectors[klass].push(disabled_config)
|
87
85
|
end
|
88
86
|
|
89
87
|
def report_on(report)
|
90
|
-
@
|
88
|
+
@detectors.each_value { |stack| stack.report_on(report) }
|
91
89
|
end
|
92
90
|
|
93
91
|
def examine(scope, type)
|
@@ -98,11 +96,11 @@ module Reek
|
|
98
96
|
private
|
99
97
|
|
100
98
|
def smell_listeners()
|
101
|
-
unless @
|
102
|
-
@
|
103
|
-
|
99
|
+
unless @typed_detectors
|
100
|
+
@typed_detectors = Hash.new {|hash,key| hash[key] = [] }
|
101
|
+
@detectors.each_value { |stack| stack.listen_to(@typed_detectors) }
|
104
102
|
end
|
105
|
-
@
|
103
|
+
@typed_detectors
|
106
104
|
end
|
107
105
|
|
108
106
|
def all_reekfiles(path)
|
data/lib/reek.rb
CHANGED
data/reek.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{reek}
|
5
|
-
s.version = "1.1.3.
|
5
|
+
s.version = "1.1.3.8"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Kevin Rutherford"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-06}
|
10
10
|
s.default_executable = %q{reek}
|
11
11
|
s.description = %q{Code smell detector for Ruby}
|
12
12
|
s.email = ["kevin@rutherford-software.com"]
|
13
13
|
s.executables = ["reek"]
|
14
14
|
s.extra_rdoc_files = ["History.txt", "README.txt"]
|
15
|
-
s.files = ["History.txt", "README.txt", "Rakefile", "bin/reek", "config/defaults.reek", "features/masking_smells.feature", "features/options.feature", "features/rake_task.feature", "features/reports.feature", "features/samples.feature", "features/stdin.feature", "features/step_definitions/reek_steps.rb", "features/support/env.rb", "lib/reek.rb", "lib/reek/block_context.rb", "lib/reek/class_context.rb", "lib/reek/code_context.rb", "lib/reek/code_parser.rb", "lib/reek/exceptions.reek", "lib/reek/if_context.rb", "lib/reek/method_context.rb", "lib/reek/module_context.rb", "lib/reek/name.rb", "lib/reek/object_refs.rb", "lib/reek/object_source.rb", "lib/reek/options.rb", "lib/reek/rake_task.rb", "lib/reek/report.rb", "lib/reek/sexp_formatter.rb", "lib/reek/singleton_method_context.rb", "lib/reek/smell_warning.rb", "lib/reek/smells/control_couple.rb", "lib/reek/smells/duplication.rb", "lib/reek/smells/feature_envy.rb", "lib/reek/smells/large_class.rb", "lib/reek/smells/long_method.rb", "lib/reek/smells/long_parameter_list.rb", "lib/reek/smells/long_yield_list.rb", "lib/reek/smells/nested_iterators.rb", "lib/reek/smells/smell_detector.rb", "lib/reek/smells/uncommunicative_name.rb", "lib/reek/smells/utility_function.rb", "lib/reek/sniffer.rb", "lib/reek/source.rb", "lib/reek/spec.rb", "lib/reek/stop_context.rb", "lib/reek/yield_call_context.rb", "reek.gemspec", "spec/reek/block_context_spec.rb", "spec/reek/class_context_spec.rb", "spec/reek/code_context_spec.rb", "spec/reek/code_parser_spec.rb", "spec/reek/config_spec.rb", "spec/reek/if_context_spec.rb", "spec/reek/method_context_spec.rb", "spec/reek/module_context_spec.rb", "spec/reek/name_spec.rb", "spec/reek/object_refs_spec.rb", "spec/reek/object_source_spec.rb", "spec/reek/options_spec.rb", "spec/reek/report_spec.rb", "spec/reek/singleton_method_context_spec.rb", "spec/reek/smell_warning_spec.rb", "spec/reek/smells/control_couple_spec.rb", "spec/reek/smells/duplication_spec.rb", "spec/reek/smells/feature_envy_spec.rb", "spec/reek/smells/large_class_spec.rb", "spec/reek/smells/long_method_spec.rb", "spec/reek/smells/long_parameter_list_spec.rb", "spec/reek/smells/nested_iterators_spec.rb", "spec/reek/smells/smell_detector_spec.rb", "spec/reek/smells/uncommunicative_name_spec.rb", "spec/reek/smells/utility_function_spec.rb", "spec/reek/spec_spec.rb", "spec/samples/corrupt_config_file/corrupt.reek", "spec/samples/corrupt_config_file/dirty.rb", "spec/samples/empty_config_file/dirty.rb", "spec/samples/empty_config_file/empty.reek", "spec/samples/inline.rb", "spec/samples/masked/dirty.rb", "spec/samples/masked/masked.reek", "spec/samples/optparse.rb", "spec/samples/redcloth.rb", "spec/samples/three_clean_files/clean_one.rb", "spec/samples/three_clean_files/clean_three.rb", "spec/samples/three_clean_files/clean_two.rb", "spec/samples/two_smelly_files/dirty_one.rb", "spec/samples/two_smelly_files/dirty_two.rb", "spec/slow/inline_spec.rb", "spec/slow/optparse_spec.rb", "spec/slow/redcloth_spec.rb", "spec/slow/reek_source_spec.rb", "spec/slow/source_list_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/reek.rake", "tasks/test.rake"]
|
15
|
+
s.files = ["History.txt", "README.txt", "Rakefile", "bin/reek", "config/defaults.reek", "features/masking_smells.feature", "features/options.feature", "features/rake_task.feature", "features/reports.feature", "features/samples.feature", "features/stdin.feature", "features/step_definitions/reek_steps.rb", "features/support/env.rb", "lib/reek.rb", "lib/reek/block_context.rb", "lib/reek/class_context.rb", "lib/reek/code_context.rb", "lib/reek/code_parser.rb", "lib/reek/config_file.rb", "lib/reek/detector_stack.rb", "lib/reek/exceptions.reek", "lib/reek/if_context.rb", "lib/reek/method_context.rb", "lib/reek/module_context.rb", "lib/reek/name.rb", "lib/reek/object_refs.rb", "lib/reek/object_source.rb", "lib/reek/options.rb", "lib/reek/rake_task.rb", "lib/reek/report.rb", "lib/reek/sexp_formatter.rb", "lib/reek/singleton_method_context.rb", "lib/reek/smell_warning.rb", "lib/reek/smells/control_couple.rb", "lib/reek/smells/duplication.rb", "lib/reek/smells/feature_envy.rb", "lib/reek/smells/large_class.rb", "lib/reek/smells/long_method.rb", "lib/reek/smells/long_parameter_list.rb", "lib/reek/smells/long_yield_list.rb", "lib/reek/smells/nested_iterators.rb", "lib/reek/smells/smell_detector.rb", "lib/reek/smells/uncommunicative_name.rb", "lib/reek/smells/utility_function.rb", "lib/reek/sniffer.rb", "lib/reek/source.rb", "lib/reek/spec.rb", "lib/reek/stop_context.rb", "lib/reek/yield_call_context.rb", "reek.gemspec", "spec/reek/block_context_spec.rb", "spec/reek/class_context_spec.rb", "spec/reek/code_context_spec.rb", "spec/reek/code_parser_spec.rb", "spec/reek/config_spec.rb", "spec/reek/if_context_spec.rb", "spec/reek/method_context_spec.rb", "spec/reek/module_context_spec.rb", "spec/reek/name_spec.rb", "spec/reek/object_refs_spec.rb", "spec/reek/object_source_spec.rb", "spec/reek/options_spec.rb", "spec/reek/report_spec.rb", "spec/reek/singleton_method_context_spec.rb", "spec/reek/smell_warning_spec.rb", "spec/reek/smells/control_couple_spec.rb", "spec/reek/smells/duplication_spec.rb", "spec/reek/smells/feature_envy_spec.rb", "spec/reek/smells/large_class_spec.rb", "spec/reek/smells/long_method_spec.rb", "spec/reek/smells/long_parameter_list_spec.rb", "spec/reek/smells/nested_iterators_spec.rb", "spec/reek/smells/smell_detector_spec.rb", "spec/reek/smells/uncommunicative_name_spec.rb", "spec/reek/smells/utility_function_spec.rb", "spec/reek/spec_spec.rb", "spec/samples/corrupt_config_file/corrupt.reek", "spec/samples/corrupt_config_file/dirty.rb", "spec/samples/empty_config_file/dirty.rb", "spec/samples/empty_config_file/empty.reek", "spec/samples/inline.rb", "spec/samples/masked/dirty.rb", "spec/samples/masked/masked.reek", "spec/samples/optparse.rb", "spec/samples/redcloth.rb", "spec/samples/three_clean_files/clean_one.rb", "spec/samples/three_clean_files/clean_three.rb", "spec/samples/three_clean_files/clean_two.rb", "spec/samples/two_smelly_files/dirty_one.rb", "spec/samples/two_smelly_files/dirty_two.rb", "spec/slow/inline_spec.rb", "spec/slow/optparse_spec.rb", "spec/slow/redcloth_spec.rb", "spec/slow/reek_source_spec.rb", "spec/slow/source_list_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/reek.rake", "tasks/test.rake"]
|
16
16
|
s.homepage = %q{http://wiki.github.com/kevinrutherford/reek}
|
17
17
|
s.post_install_message = %q{
|
18
18
|
For more information on reek, see http://wiki.github.com/kevinrutherford/reek
|
@@ -41,26 +41,23 @@ describe Duplication, "non-repeated method calls" do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
require 'ostruct'
|
45
|
-
|
46
44
|
describe Duplication, '#examine' do
|
47
45
|
before :each do
|
48
|
-
@mc =
|
46
|
+
@mc = MethodContext.new(StopContext.new, s(:defn, :fred))
|
49
47
|
@dup = Duplication.new
|
50
48
|
end
|
51
49
|
|
52
50
|
it 'should return true when reporting a smell' do
|
53
|
-
@mc.
|
51
|
+
3.times { @mc.record_call_to(s(:call, nil, :other, s(:arglist)))}
|
54
52
|
@dup.examine(@mc).should == true
|
55
53
|
end
|
56
|
-
|
54
|
+
|
57
55
|
it 'should return false when not reporting a smell' do
|
58
|
-
@mc.calls = []
|
59
56
|
@dup.examine(@mc).should == false
|
60
57
|
end
|
61
|
-
|
58
|
+
|
62
59
|
it 'should return false when not reporting calls to new' do
|
63
|
-
@mc.
|
60
|
+
4.times { @mc.record_call_to(s(:call, s(:Set), :new, s(:arglist)))}
|
64
61
|
@dup.examine(@mc).should == false
|
65
62
|
end
|
66
63
|
end
|
@@ -7,6 +7,34 @@ require 'reek/smells/large_class'
|
|
7
7
|
include Reek
|
8
8
|
include Reek::Smells
|
9
9
|
|
10
|
+
describe SmellDetector, 'configuration' do
|
11
|
+
before:each do
|
12
|
+
@detector = LongMethod.new
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'adopts new max_statements value' do
|
16
|
+
@detector.configure_with('max_statements' => 25)
|
17
|
+
@detector.max_statements.should == 25
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe SmellDetector, 'when copied' do
|
22
|
+
before :each do
|
23
|
+
@detector = LongMethod.new
|
24
|
+
@copy = @detector.copy
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should have the same state' do
|
28
|
+
@copy.max_statements.should == @detector.max_statements
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should change independently of its parent' do
|
32
|
+
default_max = @detector.max_statements
|
33
|
+
@copy.configure_with('max_statements' => 25)
|
34
|
+
@detector.max_statements.should == default_max
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
10
38
|
describe SmellDetector, 'when masked' do
|
11
39
|
before(:each) do
|
12
40
|
@detector = Duplication.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kevinrutherford-reek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.3.
|
4
|
+
version: 1.1.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Rutherford
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-06 00:00:00 -07:00
|
13
13
|
default_executable: reek
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -71,6 +71,8 @@ files:
|
|
71
71
|
- lib/reek/class_context.rb
|
72
72
|
- lib/reek/code_context.rb
|
73
73
|
- lib/reek/code_parser.rb
|
74
|
+
- lib/reek/config_file.rb
|
75
|
+
- lib/reek/detector_stack.rb
|
74
76
|
- lib/reek/exceptions.reek
|
75
77
|
- lib/reek/if_context.rb
|
76
78
|
- lib/reek/method_context.rb
|