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,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,72 @@
|
|
1
|
+
require 'reek/adapters/source'
|
2
|
+
require 'reek/sniffer'
|
3
|
+
|
4
|
+
class Object
|
5
|
+
#
|
6
|
+
# Creates a new +Sniffer+ that assumes this object contains Ruby source
|
7
|
+
# code and examines that code for smells. Calls +to_reek_source+ on self
|
8
|
+
# to obtain the +Source+ object wrapper.
|
9
|
+
#
|
10
|
+
def sniff
|
11
|
+
Reek::Sniffer.new(self.to_reek_source)
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# Constructs a Sniffer which examines this object for code smells.
|
16
|
+
# (This feature is only enabled if you have the ParseTree gem installed.)
|
17
|
+
#
|
18
|
+
def to_reek_source
|
19
|
+
ObjectSource.new(self, self.to_s)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class File
|
24
|
+
#
|
25
|
+
# Creates a new +Source+ that assumes this File contains Ruby source
|
26
|
+
# code and prepares it to be examined for code smells.
|
27
|
+
#
|
28
|
+
def to_reek_source
|
29
|
+
Reek::SourceFile.new(self)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class IO
|
34
|
+
#
|
35
|
+
# Creates a new +Source+ that assumes this IO stream contains Ruby source
|
36
|
+
# code and prepares it to be examined for code smells.
|
37
|
+
#
|
38
|
+
def to_reek_source(description = 'io')
|
39
|
+
Reek::Source.new(self.readlines.join, description)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class String
|
44
|
+
#
|
45
|
+
# Creates a new +Source+ that assumes this string contains Ruby source
|
46
|
+
# code and prepares it to be examined for code smells.
|
47
|
+
#
|
48
|
+
def to_reek_source
|
49
|
+
Reek::Source.new(self, 'string')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Array
|
54
|
+
def paths
|
55
|
+
self.map do |path|
|
56
|
+
if test 'd', path
|
57
|
+
Dir["#{path}/**/*.rb"].paths
|
58
|
+
else
|
59
|
+
path
|
60
|
+
end
|
61
|
+
end.flatten.sort
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Creates a new +Sniffer+ that assumes this Array contains the names
|
66
|
+
# of Ruby source files and examines those files for smells.
|
67
|
+
#
|
68
|
+
def sniff
|
69
|
+
sniffers = paths.map {|path| File.new(path).sniff}
|
70
|
+
Reek::SnifferSet.new(sniffers, 'dir')
|
71
|
+
end
|
72
|
+
end
|
@@ -1,15 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
# Factory method: creates a +Source+ from obj.
|
5
|
-
# The code is not parsed until +report+ is called.
|
6
|
-
# (This feature is only enabled if you have the ParseTree gem installed.)
|
7
|
-
#
|
8
|
-
def self.from_object(obj)
|
9
|
-
return ObjectSource.new(obj, obj.to_s)
|
10
|
-
end
|
11
|
-
end
|
1
|
+
require 'reek/adapters/source'
|
2
|
+
require 'reek/configuration'
|
12
3
|
|
4
|
+
module Reek
|
13
5
|
class ObjectSource < Source # :nodoc:
|
14
6
|
|
15
7
|
def self.unify(sexp) # :nodoc:
|
@@ -20,7 +12,13 @@ module Reek
|
|
20
12
|
return unifier.process(sexp[0])
|
21
13
|
end
|
22
14
|
|
23
|
-
def
|
15
|
+
def configure(sniffer)
|
16
|
+
super
|
17
|
+
disabled_config = {Reek::SmellConfiguration::ENABLED_KEY => false}
|
18
|
+
sniffer.configure(LargeClass, disabled_config)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.can_parse_objects?
|
24
22
|
return true if Object.const_defined?(:ParseTree)
|
25
23
|
begin
|
26
24
|
require 'parse_tree'
|
@@ -30,8 +28,8 @@ module Reek
|
|
30
28
|
end
|
31
29
|
end
|
32
30
|
|
33
|
-
def
|
34
|
-
if can_parse_objects?
|
31
|
+
def syntax_tree
|
32
|
+
if ObjectSource.can_parse_objects?
|
35
33
|
ObjectSource.unify(ParseTree.new.parse_tree(@source))
|
36
34
|
else
|
37
35
|
throw ArgumentError.new('You must install the ParseTree gem to use this feature')
|
@@ -42,12 +40,10 @@ end
|
|
42
40
|
|
43
41
|
class Object
|
44
42
|
#
|
45
|
-
# Constructs a
|
46
|
-
# to generate an abstract syntax tree for the object, which can in turn then
|
47
|
-
# be examined for code smells.
|
43
|
+
# Constructs a Sniffer which examines this object for code smells.
|
48
44
|
# (This feature is only enabled if you have the ParseTree gem installed.)
|
49
45
|
#
|
50
|
-
def
|
51
|
-
|
46
|
+
def to_reek_source
|
47
|
+
ObjectSource.new(self, self.to_s)
|
52
48
|
end
|
53
49
|
end
|
@@ -59,7 +59,7 @@ module Reek
|
|
59
59
|
# Defines a new task, using the name +name+.
|
60
60
|
def initialize(name = :reek)
|
61
61
|
@name = name
|
62
|
-
@libs = [File.expand_path(File.dirname(__FILE__) + '
|
62
|
+
@libs = [File.expand_path(File.dirname(__FILE__) + '/../../../lib')]
|
63
63
|
@source_files = nil
|
64
64
|
@ruby_opts = []
|
65
65
|
@reek_opts = ''
|
@@ -87,7 +87,7 @@ private
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def self.reek_script
|
90
|
-
File.expand_path(File.dirname(__FILE__) + '
|
90
|
+
File.expand_path(File.dirname(__FILE__) + '/../../../bin/reek')
|
91
91
|
end
|
92
92
|
|
93
93
|
def self.ruby_exe
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'reek/command_line' # SMELL: Global Variable
|
3
|
+
|
4
|
+
module Reek
|
5
|
+
class ReportSection
|
6
|
+
|
7
|
+
def initialize(sniffer) # :nodoc:
|
8
|
+
@masked_warnings = SortedSet.new
|
9
|
+
@warnings = SortedSet.new
|
10
|
+
@desc = sniffer.desc
|
11
|
+
sniffer.report_on(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
def <<(smell) # :nodoc:
|
15
|
+
@warnings << smell
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def record_masked_smell(smell)
|
20
|
+
@masked_warnings << smell
|
21
|
+
end
|
22
|
+
|
23
|
+
def num_masked_smells # SMELL: getter
|
24
|
+
@masked_warnings.length
|
25
|
+
end
|
26
|
+
|
27
|
+
# Creates a formatted report of all the +Smells::SmellWarning+ objects recorded in
|
28
|
+
# this report, with a heading.
|
29
|
+
def full_report
|
30
|
+
return quiet_report if Options[:quiet]
|
31
|
+
result = header
|
32
|
+
result += ":\n#{smell_list}" if should_report
|
33
|
+
result += "\n"
|
34
|
+
result
|
35
|
+
end
|
36
|
+
|
37
|
+
def quiet_report
|
38
|
+
return '' unless should_report
|
39
|
+
"#{header}:\n#{smell_list}\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
def header
|
43
|
+
@all_warnings = SortedSet.new(@warnings) # SMELL: Temporary Field
|
44
|
+
@all_warnings.merge(@masked_warnings)
|
45
|
+
"#{@desc} -- #{visible_header}#{masked_header}"
|
46
|
+
end
|
47
|
+
|
48
|
+
# Creates a formatted report of all the +Smells::SmellWarning+ objects recorded in
|
49
|
+
# this report.
|
50
|
+
def smell_list
|
51
|
+
smells = Options[:show_all] ? @all_warnings : @warnings
|
52
|
+
smells.map {|smell| " #{smell.report}"}.join("\n")
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def should_report
|
58
|
+
@warnings.length > 0 or (Options[:show_all] and @masked_warnings.length > 0)
|
59
|
+
end
|
60
|
+
|
61
|
+
def visible_header
|
62
|
+
num_smells = @warnings.length
|
63
|
+
result = "#{num_smells} warning"
|
64
|
+
result += 's' unless num_smells == 1
|
65
|
+
result
|
66
|
+
end
|
67
|
+
|
68
|
+
def masked_header
|
69
|
+
num_masked_warnings = @all_warnings.length - @warnings.length
|
70
|
+
num_masked_warnings == 0 ? '' : " (+#{num_masked_warnings} masked)"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class Report
|
75
|
+
|
76
|
+
def initialize(sniffers)
|
77
|
+
@partials = Array(sniffers).map {|sn| ReportSection.new(sn)}
|
78
|
+
end
|
79
|
+
|
80
|
+
# SMELL: Shotgun Surgery
|
81
|
+
# This method and the next will have to be repeated for every new
|
82
|
+
# kind of report.
|
83
|
+
def full_report
|
84
|
+
@partials.map { |rpt| rpt.full_report }.join
|
85
|
+
end
|
86
|
+
|
87
|
+
def quiet_report
|
88
|
+
@partials.map { |rpt| rpt.quiet_report }.join
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'reek/adapters/config_file'
|
2
|
+
|
3
|
+
module Reek
|
4
|
+
|
5
|
+
#
|
6
|
+
# A +Source+ object represents a chunk of Ruby source code.
|
7
|
+
#
|
8
|
+
class Source
|
9
|
+
|
10
|
+
attr_reader :desc
|
11
|
+
|
12
|
+
def initialize(code, desc)
|
13
|
+
@source = code
|
14
|
+
@desc = desc
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure(sniffer) end
|
18
|
+
|
19
|
+
def syntax_tree
|
20
|
+
RubyParser.new.parse(@source, @desc) || s()
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Represents a file of Ruby source, whose contents will be examined
|
26
|
+
# for code smells.
|
27
|
+
#
|
28
|
+
class SourceFile < Source
|
29
|
+
|
30
|
+
def self.lines(file)
|
31
|
+
IO.readlines(file.path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(file)
|
35
|
+
@file = file
|
36
|
+
super(SourceFile.lines(@file).join, @file.path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def configure(sniffer)
|
40
|
+
path = File.expand_path(File.dirname(@file.path))
|
41
|
+
all_config_files(path).each { |cf| ConfigFile.new(cf).configure(sniffer) }
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def all_config_files(path)
|
47
|
+
return [] unless File.exist?(path)
|
48
|
+
parent = File.dirname(path)
|
49
|
+
return [] if path == parent
|
50
|
+
all_config_files(parent) + Dir["#{path}/*.reek"]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,4 +1,7 @@
|
|
1
|
-
require 'reek/
|
1
|
+
require 'reek/sniffer'
|
2
|
+
require 'reek/adapters/core_extras'
|
3
|
+
require 'reek/adapters/object_source'
|
4
|
+
require 'reek/adapters/report'
|
2
5
|
|
3
6
|
module Reek
|
4
7
|
|
@@ -34,75 +37,83 @@ module Reek
|
|
34
37
|
# And a more complex example, making use of one of the factory methods for
|
35
38
|
# +Source+ so that the code is parsed and analysed only once:
|
36
39
|
#
|
37
|
-
# ruby = 'def double_thing() @other.thing.foo + @other.thing.foo end'.
|
40
|
+
# ruby = 'def double_thing() @other.thing.foo + @other.thing.foo end'.sniff
|
38
41
|
# ruby.should reek_of(:Duplication, /@other.thing[^\.]/)
|
39
42
|
# ruby.should reek_of(:Duplication, /@other.thing.foo/)
|
40
43
|
# ruby.should_not reek_of(:FeatureEnvy)
|
41
44
|
#
|
42
45
|
module Spec
|
46
|
+
module ReekMatcher
|
47
|
+
def report
|
48
|
+
Report.new(@sniffer.sniffers).quiet_report
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
43
52
|
class ShouldReek # :nodoc:
|
53
|
+
include ReekMatcher
|
54
|
+
|
44
55
|
def matches?(actual)
|
45
|
-
@
|
46
|
-
@
|
56
|
+
@sniffer = actual.sniff
|
57
|
+
@sniffer.smelly?
|
47
58
|
end
|
48
59
|
def failure_message_for_should
|
49
|
-
"Expected
|
60
|
+
"Expected #{@sniffer.desc} to reek, but it didn't"
|
50
61
|
end
|
51
62
|
def failure_message_for_should_not
|
52
|
-
"Expected no smells, but got:\n#{
|
63
|
+
"Expected no smells, but got:\n#{report}"
|
53
64
|
end
|
54
65
|
end
|
55
66
|
|
56
|
-
#
|
57
|
-
# Returns +true+ if and only if the target source code contains smells.
|
58
|
-
#
|
59
|
-
def reek
|
60
|
-
ShouldReek.new
|
61
|
-
end
|
62
|
-
|
63
67
|
class ShouldReekOf # :nodoc:
|
68
|
+
include ReekMatcher
|
69
|
+
|
64
70
|
def initialize(klass, patterns)
|
65
71
|
@klass = klass
|
66
72
|
@patterns = patterns
|
67
73
|
end
|
68
74
|
def matches?(actual)
|
69
|
-
@
|
70
|
-
@
|
75
|
+
@sniffer = actual.sniff
|
76
|
+
@sniffer.has_smell?(@klass, @patterns)
|
71
77
|
end
|
72
78
|
def failure_message_for_should
|
73
|
-
"Expected #{@
|
79
|
+
"Expected #{@sniffer.desc} to reek of #{@klass}, but it didn't"
|
74
80
|
end
|
75
81
|
def failure_message_for_should_not
|
76
|
-
"Expected #{@
|
82
|
+
"Expected #{@sniffer.desc} not to reek of #{@klass}, but got:\n#{report}"
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
80
|
-
#
|
81
|
-
|
82
|
-
# and returns +true+ only if one of them has a report string matching
|
83
|
-
# all of the +patterns+.
|
84
|
-
#
|
85
|
-
def reek_of(smell_class, *patterns)
|
86
|
-
ShouldReekOf.new(smell_class, patterns)
|
87
|
-
end
|
86
|
+
class ShouldReekOnlyOf < ShouldReekOf # :nodoc:
|
87
|
+
include ReekMatcher
|
88
88
|
|
89
|
-
class ShouldReekOnlyOf # :nodoc:
|
90
|
-
def initialize(klass, patterns)
|
91
|
-
@klass = klass
|
92
|
-
@patterns = patterns
|
93
|
-
end
|
94
89
|
def matches?(actual)
|
95
|
-
@
|
96
|
-
@
|
90
|
+
@sniffer = actual.sniff
|
91
|
+
@sniffer.smells_only_of?(@klass, @patterns)
|
97
92
|
end
|
98
93
|
def failure_message_for_should
|
99
|
-
"Expected
|
94
|
+
"Expected #{@sniffer.desc} to reek only of #{@klass}, but got:\n#{report}"
|
100
95
|
end
|
101
96
|
def failure_message_for_should_not
|
102
|
-
"Expected
|
97
|
+
"Expected #{@sniffer.desc} not to reek only of #{@klass}, but it did"
|
103
98
|
end
|
104
99
|
end
|
105
100
|
|
101
|
+
#
|
102
|
+
# Returns +true+ if and only if the target source code contains smells.
|
103
|
+
#
|
104
|
+
def reek
|
105
|
+
ShouldReek.new
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Checks the target source code for instances of +smell_class+,
|
110
|
+
# and returns +true+ only if one of them has a report string matching
|
111
|
+
# all of the +patterns+.
|
112
|
+
#
|
113
|
+
def reek_of(smell_class, *patterns)
|
114
|
+
ShouldReekOf.new(smell_class, patterns)
|
115
|
+
end
|
116
|
+
|
106
117
|
#
|
107
118
|
# As for reek_of, but the matched smell warning must be the only warning of
|
108
119
|
# any kind in the target source code's Reek report.
|
@@ -113,32 +124,6 @@ module Reek
|
|
113
124
|
end
|
114
125
|
end
|
115
126
|
|
116
|
-
class File
|
117
|
-
def to_source
|
118
|
-
Reek::Source.from_f(self)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
class String
|
123
|
-
def to_source
|
124
|
-
Reek::Source.from_s(self)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
class Array
|
129
|
-
def to_source
|
130
|
-
Reek::Source.from_pathlist(self)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
module Reek
|
135
|
-
class Source
|
136
|
-
def to_source
|
137
|
-
self
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
127
|
if Object.const_defined?(:Spec)
|
143
128
|
Spec::Runner.configure do |config|
|
144
129
|
config.include(Reek::Spec)
|