reek 1.2.4 → 1.2.5
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.
- data/History.txt +5 -0
- data/lib/reek.rb +1 -1
- data/lib/reek/adapters/report.rb +1 -14
- data/lib/reek/adapters/source.rb +8 -2
- data/lib/reek/masking_collection.rb +2 -2
- data/lib/reek/smells/control_couple.rb +1 -2
- data/lib/reek/smells/smell_detector.rb +0 -14
- data/lib/reek/stop_context.rb +0 -16
- data/lib/reek/tree_dresser.rb +0 -4
- data/reek.gemspec +3 -3
- data/spec/reek/adapters/report_spec.rb +0 -18
- data/spec/reek/adapters/source_spec.rb +16 -0
- data/spec/reek/code_parser_spec.rb +7 -5
- data/spec/reek/masking_collection_spec.rb +16 -16
- data/spec/reek/smells/feature_envy_spec.rb +50 -73
- data/spec/reek/smells/nested_iterators_spec.rb +20 -11
- data/spec/reek/smells/utility_function_spec.rb +3 -9
- data/spec/reek/stop_context_spec.rb +1 -1
- metadata +3 -2
data/History.txt
CHANGED
data/lib/reek.rb
CHANGED
data/lib/reek/adapters/report.rb
CHANGED
@@ -11,20 +11,7 @@ module Reek
|
|
11
11
|
@cwarnings = MaskingCollection.new
|
12
12
|
@desc = sniffer.desc
|
13
13
|
@display_masked_warnings = display_masked_warnings # SMELL: Control Couple
|
14
|
-
sniffer.report_on(
|
15
|
-
end
|
16
|
-
|
17
|
-
def found_smell(warning)
|
18
|
-
@cwarnings.add(warning)
|
19
|
-
true
|
20
|
-
end
|
21
|
-
|
22
|
-
def found_masked_smell(warning)
|
23
|
-
@cwarnings.add_masked(warning)
|
24
|
-
end
|
25
|
-
|
26
|
-
def num_masked_smells # SMELL: getter
|
27
|
-
@cwarnings.num_masked_items
|
14
|
+
sniffer.report_on(@cwarnings)
|
28
15
|
end
|
29
16
|
|
30
17
|
# Creates a formatted report of all the +Smells::SmellWarning+ objects recorded in
|
data/lib/reek/adapters/source.rb
CHANGED
@@ -11,15 +11,21 @@ module Reek
|
|
11
11
|
|
12
12
|
attr_reader :desc
|
13
13
|
|
14
|
-
def initialize(code, desc)
|
14
|
+
def initialize(code, desc, parser = RubyParser.new)
|
15
15
|
@source = code
|
16
16
|
@desc = desc
|
17
|
+
@parser = parser
|
17
18
|
end
|
18
19
|
|
19
20
|
def configure(sniffer) end
|
20
21
|
|
21
22
|
def syntax_tree
|
22
|
-
|
23
|
+
begin
|
24
|
+
ast = @parser.parse(@source, @desc)
|
25
|
+
rescue Exception => error
|
26
|
+
$stderr.puts "#{desc}: #{error.class.name}: #{error}"
|
27
|
+
end
|
28
|
+
ast ||= s()
|
23
29
|
TreeDresser.new.dress(ast)
|
24
30
|
end
|
25
31
|
end
|
@@ -9,11 +9,11 @@ class MaskingCollection
|
|
9
9
|
@visible_items = SortedSet.new
|
10
10
|
@masked_items = SortedSet.new
|
11
11
|
end
|
12
|
-
def
|
12
|
+
def found_smell(item)
|
13
13
|
@visible_items.add(item)
|
14
14
|
@masked_items.delete(item) if @masked_items.include?(item)
|
15
15
|
end
|
16
|
-
def
|
16
|
+
def found_masked_smell(item)
|
17
17
|
@masked_items.add(item) unless @visible_items.include?(item)
|
18
18
|
end
|
19
19
|
def num_visible_items
|
@@ -48,12 +48,11 @@ module Reek
|
|
48
48
|
when IfContext
|
49
49
|
return unless ctx.tests_a_parameter?
|
50
50
|
found(ctx, "is controlled by argument #{SexpFormatter.format(ctx.if_expr)}")
|
51
|
-
|
51
|
+
else
|
52
52
|
ctx.parameters.default_assignments.each do |param, value|
|
53
53
|
next unless [:true, :false].include?(value[0])
|
54
54
|
found(ctx, "is controlled by argument #{param.to_s}")
|
55
55
|
end
|
56
|
-
else
|
57
56
|
end
|
58
57
|
end
|
59
58
|
end
|
@@ -31,10 +31,6 @@ module Reek
|
|
31
31
|
DEFAULT_EXCLUDE_SET = []
|
32
32
|
|
33
33
|
class << self
|
34
|
-
def class_name
|
35
|
-
self.name.split(/::/)[-1]
|
36
|
-
end
|
37
|
-
|
38
34
|
def contexts # :nodoc:
|
39
35
|
[:defn, :defs]
|
40
36
|
end
|
@@ -45,16 +41,6 @@ module Reek
|
|
45
41
|
EXCLUDE_KEY => DEFAULT_EXCLUDE_SET
|
46
42
|
}
|
47
43
|
end
|
48
|
-
|
49
|
-
def create(config)
|
50
|
-
new(config[class_name])
|
51
|
-
end
|
52
|
-
|
53
|
-
def listen(hooks, config)
|
54
|
-
detector = create(config)
|
55
|
-
detector.listen_to(hooks)
|
56
|
-
detector
|
57
|
-
end
|
58
44
|
end
|
59
45
|
|
60
46
|
def initialize(config = self.class.default_config)
|
data/lib/reek/stop_context.rb
CHANGED
@@ -18,10 +18,6 @@ module Reek
|
|
18
18
|
sym = name.to_s
|
19
19
|
@myself.const_defined?(sym) ? @myself.const_get(sym) : nil
|
20
20
|
end
|
21
|
-
|
22
|
-
def has_parameter(sym)
|
23
|
-
false
|
24
|
-
end
|
25
21
|
|
26
22
|
def inside_a_block?
|
27
23
|
false
|
@@ -31,18 +27,6 @@ module Reek
|
|
31
27
|
false
|
32
28
|
end
|
33
29
|
|
34
|
-
def num_statements
|
35
|
-
0
|
36
|
-
end
|
37
|
-
|
38
|
-
def refs
|
39
|
-
@refs
|
40
|
-
end
|
41
|
-
|
42
|
-
def record_depends_on_self
|
43
|
-
false
|
44
|
-
end
|
45
|
-
|
46
30
|
def outer_name
|
47
31
|
''
|
48
32
|
end
|
data/lib/reek/tree_dresser.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.2.
|
5
|
+
s.version = "1.2.5"
|
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-11-
|
9
|
+
s.date = %q{2009-11-19}
|
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", "License.txt", "README.rdoc"]
|
15
|
-
s.files = ["History.txt", "License.txt", "README.rdoc", "Rakefile", "bin/reek", "config/defaults.reek", "features/masking_smells.feature", "features/options.feature", "features/profile.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/adapters/application.rb", "lib/reek/adapters/command_line.rb", "lib/reek/adapters/config_file.rb", "lib/reek/adapters/core_extras.rb", "lib/reek/adapters/rake_task.rb", "lib/reek/adapters/report.rb", "lib/reek/adapters/source.rb", "lib/reek/adapters/spec.rb", "lib/reek/block_context.rb", "lib/reek/class_context.rb", "lib/reek/code_context.rb", "lib/reek/code_parser.rb", "lib/reek/configuration.rb", "lib/reek/detector_stack.rb", "lib/reek/help_command.rb", "lib/reek/if_context.rb", "lib/reek/masking_collection.rb", "lib/reek/method_context.rb", "lib/reek/module_context.rb", "lib/reek/name.rb", "lib/reek/object_refs.rb", "lib/reek/reek_command.rb", "lib/reek/sexp_formatter.rb", "lib/reek/singleton_method_context.rb", "lib/reek/smell_warning.rb", "lib/reek/smells/attribute.rb", "lib/reek/smells/class_variable.rb", "lib/reek/smells/control_couple.rb", "lib/reek/smells/data_clump.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/simulated_polymorphism.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/stop_context.rb", "lib/reek/tree_dresser.rb", "lib/reek/version_command.rb", "lib/reek/yield_call_context.rb", "reek.gemspec", "spec/reek/adapters/report_spec.rb", "spec/reek/adapters/should_reek_of_spec.rb", "spec/reek/adapters/should_reek_only_of_spec.rb", "spec/reek/adapters/should_reek_spec.rb", "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/configuration_spec.rb", "spec/reek/help_command_spec.rb", "spec/reek/if_context_spec.rb", "spec/reek/masking_collection_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/reek_command_spec.rb", "spec/reek/singleton_method_context_spec.rb", "spec/reek/smell_warning_spec.rb", "spec/reek/smells/attribute_spec.rb", "spec/reek/smells/behaves_like_variable_detector.rb", "spec/reek/smells/class_variable_spec.rb", "spec/reek/smells/control_couple_spec.rb", "spec/reek/smells/data_clump_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/simulated_polymorphism_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/sniffer_spec.rb", "spec/reek/stop_context_spec.rb", "spec/reek/tree_dresser_spec.rb", "spec/reek/version_command_spec.rb", "spec/samples/all_but_one_masked/clean_one.rb", "spec/samples/all_but_one_masked/dirty.rb", "spec/samples/all_but_one_masked/masked.reek", "spec/samples/clean_due_to_masking/clean_one.rb", "spec/samples/clean_due_to_masking/clean_three.rb", "spec/samples/clean_due_to_masking/clean_two.rb", "spec/samples/clean_due_to_masking/dirty_one.rb", "spec/samples/clean_due_to_masking/dirty_two.rb", "spec/samples/clean_due_to_masking/masked.reek", "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/exceptions.reek", "spec/samples/inline.rb", "spec/samples/masked/dirty.rb", "spec/samples/masked/masked.reek", "spec/samples/mixed_results/clean_one.rb", "spec/samples/mixed_results/clean_three.rb", "spec/samples/mixed_results/clean_two.rb", "spec/samples/mixed_results/dirty_one.rb", "spec/samples/mixed_results/dirty_two.rb", "spec/samples/not_quite_masked/dirty.rb", "spec/samples/not_quite_masked/masked.reek", "spec/samples/optparse.rb", "spec/samples/overrides/masked/dirty.rb", "spec/samples/overrides/masked/lower.reek", "spec/samples/overrides/upper.reek", "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/spec.opts", "spec/spec_helper.rb", "tasks/reek.rake", "tasks/test.rake"]
|
15
|
+
s.files = ["History.txt", "License.txt", "README.rdoc", "Rakefile", "bin/reek", "config/defaults.reek", "features/masking_smells.feature", "features/options.feature", "features/profile.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/adapters/application.rb", "lib/reek/adapters/command_line.rb", "lib/reek/adapters/config_file.rb", "lib/reek/adapters/core_extras.rb", "lib/reek/adapters/rake_task.rb", "lib/reek/adapters/report.rb", "lib/reek/adapters/source.rb", "lib/reek/adapters/spec.rb", "lib/reek/block_context.rb", "lib/reek/class_context.rb", "lib/reek/code_context.rb", "lib/reek/code_parser.rb", "lib/reek/configuration.rb", "lib/reek/detector_stack.rb", "lib/reek/help_command.rb", "lib/reek/if_context.rb", "lib/reek/masking_collection.rb", "lib/reek/method_context.rb", "lib/reek/module_context.rb", "lib/reek/name.rb", "lib/reek/object_refs.rb", "lib/reek/reek_command.rb", "lib/reek/sexp_formatter.rb", "lib/reek/singleton_method_context.rb", "lib/reek/smell_warning.rb", "lib/reek/smells/attribute.rb", "lib/reek/smells/class_variable.rb", "lib/reek/smells/control_couple.rb", "lib/reek/smells/data_clump.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/simulated_polymorphism.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/stop_context.rb", "lib/reek/tree_dresser.rb", "lib/reek/version_command.rb", "lib/reek/yield_call_context.rb", "reek.gemspec", "spec/reek/adapters/report_spec.rb", "spec/reek/adapters/should_reek_of_spec.rb", "spec/reek/adapters/should_reek_only_of_spec.rb", "spec/reek/adapters/should_reek_spec.rb", "spec/reek/adapters/source_spec.rb", "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/configuration_spec.rb", "spec/reek/help_command_spec.rb", "spec/reek/if_context_spec.rb", "spec/reek/masking_collection_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/reek_command_spec.rb", "spec/reek/singleton_method_context_spec.rb", "spec/reek/smell_warning_spec.rb", "spec/reek/smells/attribute_spec.rb", "spec/reek/smells/behaves_like_variable_detector.rb", "spec/reek/smells/class_variable_spec.rb", "spec/reek/smells/control_couple_spec.rb", "spec/reek/smells/data_clump_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/simulated_polymorphism_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/sniffer_spec.rb", "spec/reek/stop_context_spec.rb", "spec/reek/tree_dresser_spec.rb", "spec/reek/version_command_spec.rb", "spec/samples/all_but_one_masked/clean_one.rb", "spec/samples/all_but_one_masked/dirty.rb", "spec/samples/all_but_one_masked/masked.reek", "spec/samples/clean_due_to_masking/clean_one.rb", "spec/samples/clean_due_to_masking/clean_three.rb", "spec/samples/clean_due_to_masking/clean_two.rb", "spec/samples/clean_due_to_masking/dirty_one.rb", "spec/samples/clean_due_to_masking/dirty_two.rb", "spec/samples/clean_due_to_masking/masked.reek", "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/exceptions.reek", "spec/samples/inline.rb", "spec/samples/masked/dirty.rb", "spec/samples/masked/masked.reek", "spec/samples/mixed_results/clean_one.rb", "spec/samples/mixed_results/clean_three.rb", "spec/samples/mixed_results/clean_two.rb", "spec/samples/mixed_results/dirty_one.rb", "spec/samples/mixed_results/dirty_two.rb", "spec/samples/not_quite_masked/dirty.rb", "spec/samples/not_quite_masked/masked.reek", "spec/samples/optparse.rb", "spec/samples/overrides/masked/dirty.rb", "spec/samples/overrides/masked/lower.reek", "spec/samples/overrides/upper.reek", "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/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
|
@@ -29,21 +29,3 @@ describe ReportSection, "smell_list" do
|
|
29
29
|
@lines[1].should match(/[Feature Envy]/)
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
33
|
-
describe ReportSection, " as a SortedSet" do
|
34
|
-
it 'should only add a smell once' do
|
35
|
-
rpt = ReportSection.new(''.sniff, false)
|
36
|
-
rpt.found_smell SmellWarning.new(Smells::FeatureEnvy.new, "self", 'too many!', false)
|
37
|
-
rpt.found_smell SmellWarning.new(Smells::FeatureEnvy.new, "self", 'too many!', false)
|
38
|
-
lines = rpt.smell_list.split("\n")
|
39
|
-
lines.should have(1).lines
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should not count an identical masked smell' do
|
43
|
-
rpt = ReportSection.new(''.sniff, false)
|
44
|
-
# SMELL: Duplication -- the SmellWarning knows whether to call << or record_masked_smell
|
45
|
-
rpt.found_smell SmellWarning.new(Smells::FeatureEnvy.new, "self", 'too many!', false)
|
46
|
-
rpt.found_masked_smell(SmellWarning.new(Smells::FeatureEnvy.new, "self", 'too many!', true))
|
47
|
-
rpt.header.should == 'string -- 1 warning'
|
48
|
-
end
|
49
|
-
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
|
3
|
+
require 'reek/adapters/source'
|
4
|
+
|
5
|
+
include Reek
|
6
|
+
|
7
|
+
describe Source do
|
8
|
+
context 'when the parser fails' do
|
9
|
+
it 'returns an empty syntax tree' do
|
10
|
+
parser = mock('parser')
|
11
|
+
parser.should_receive(:parse).and_raise(SyntaxError)
|
12
|
+
src = Source.new('', '', parser)
|
13
|
+
src.syntax_tree.should == s()
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -21,14 +21,16 @@ end
|
|
21
21
|
|
22
22
|
describe CodeParser, 'when a yield is the receiver' do
|
23
23
|
it 'reports no problems' do
|
24
|
-
|
24
|
+
src = <<EOS
|
25
|
+
def values(*args)
|
25
26
|
@to_sql += case
|
26
|
-
when block_given? then
|
27
|
-
else
|
27
|
+
when block_given? then yield.to_sql
|
28
|
+
else args.to_sql
|
28
29
|
end
|
29
30
|
self
|
30
|
-
end
|
31
|
-
|
31
|
+
end
|
32
|
+
EOS
|
33
|
+
src.should_not reek
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
@@ -78,7 +78,7 @@ describe MaskingCollection do
|
|
78
78
|
context 'with one visible item' do
|
79
79
|
before :each do
|
80
80
|
@item = "hello"
|
81
|
-
@collection.
|
81
|
+
@collection.found_smell(@item)
|
82
82
|
end
|
83
83
|
it_should_behave_like 'one visible item'
|
84
84
|
end
|
@@ -86,7 +86,7 @@ describe MaskingCollection do
|
|
86
86
|
context 'with one masked item' do
|
87
87
|
before :each do
|
88
88
|
@item = "hiding!"
|
89
|
-
@collection.
|
89
|
+
@collection.found_masked_smell(@item)
|
90
90
|
end
|
91
91
|
it_should_behave_like 'one masked item'
|
92
92
|
end
|
@@ -95,8 +95,8 @@ describe MaskingCollection do
|
|
95
95
|
before :each do
|
96
96
|
@visible = "visible"
|
97
97
|
@masked = "masked"
|
98
|
-
@collection.
|
99
|
-
@collection.
|
98
|
+
@collection.found_masked_smell(@masked)
|
99
|
+
@collection.found_smell(@visible)
|
100
100
|
end
|
101
101
|
it 'has one visible item' do
|
102
102
|
@collection.num_visible_items.should == 1
|
@@ -131,8 +131,8 @@ describe MaskingCollection do
|
|
131
131
|
context 'with one visible item added twice' do
|
132
132
|
before :each do
|
133
133
|
@item = "hello"
|
134
|
-
@collection.
|
135
|
-
@collection.
|
134
|
+
@collection.found_smell(@item)
|
135
|
+
@collection.found_smell(@item)
|
136
136
|
end
|
137
137
|
it_should_behave_like 'one visible item'
|
138
138
|
end
|
@@ -140,8 +140,8 @@ describe MaskingCollection do
|
|
140
140
|
context 'with one masked item added twice' do
|
141
141
|
before :each do
|
142
142
|
@item = "hello"
|
143
|
-
@collection.
|
144
|
-
@collection.
|
143
|
+
@collection.found_masked_smell(@item)
|
144
|
+
@collection.found_masked_smell(@item)
|
145
145
|
end
|
146
146
|
it_should_behave_like 'one masked item'
|
147
147
|
end
|
@@ -150,8 +150,8 @@ describe MaskingCollection do
|
|
150
150
|
before :each do
|
151
151
|
@first_item = "hello"
|
152
152
|
@second_item = "goodbye"
|
153
|
-
@collection.
|
154
|
-
@collection.
|
153
|
+
@collection.found_smell(@first_item)
|
154
|
+
@collection.found_smell(@second_item)
|
155
155
|
end
|
156
156
|
it 'has 2 visible items' do
|
157
157
|
@collection.num_visible_items.should == 2
|
@@ -186,8 +186,8 @@ describe MaskingCollection do
|
|
186
186
|
before :each do
|
187
187
|
@first_item = "hello"
|
188
188
|
@second_item = "goodbye"
|
189
|
-
@collection.
|
190
|
-
@collection.
|
189
|
+
@collection.found_masked_smell(@first_item)
|
190
|
+
@collection.found_masked_smell(@second_item)
|
191
191
|
end
|
192
192
|
it 'has 0 visible items' do
|
193
193
|
@collection.num_visible_items.should == 0
|
@@ -219,8 +219,8 @@ describe MaskingCollection do
|
|
219
219
|
context 'with one masked item later made visible' do
|
220
220
|
before :each do
|
221
221
|
@item = "hello"
|
222
|
-
@collection.
|
223
|
-
@collection.
|
222
|
+
@collection.found_masked_smell(@item)
|
223
|
+
@collection.found_smell(@item)
|
224
224
|
end
|
225
225
|
it_should_behave_like 'one visible item'
|
226
226
|
end
|
@@ -228,8 +228,8 @@ describe MaskingCollection do
|
|
228
228
|
context 'with one visible item later masked' do
|
229
229
|
before :each do
|
230
230
|
@item = "hello"
|
231
|
-
@collection.
|
232
|
-
@collection.
|
231
|
+
@collection.found_smell(@item)
|
232
|
+
@collection.found_masked_smell(@item)
|
233
233
|
end
|
234
234
|
it_should_behave_like 'one visible item'
|
235
235
|
end
|
@@ -20,44 +20,41 @@ describe FeatureEnvy do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should not report single use' do
|
23
|
-
'def no_envy(arga)
|
24
|
-
arga.barg(@item)
|
25
|
-
end'.should_not reek
|
23
|
+
'def no_envy(arga) arga.barg(@item) end'.should_not reek
|
26
24
|
end
|
27
25
|
|
28
26
|
it 'should not report return value' do
|
29
|
-
'def no_envy(arga)
|
30
|
-
arga.barg(@item)
|
31
|
-
arga
|
32
|
-
end'.should_not reek
|
27
|
+
'def no_envy(arga) arga.barg(@item); arga end'.should_not reek
|
33
28
|
end
|
34
29
|
|
35
30
|
it 'should report many calls to parameter' do
|
36
|
-
'def envy(arga)
|
37
|
-
arga.b(arga) + arga.c(@fred)
|
38
|
-
end'.should reek_only_of(:FeatureEnvy, /arga/)
|
31
|
+
'def envy(arga) arga.b(arga) + arga.c(@fred) end'.should reek_only_of(:FeatureEnvy, /arga/)
|
39
32
|
end
|
40
33
|
|
41
34
|
it 'should report highest affinity' do
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
35
|
+
src = <<EOS
|
36
|
+
def total_envy
|
37
|
+
fred = @item
|
38
|
+
total = 0
|
39
|
+
total += fred.price
|
40
|
+
total += fred.tax
|
41
|
+
total *= 1.15
|
42
|
+
end
|
43
|
+
EOS
|
44
|
+
src.should reek_only_of(:FeatureEnvy, /total/)
|
50
45
|
end
|
51
46
|
|
52
47
|
it 'should report multiple affinities' do
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
48
|
+
src = <<EOS
|
49
|
+
def total_envy
|
50
|
+
fred = @item
|
51
|
+
total = 0
|
52
|
+
total += fred.price
|
53
|
+
total += fred.tax
|
54
|
+
end
|
55
|
+
EOS
|
56
|
+
src.should reek_of(:FeatureEnvy, /total/)
|
57
|
+
src.should reek_of(:FeatureEnvy, /fred/)
|
61
58
|
end
|
62
59
|
|
63
60
|
it 'should ignore global variables' do
|
@@ -77,45 +74,27 @@ describe FeatureEnvy do
|
|
77
74
|
end
|
78
75
|
|
79
76
|
it 'should not report ivar usage in a parameter' do
|
80
|
-
'def no_envy
|
81
|
-
@item.price + tax(@item) - savings(@item)
|
82
|
-
end'.should_not reek
|
77
|
+
'def no_envy() @item.price + tax(@item) - savings(@item) end'.should_not reek
|
83
78
|
end
|
84
79
|
|
85
80
|
it 'should not be fooled by duplication' do
|
86
|
-
'def feed(thing)
|
87
|
-
@cow.feed_to(thing.pig)
|
88
|
-
@duck.feed_to(thing.pig)
|
89
|
-
end'.should reek_only_of(:Duplication, /thing.pig/)
|
81
|
+
'def feed(thing) @cow.feed_to(thing.pig); @duck.feed_to(thing.pig) end'.should reek_only_of(:Duplication, /thing.pig/)
|
90
82
|
end
|
91
83
|
|
92
84
|
it 'should count local calls' do
|
93
|
-
'def feed(thing)
|
94
|
-
cow.feed_to(thing.pig)
|
95
|
-
duck.feed_to(thing.pig)
|
96
|
-
end'.should reek_only_of(:Duplication, /thing.pig/)
|
85
|
+
'def feed(thing) cow.feed_to(thing.pig); duck.feed_to(thing.pig) end'.should reek_only_of(:Duplication, /thing.pig/)
|
97
86
|
end
|
98
87
|
|
99
88
|
it 'should not report single use of an lvar' do
|
100
|
-
'def no_envy()
|
101
|
-
lv = @item
|
102
|
-
lv.to_a
|
103
|
-
end'.should_not reek
|
89
|
+
'def no_envy() lv = @item; lv.to_a end'.should_not reek
|
104
90
|
end
|
105
91
|
|
106
92
|
it 'should not report returning an lvar' do
|
107
|
-
'def no_envy()
|
108
|
-
lv = @item
|
109
|
-
lv.to_a
|
110
|
-
lv
|
111
|
-
end'.should_not reek
|
93
|
+
'def no_envy() lv = @item; lv.to_a; lv end'.should_not reek
|
112
94
|
end
|
113
95
|
|
114
96
|
it 'should report many calls to lvar' do
|
115
|
-
'def envy
|
116
|
-
lv = @item
|
117
|
-
lv.price + lv.tax
|
118
|
-
end'.should reek_only_of(:FeatureEnvy, /lv/)
|
97
|
+
'def envy() lv = @item; lv.price + lv.tax; end'.should reek_only_of(:FeatureEnvy, /lv/)
|
119
98
|
#
|
120
99
|
# def moved_version
|
121
100
|
# price + tax
|
@@ -127,19 +106,19 @@ describe FeatureEnvy do
|
|
127
106
|
end
|
128
107
|
|
129
108
|
it 'ignores lvar usage in a parameter' do
|
130
|
-
'def no_envy
|
131
|
-
lv = @item
|
132
|
-
lv.price + tax(lv) - savings(lv)
|
133
|
-
end'.should_not reek
|
109
|
+
'def no_envy() lv = @item; lv.price + tax(lv) - savings(lv); end'.should_not reek
|
134
110
|
end
|
135
111
|
|
136
112
|
it 'ignores multiple ivars' do
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
113
|
+
src = <<EOS
|
114
|
+
def func
|
115
|
+
@other.a
|
116
|
+
@other.b
|
117
|
+
@nother.c
|
118
|
+
@nother.d
|
119
|
+
end
|
120
|
+
EOS
|
121
|
+
src.should_not reek
|
143
122
|
#
|
144
123
|
# def other.func(me)
|
145
124
|
# a
|
@@ -151,21 +130,20 @@ describe FeatureEnvy do
|
|
151
130
|
end
|
152
131
|
|
153
132
|
it 'ignores frequent use of a call' do
|
154
|
-
'def func
|
155
|
-
other.a
|
156
|
-
other.b
|
157
|
-
nother.c
|
158
|
-
end'.should_not reek_of(:FeatureEnvy)
|
133
|
+
'def func() other.a; other.b; nother.c end'.should_not reek_of(:FeatureEnvy)
|
159
134
|
end
|
160
135
|
|
161
136
|
it 'counts self references correctly' do
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
137
|
+
src = <<EOS
|
138
|
+
def adopt!(other)
|
139
|
+
other.keys.each do |key|
|
140
|
+
self[key] += 3
|
141
|
+
self[key] = o4
|
142
|
+
end
|
143
|
+
self
|
144
|
+
end
|
145
|
+
EOS
|
146
|
+
src.should_not reek
|
169
147
|
end
|
170
148
|
end
|
171
149
|
|
@@ -182,7 +160,6 @@ def report
|
|
182
160
|
@report
|
183
161
|
end
|
184
162
|
EOS
|
185
|
-
|
186
163
|
ruby.should_not reek
|
187
164
|
end
|
188
165
|
|
@@ -11,23 +11,32 @@ describe NestedIterators do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should not report method with successive iterators' do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
src = <<EOS
|
15
|
+
def bad(fred)
|
16
|
+
@fred.each {|item| item.each }
|
17
|
+
@jim.each {|ting| ting.each }
|
18
|
+
end
|
19
|
+
EOS
|
20
|
+
src.should_not reek
|
18
21
|
end
|
19
22
|
|
20
23
|
it 'should not report method with chained iterators' do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
src = <<EOS
|
25
|
+
def chained
|
26
|
+
@sig.keys.sort_by { |xray| xray.to_s }.each { |min| md5 << min.to_s }
|
27
|
+
end
|
28
|
+
EOS
|
29
|
+
src.should_not reek
|
24
30
|
end
|
25
31
|
|
26
32
|
it 'should report nested iterators only once per method' do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
33
|
+
src = <<EOS
|
34
|
+
def bad(fred)
|
35
|
+
@fred.each {|item| item.each {|part| @joe.send} }
|
36
|
+
@jim.each {|ting| ting.each {|piece| @hal.send} }
|
37
|
+
end
|
38
|
+
EOS
|
39
|
+
src.should reek_only_of(:NestedIterators)
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
@@ -29,22 +29,16 @@ describe UtilityFunction do
|
|
29
29
|
|
30
30
|
context 'with only one call' do
|
31
31
|
it 'does not report a call to a parameter' do
|
32
|
-
'def simple(arga)
|
33
|
-
arga.to_s
|
34
|
-
end'.should_not reek_of(:UtilityFunction, /simple/)
|
32
|
+
'def simple(arga) arga.to_s end'.should_not reek_of(:UtilityFunction, /simple/)
|
35
33
|
end
|
36
34
|
it 'does not report a call to a constant' do
|
37
|
-
'def simple(arga)
|
38
|
-
FIELDS[arga]
|
39
|
-
end'.should_not reek
|
35
|
+
'def simple(arga) FIELDS[arga] end'.should_not reek
|
40
36
|
end
|
41
37
|
end
|
42
38
|
|
43
39
|
context 'with two or more calls' do
|
44
40
|
it 'reports two calls' do
|
45
|
-
'def simple(arga)
|
46
|
-
arga.to_s + arga.to_i
|
47
|
-
end'.should reek_of(:UtilityFunction, /simple/)
|
41
|
+
'def simple(arga) arga.to_s + arga.to_i end'.should reek_of(:UtilityFunction, /simple/)
|
48
42
|
end
|
49
43
|
it 'should count usages of self'do
|
50
44
|
'def <=>(other) Options[:sort_order].compare(self, other) end'.should_not reek
|
@@ -12,7 +12,7 @@ describe StopContext do
|
|
12
12
|
|
13
13
|
context 'with a module that is not loaded' do
|
14
14
|
it 'does not find the module' do
|
15
|
-
@stop.find_module('
|
15
|
+
@stop.find_module('Nobbles').should == nil
|
16
16
|
end
|
17
17
|
it 'does not find an unqualified class in the module' do
|
18
18
|
@stop.find_module('HtmlExtension').should == nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.5
|
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-11-
|
12
|
+
date: 2009-11-19 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- spec/reek/adapters/should_reek_of_spec.rb
|
121
121
|
- spec/reek/adapters/should_reek_only_of_spec.rb
|
122
122
|
- spec/reek/adapters/should_reek_spec.rb
|
123
|
+
- spec/reek/adapters/source_spec.rb
|
123
124
|
- spec/reek/block_context_spec.rb
|
124
125
|
- spec/reek/class_context_spec.rb
|
125
126
|
- spec/reek/code_context_spec.rb
|