reek 1.2.6 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. data/.yardopts +10 -0
  2. data/History.txt +20 -0
  3. data/README.md +90 -0
  4. data/bin/reek +2 -2
  5. data/config/defaults.reek +34 -4
  6. data/features/masking_smells.feature +35 -15
  7. data/features/options.feature +2 -0
  8. data/features/rake_task.feature +11 -18
  9. data/features/reports.feature +13 -15
  10. data/features/samples.feature +90 -105
  11. data/features/stdin.feature +3 -6
  12. data/features/step_definitions/reek_steps.rb +8 -4
  13. data/features/support/env.rb +2 -3
  14. data/features/yaml.feature +124 -0
  15. data/lib/reek.rb +8 -4
  16. data/lib/reek/cli/application.rb +46 -0
  17. data/lib/reek/cli/command_line.rb +106 -0
  18. data/lib/reek/cli/help_command.rb +18 -0
  19. data/lib/reek/cli/reek_command.rb +37 -0
  20. data/lib/reek/cli/report.rb +91 -0
  21. data/lib/reek/cli/version_command.rb +19 -0
  22. data/lib/reek/cli/yaml_command.rb +32 -0
  23. data/lib/reek/core/block_context.rb +18 -0
  24. data/lib/reek/core/class_context.rb +23 -0
  25. data/lib/reek/core/code_context.rb +72 -0
  26. data/lib/reek/core/code_parser.rb +192 -0
  27. data/lib/reek/core/detector_stack.rb +29 -0
  28. data/lib/reek/core/masking_collection.rb +46 -0
  29. data/lib/reek/core/method_context.rb +132 -0
  30. data/lib/reek/core/module_context.rb +64 -0
  31. data/lib/reek/{object_refs.rb → core/object_refs.rb} +8 -6
  32. data/lib/reek/{singleton_method_context.rb → core/singleton_method_context.rb} +10 -5
  33. data/lib/reek/core/smell_configuration.rb +66 -0
  34. data/lib/reek/core/sniffer.rb +110 -0
  35. data/lib/reek/core/stop_context.rb +26 -0
  36. data/lib/reek/examiner.rb +88 -0
  37. data/lib/reek/rake/task.rb +124 -0
  38. data/lib/reek/smell_warning.rb +69 -13
  39. data/lib/reek/smells.rb +29 -0
  40. data/lib/reek/smells/attribute.rb +13 -14
  41. data/lib/reek/smells/boolean_parameter.rb +33 -0
  42. data/lib/reek/smells/class_variable.rb +8 -6
  43. data/lib/reek/smells/control_couple.rb +33 -17
  44. data/lib/reek/smells/data_clump.rb +10 -6
  45. data/lib/reek/smells/duplication.rb +24 -14
  46. data/lib/reek/smells/feature_envy.rb +11 -6
  47. data/lib/reek/smells/irresponsible_module.rb +28 -0
  48. data/lib/reek/smells/large_class.rb +9 -7
  49. data/lib/reek/smells/long_method.rb +6 -5
  50. data/lib/reek/smells/long_parameter_list.rb +11 -9
  51. data/lib/reek/smells/long_yield_list.rb +37 -7
  52. data/lib/reek/smells/nested_iterators.rb +34 -9
  53. data/lib/reek/smells/simulated_polymorphism.rb +15 -11
  54. data/lib/reek/smells/smell_detector.rb +24 -12
  55. data/lib/reek/smells/uncommunicative_method_name.rb +76 -0
  56. data/lib/reek/smells/uncommunicative_module_name.rb +76 -0
  57. data/lib/reek/smells/{uncommunicative_name.rb → uncommunicative_parameter_name.rb} +14 -26
  58. data/lib/reek/smells/uncommunicative_variable_name.rb +90 -0
  59. data/lib/reek/smells/utility_function.rb +33 -9
  60. data/lib/reek/source.rb +18 -0
  61. data/lib/reek/source/code_comment.rb +19 -0
  62. data/lib/reek/source/config_file.rb +72 -0
  63. data/lib/reek/source/core_extras.rb +46 -0
  64. data/lib/reek/source/sexp_formatter.rb +16 -0
  65. data/lib/reek/source/source_code.rb +44 -0
  66. data/lib/reek/source/source_file.rb +32 -0
  67. data/lib/reek/source/source_locator.rb +36 -0
  68. data/lib/reek/source/tree_dresser.rb +128 -0
  69. data/lib/reek/spec.rb +51 -0
  70. data/lib/reek/spec/should_reek.rb +34 -0
  71. data/lib/reek/spec/should_reek_of.rb +37 -0
  72. data/lib/reek/spec/should_reek_only_of.rb +36 -0
  73. data/reek.gemspec +5 -5
  74. data/spec/reek/{help_command_spec.rb → cli/help_command_spec.rb} +3 -4
  75. data/spec/reek/{reek_command_spec.rb → cli/reek_command_spec.rb} +8 -7
  76. data/spec/reek/cli/report_spec.rb +26 -0
  77. data/spec/reek/{version_command_spec.rb → cli/version_command_spec.rb} +3 -3
  78. data/spec/reek/cli/yaml_command_spec.rb +47 -0
  79. data/spec/reek/core/block_context_spec.rb +26 -0
  80. data/spec/reek/core/class_context_spec.rb +53 -0
  81. data/spec/reek/{code_context_spec.rb → core/code_context_spec.rb} +15 -37
  82. data/spec/reek/{code_parser_spec.rb → core/code_parser_spec.rb} +5 -5
  83. data/spec/reek/{config_spec.rb → core/config_spec.rb} +2 -6
  84. data/spec/reek/{masking_collection_spec.rb → core/masking_collection_spec.rb} +3 -4
  85. data/spec/reek/{method_context_spec.rb → core/method_context_spec.rb} +6 -7
  86. data/spec/reek/core/module_context_spec.rb +42 -0
  87. data/spec/reek/{object_refs_spec.rb → core/object_refs_spec.rb} +5 -6
  88. data/spec/reek/core/singleton_method_context_spec.rb +15 -0
  89. data/spec/reek/core/smell_configuration_spec.rb +11 -0
  90. data/spec/reek/core/stop_context_spec.rb +17 -0
  91. data/spec/reek/examiner_spec.rb +42 -0
  92. data/spec/reek/smell_warning_spec.rb +82 -33
  93. data/spec/reek/smells/attribute_spec.rb +33 -7
  94. data/spec/reek/smells/boolean_parameter_spec.rb +76 -0
  95. data/spec/reek/smells/class_variable_spec.rb +15 -6
  96. data/spec/reek/smells/control_couple_spec.rb +40 -29
  97. data/spec/reek/smells/data_clump_spec.rb +28 -7
  98. data/spec/reek/smells/duplication_spec.rb +47 -41
  99. data/spec/reek/smells/feature_envy_spec.rb +76 -18
  100. data/spec/reek/smells/irresponsible_module_spec.rb +37 -0
  101. data/spec/reek/smells/large_class_spec.rb +91 -56
  102. data/spec/reek/smells/long_method_spec.rb +32 -7
  103. data/spec/reek/smells/long_parameter_list_spec.rb +42 -13
  104. data/spec/reek/smells/long_yield_list_spec.rb +65 -0
  105. data/spec/reek/smells/nested_iterators_spec.rb +94 -3
  106. data/spec/reek/smells/simulated_polymorphism_spec.rb +48 -20
  107. data/spec/reek/smells/smell_detector_shared.rb +28 -0
  108. data/spec/reek/smells/uncommunicative_method_name_spec.rb +57 -0
  109. data/spec/reek/smells/uncommunicative_module_name_spec.rb +67 -0
  110. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +61 -0
  111. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +124 -0
  112. data/spec/reek/smells/utility_function_spec.rb +45 -3
  113. data/spec/reek/source/code_comment_spec.rb +24 -0
  114. data/spec/reek/source/object_source_spec.rb +20 -0
  115. data/spec/reek/{adapters/source_spec.rb → source/source_code_spec.rb} +7 -8
  116. data/spec/reek/source/tree_dresser_spec.rb +165 -0
  117. data/spec/reek/spec/should_reek_of_spec.rb +76 -0
  118. data/spec/reek/spec/should_reek_only_of_spec.rb +89 -0
  119. data/spec/reek/{adapters → spec}/should_reek_spec.rb +8 -32
  120. data/spec/samples/all_but_one_masked/clean_one.rb +1 -0
  121. data/spec/samples/all_but_one_masked/dirty.rb +1 -0
  122. data/spec/samples/all_but_one_masked/masked.reek +5 -1
  123. data/spec/samples/clean_due_to_masking/clean_one.rb +1 -0
  124. data/spec/samples/clean_due_to_masking/clean_three.rb +1 -0
  125. data/spec/samples/clean_due_to_masking/clean_two.rb +1 -0
  126. data/spec/samples/clean_due_to_masking/dirty_one.rb +1 -1
  127. data/spec/samples/clean_due_to_masking/dirty_two.rb +1 -1
  128. data/spec/samples/clean_due_to_masking/masked.reek +5 -1
  129. data/spec/samples/corrupt_config_file/dirty.rb +1 -1
  130. data/spec/samples/empty_config_file/dirty.rb +2 -1
  131. data/spec/samples/exceptions.reek +1 -1
  132. data/spec/samples/masked/dirty.rb +2 -1
  133. data/spec/samples/masked/masked.reek +3 -1
  134. data/spec/samples/mixed_results/clean_one.rb +1 -0
  135. data/spec/samples/mixed_results/clean_three.rb +1 -0
  136. data/spec/samples/mixed_results/clean_two.rb +1 -0
  137. data/spec/samples/mixed_results/dirty_one.rb +1 -0
  138. data/spec/samples/mixed_results/dirty_two.rb +1 -0
  139. data/spec/samples/not_quite_masked/dirty.rb +2 -1
  140. data/spec/samples/not_quite_masked/masked.reek +1 -1
  141. data/spec/samples/overrides/masked/dirty.rb +2 -1
  142. data/spec/samples/overrides/masked/lower.reek +3 -1
  143. data/spec/samples/three_clean_files/clean_one.rb +1 -0
  144. data/spec/samples/three_clean_files/clean_three.rb +1 -0
  145. data/spec/samples/three_clean_files/clean_two.rb +1 -0
  146. data/spec/samples/two_smelly_files/dirty_one.rb +2 -1
  147. data/spec/samples/two_smelly_files/dirty_two.rb +2 -1
  148. data/spec/spec_helper.rb +1 -2
  149. data/tasks/reek.rake +2 -2
  150. data/tasks/test.rake +12 -3
  151. metadata +81 -62
  152. data/README.rdoc +0 -84
  153. data/lib/reek/adapters/application.rb +0 -46
  154. data/lib/reek/adapters/command_line.rb +0 -77
  155. data/lib/reek/adapters/config_file.rb +0 -31
  156. data/lib/reek/adapters/core_extras.rb +0 -64
  157. data/lib/reek/adapters/rake_task.rb +0 -121
  158. data/lib/reek/adapters/report.rb +0 -86
  159. data/lib/reek/adapters/source.rb +0 -72
  160. data/lib/reek/adapters/spec.rb +0 -133
  161. data/lib/reek/block_context.rb +0 -62
  162. data/lib/reek/class_context.rb +0 -41
  163. data/lib/reek/code_context.rb +0 -68
  164. data/lib/reek/code_parser.rb +0 -203
  165. data/lib/reek/configuration.rb +0 -57
  166. data/lib/reek/detector_stack.rb +0 -37
  167. data/lib/reek/help_command.rb +0 -14
  168. data/lib/reek/if_context.rb +0 -18
  169. data/lib/reek/masking_collection.rb +0 -33
  170. data/lib/reek/method_context.rb +0 -138
  171. data/lib/reek/module_context.rb +0 -49
  172. data/lib/reek/name.rb +0 -57
  173. data/lib/reek/reek_command.rb +0 -28
  174. data/lib/reek/sexp_formatter.rb +0 -10
  175. data/lib/reek/sniffer.rb +0 -177
  176. data/lib/reek/stop_context.rb +0 -35
  177. data/lib/reek/tree_dresser.rb +0 -82
  178. data/lib/reek/version_command.rb +0 -14
  179. data/lib/reek/yield_call_context.rb +0 -12
  180. data/spec/reek/adapters/report_spec.rb +0 -31
  181. data/spec/reek/adapters/should_reek_of_spec.rb +0 -138
  182. data/spec/reek/adapters/should_reek_only_of_spec.rb +0 -87
  183. data/spec/reek/block_context_spec.rb +0 -65
  184. data/spec/reek/class_context_spec.rb +0 -161
  185. data/spec/reek/configuration_spec.rb +0 -12
  186. data/spec/reek/if_context_spec.rb +0 -17
  187. data/spec/reek/module_context_spec.rb +0 -46
  188. data/spec/reek/name_spec.rb +0 -37
  189. data/spec/reek/object_source_spec.rb +0 -23
  190. data/spec/reek/singleton_method_context_spec.rb +0 -16
  191. data/spec/reek/smells/smell_detector_spec.rb +0 -36
  192. data/spec/reek/smells/uncommunicative_name_spec.rb +0 -146
  193. data/spec/reek/sniffer_spec.rb +0 -11
  194. data/spec/reek/stop_context_spec.rb +0 -33
  195. data/spec/reek/tree_dresser_spec.rb +0 -20
@@ -0,0 +1,16 @@
1
+ require 'ruby2ruby'
2
+
3
+ module Reek
4
+ module Source
5
+
6
+ #
7
+ # Formats snippets of syntax tree back into Ruby source code.
8
+ #
9
+ class SexpFormatter
10
+ def self.format(sexp)
11
+ sexp = YAML::load(YAML::dump(sexp))
12
+ Ruby2Ruby.new.process(sexp)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ require 'ruby_parser'
2
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'config_file')
3
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'tree_dresser')
4
+
5
+ module Reek
6
+ module Source
7
+
8
+ #
9
+ # A +Source+ object represents a chunk of Ruby source code.
10
+ #
11
+ class SourceCode
12
+
13
+ @@err_io = $stderr
14
+
15
+ class << self
16
+ def err_io=(io)
17
+ original = @@err_io
18
+ @@err_io = io
19
+ original
20
+ end
21
+ end
22
+
23
+ attr_reader :desc
24
+
25
+ def initialize(code, desc, parser = RubyParser.new)
26
+ @source = code
27
+ @desc = desc
28
+ @parser = parser
29
+ end
30
+
31
+ def configure(sniffer) end
32
+
33
+ def syntax_tree
34
+ begin
35
+ ast = @parser.parse(@source, @desc)
36
+ rescue Exception => error
37
+ @@err_io.puts "#{desc}: #{error.class.name}: #{error}"
38
+ end
39
+ ast ||= s()
40
+ TreeDresser.new.dress(ast)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'source_code')
2
+
3
+ module Reek
4
+ module Source
5
+
6
+ #
7
+ # Represents a file of Ruby source, whose contents will be examined
8
+ # for code smells.
9
+ #
10
+ class SourceFile < SourceCode
11
+
12
+ def initialize(path)
13
+ @path = path
14
+ super(IO.readlines(@path).join, @path)
15
+ end
16
+
17
+ def configure(sniffer)
18
+ path = File.expand_path(File.dirname(@path))
19
+ all_config_files(path).each { |cf| ConfigFile.new(cf).configure(sniffer) }
20
+ end
21
+
22
+ private
23
+
24
+ def all_config_files(path)
25
+ return [] unless File.exist?(path)
26
+ parent = File.dirname(path)
27
+ return [] if path == parent
28
+ all_config_files(parent) + Dir["#{path}/*.reek"]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'core_extras')
2
+
3
+ module Reek
4
+ module Source
5
+ class SourceLocator
6
+ def initialize(paths)
7
+ @paths = paths
8
+ end
9
+
10
+ def all_sources
11
+ valid_paths.map {|path| File.new(path).to_reek_source }
12
+ end
13
+
14
+ def all_ruby_source_files(paths)
15
+ paths.map do |path|
16
+ if test 'd', path
17
+ all_ruby_source_files(Dir["#{path}/**/*.rb"])
18
+ else
19
+ path
20
+ end
21
+ end.flatten.sort
22
+ end
23
+
24
+ def valid_paths
25
+ all_ruby_source_files(@paths).select do |path|
26
+ if test 'f', path
27
+ true
28
+ else
29
+ $stderr.puts "Error: No such file - #{path}"
30
+ false
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,128 @@
1
+ module Reek
2
+ module Source
3
+
4
+ #
5
+ # Extensions to +Sexp+ to allow +CodeParser+ to navigate the abstract
6
+ # syntax tree more easily.
7
+ #
8
+ module SexpNode
9
+ def is_language_node?
10
+ first.class == Symbol
11
+ end
12
+
13
+ def has_type?(type)
14
+ is_language_node? and first == type
15
+ end
16
+
17
+ #
18
+ # Carries out a depth-first traversal of this syntax tree, yielding
19
+ # every Sexp of type +target_type+. The traversal ignores any node
20
+ # whose type is listed in the Array +ignoring+.
21
+ #
22
+ def look_for(target_type, ignoring, &blk)
23
+ each do |elem|
24
+ if Sexp === elem then
25
+ elem.look_for(target_type, ignoring, &blk) unless ignoring.include?(elem.first)
26
+ end
27
+ end
28
+ blk.call(self) if first == target_type
29
+ end
30
+ end
31
+
32
+ module SexpExtensions
33
+ module CaseNode
34
+ def condition
35
+ self[1]
36
+ end
37
+ end
38
+
39
+ module CallNode
40
+ def receiver() self[1] end
41
+ def method_name() self[2] end
42
+ def args() self[3] end
43
+ def arg_names
44
+ args[1..-1].map {|arg| arg[1]}
45
+ end
46
+ end
47
+
48
+ module CvarNode
49
+ def name() self[1] end
50
+ end
51
+
52
+ CvasgnNode = CvarNode
53
+ CvdeclNode = CvarNode
54
+
55
+ module DefnNode
56
+ def method_name() self[1] end
57
+ def parameters()
58
+ self[2].reject {|param| Sexp === param}
59
+ end
60
+ def parameter_names
61
+ parameters[1..-1]
62
+ end
63
+ end
64
+
65
+ module DefsNode
66
+ def method_name() self[2] end
67
+ def parameters
68
+ self[3].reject {|param| Sexp === param}
69
+ end
70
+ def parameter_names
71
+ parameters[1..-1]
72
+ end
73
+ end
74
+
75
+ module IfNode
76
+ def condition
77
+ self[1]
78
+ end
79
+ end
80
+
81
+ module IterNode
82
+ def call() self[1] end
83
+ def args() self[2] end
84
+ def block() self[3] end
85
+ def parameters() self[2] || [] end
86
+ def parameter_names
87
+ result = parameters
88
+ return case result[0]
89
+ when :lasgn
90
+ [result[1]]
91
+ when :masgn
92
+ result[1][1..-1].map {|lasgn| lasgn[1]}
93
+ else
94
+ []
95
+ end
96
+ end
97
+ end
98
+
99
+ module YieldNode
100
+ def args() self[1..-1] end
101
+ def arg_names
102
+ args.map {|arg| arg[1]}
103
+ end
104
+ end
105
+ end
106
+
107
+ #
108
+ # Adorns an abstract syntax tree with mix-in modules to make accessing
109
+ # the tree more understandable and less implementation-dependent.
110
+ #
111
+ class TreeDresser
112
+
113
+ def dress(sexp)
114
+ sexp.extend(SexpNode)
115
+ module_name = extensions_for(sexp.sexp_type)
116
+ if SexpExtensions.const_defined?(module_name)
117
+ sexp.extend(SexpExtensions.const_get(module_name))
118
+ end
119
+ sexp[0..-1].each { |sub| dress(sub) if Array === sub }
120
+ sexp
121
+ end
122
+
123
+ def extensions_for(node_type)
124
+ "#{node_type.to_s.capitalize}Node"
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,51 @@
1
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec', 'should_reek')
2
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec', 'should_reek_of')
3
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec', 'should_reek_only_of')
4
+
5
+ module Reek
6
+
7
+ #
8
+ # Provides matchers for Rspec, making it easy to check code quality.
9
+ #
10
+ # If you require this module somewhere within your spec (or in your spec_helper),
11
+ # Reek will arrange to update Spec::Runner's config so that it knows about the
12
+ # matchers defined here.
13
+ #
14
+ # === Examples
15
+ #
16
+ # Here's a spec that ensures there are no active code smells in the current project:
17
+ #
18
+ # describe 'source code quality' do
19
+ # Dir['lib/**/*.rb'].each do |path|
20
+ # it "reports no smells in #{path}" do
21
+ # File.new(path).should_not reek
22
+ # end
23
+ # end
24
+ # end
25
+ #
26
+ # And here's an even simpler way to do the same:
27
+ #
28
+ # it 'has no code smells' do
29
+ # Dir['lib/**/*.rb'].should_not reek
30
+ # end
31
+ #
32
+ # Here's a simple check of a code fragment:
33
+ #
34
+ # 'def equals(other) other.thing == self.thing end'.should_not reek
35
+ #
36
+ # To check for specific smells, use something like this:
37
+ #
38
+ # ruby = 'def double_thing() @other.thing.foo + @other.thing.foo end'
39
+ # ruby.should reek_of(:Duplication, /@other.thing[^\.]/)
40
+ # ruby.should reek_of(:Duplication, /@other.thing.foo/)
41
+ # ruby.should_not reek_of(:FeatureEnvy)
42
+ #
43
+ module Spec
44
+ end
45
+ end
46
+
47
+ if Object.const_defined?(:Spec)
48
+ Spec::Runner.configure do |config|
49
+ config.include(Reek::Spec)
50
+ end
51
+ end
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'examiner')
2
+
3
+ module Reek
4
+ module Spec
5
+
6
+ #
7
+ # An rspec matcher that matches when the +actual+ has code smells.
8
+ #
9
+ class ShouldReek # :nodoc:
10
+ def matches?(actual)
11
+ @examiner = Examiner.new(actual)
12
+ @examiner.smelly?
13
+ end
14
+ def failure_message_for_should
15
+ "Expected #{@examiner.description} to reek, but it didn't"
16
+ end
17
+ def failure_message_for_should_not
18
+ "Expected no smells, but got:\n#{list_smells(@examiner)}"
19
+ end
20
+ def list_smells(examiner)
21
+ examiner.all_active_smells.map do |smell|
22
+ "#{smell.report('%c %w (%s)')}"
23
+ end.join("\n")
24
+ end
25
+ end
26
+
27
+ #
28
+ # Returns +true+ if and only if the target source code contains smells.
29
+ #
30
+ def reek
31
+ ShouldReek.new
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'examiner')
2
+
3
+ module Reek
4
+ module Spec
5
+
6
+ #
7
+ # An rspec matcher that matches when the +actual+ has the specified
8
+ # code smell.
9
+ #
10
+ class ShouldReekOf # :nodoc:
11
+ def initialize(klass, patterns)
12
+ @klass = klass
13
+ @patterns = patterns
14
+ end
15
+ def matches?(actual)
16
+ @examiner = Examiner.new(actual)
17
+ @all_smells = @examiner.all_active_smells
18
+ @all_smells.any? {|warning| warning.matches?(@klass, @patterns)}
19
+ end
20
+ def failure_message_for_should
21
+ "Expected #{@examiner.description} to reek of #{@klass}, but it didn't"
22
+ end
23
+ def failure_message_for_should_not
24
+ "Expected #{@examiner.description} not to reek of #{@klass}, but it did"
25
+ end
26
+ end
27
+
28
+ #
29
+ # Checks the target source code for instances of +smell_class+,
30
+ # and returns +true+ only if one of them has a report string matching
31
+ # all of the +patterns+.
32
+ #
33
+ def reek_of(smell_class, *patterns)
34
+ ShouldReekOf.new(smell_class, patterns)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'examiner')
2
+
3
+ module Reek
4
+ module Spec
5
+
6
+ #
7
+ # An rspec matcher that matches when the +actual+ has the specified
8
+ # code smell and no others.
9
+ #
10
+ class ShouldReekOnlyOf < ShouldReekOf # :nodoc:
11
+ def matches?(actual)
12
+ matches_examiner?(Examiner.new(actual))
13
+ end
14
+ def matches_examiner?(examiner)
15
+ @examiner = examiner
16
+ @all_smells = @examiner.all_active_smells
17
+ @all_smells.length == 1 and @all_smells[0].matches?(@klass, @patterns)
18
+ end
19
+ def failure_message_for_should
20
+ rpt = @all_smells.map { |smell| "#{smell.report('%c %w (%s)')}" }.join("\n")
21
+ "Expected #{@examiner.description} to reek only of #{@klass}, but got:\n#{rpt}"
22
+ end
23
+ def failure_message_for_should_not
24
+ "Expected #{@examiner.description} not to reek only of #{@klass}, but it did"
25
+ end
26
+ end
27
+
28
+ #
29
+ # As for reek_of, but the matched smell warning must be the only warning of
30
+ # any kind in the target source code's Reek report.
31
+ #
32
+ def reek_only_of(smell_class, *patterns)
33
+ ShouldReekOnlyOf.new(smell_class, patterns)
34
+ end
35
+ end
36
+ end
@@ -2,24 +2,24 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reek}
5
- s.version = "1.2.6"
5
+ s.version = "1.2.7"
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-28}
9
+ s.date = %q{2010-02-01}
10
10
  s.default_executable = %q{reek}
11
11
  s.description = %q{Reek is a tool that examines Ruby classes, modules and methods
12
12
  and reports any code smells it finds.
13
13
  }
14
14
  s.email = ["kevin@rutherford-software.com"]
15
15
  s.executables = ["reek"]
16
- s.extra_rdoc_files = ["History.txt", "License.txt", "README.rdoc"]
17
- 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
+ s.extra_rdoc_files = ["History.txt", "License.txt"]
17
+ s.files = [".yardopts", "History.txt", "License.txt", "README.md", "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", "features/yaml.feature", "lib/reek.rb", "lib/reek/cli/application.rb", "lib/reek/cli/command_line.rb", "lib/reek/cli/help_command.rb", "lib/reek/cli/reek_command.rb", "lib/reek/cli/report.rb", "lib/reek/cli/version_command.rb", "lib/reek/cli/yaml_command.rb", "lib/reek/core/block_context.rb", "lib/reek/core/class_context.rb", "lib/reek/core/code_context.rb", "lib/reek/core/code_parser.rb", "lib/reek/core/detector_stack.rb", "lib/reek/core/masking_collection.rb", "lib/reek/core/method_context.rb", "lib/reek/core/module_context.rb", "lib/reek/core/object_refs.rb", "lib/reek/core/singleton_method_context.rb", "lib/reek/core/smell_configuration.rb", "lib/reek/core/sniffer.rb", "lib/reek/core/stop_context.rb", "lib/reek/examiner.rb", "lib/reek/rake/task.rb", "lib/reek/smell_warning.rb", "lib/reek/smells.rb", "lib/reek/smells/attribute.rb", "lib/reek/smells/boolean_parameter.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/irresponsible_module.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_method_name.rb", "lib/reek/smells/uncommunicative_module_name.rb", "lib/reek/smells/uncommunicative_parameter_name.rb", "lib/reek/smells/uncommunicative_variable_name.rb", "lib/reek/smells/utility_function.rb", "lib/reek/source.rb", "lib/reek/source/code_comment.rb", "lib/reek/source/config_file.rb", "lib/reek/source/core_extras.rb", "lib/reek/source/sexp_formatter.rb", "lib/reek/source/source_code.rb", "lib/reek/source/source_file.rb", "lib/reek/source/source_locator.rb", "lib/reek/source/tree_dresser.rb", "lib/reek/spec.rb", "lib/reek/spec/should_reek.rb", "lib/reek/spec/should_reek_of.rb", "lib/reek/spec/should_reek_only_of.rb", "reek.gemspec", "spec/reek/cli/help_command_spec.rb", "spec/reek/cli/reek_command_spec.rb", "spec/reek/cli/report_spec.rb", "spec/reek/cli/version_command_spec.rb", "spec/reek/cli/yaml_command_spec.rb", "spec/reek/core/block_context_spec.rb", "spec/reek/core/class_context_spec.rb", "spec/reek/core/code_context_spec.rb", "spec/reek/core/code_parser_spec.rb", "spec/reek/core/config_spec.rb", "spec/reek/core/masking_collection_spec.rb", "spec/reek/core/method_context_spec.rb", "spec/reek/core/module_context_spec.rb", "spec/reek/core/object_refs_spec.rb", "spec/reek/core/singleton_method_context_spec.rb", "spec/reek/core/smell_configuration_spec.rb", "spec/reek/core/stop_context_spec.rb", "spec/reek/examiner_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/boolean_parameter_spec.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/irresponsible_module_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/long_yield_list_spec.rb", "spec/reek/smells/nested_iterators_spec.rb", "spec/reek/smells/simulated_polymorphism_spec.rb", "spec/reek/smells/smell_detector_shared.rb", "spec/reek/smells/uncommunicative_method_name_spec.rb", "spec/reek/smells/uncommunicative_module_name_spec.rb", "spec/reek/smells/uncommunicative_parameter_name_spec.rb", "spec/reek/smells/uncommunicative_variable_name_spec.rb", "spec/reek/smells/utility_function_spec.rb", "spec/reek/source/code_comment_spec.rb", "spec/reek/source/object_source_spec.rb", "spec/reek/source/source_code_spec.rb", "spec/reek/source/tree_dresser_spec.rb", "spec/reek/spec/should_reek_of_spec.rb", "spec/reek/spec/should_reek_only_of_spec.rb", "spec/reek/spec/should_reek_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"]
18
18
  s.homepage = %q{http://wiki.github.com/kevinrutherford/reek}
19
19
  s.post_install_message = %q{
20
20
  For more information on reek, see http://wiki.github.com/kevinrutherford/reek
21
21
  }
22
- s.rdoc_options = ["--main", "README.rdoc"]
22
+ s.rdoc_options = ["--main", "README.md"]
23
23
  s.require_paths = ["lib"]
24
24
  s.rubyforge_project = %q{reek}
25
25
  s.rubygems_version = %q{1.3.5}