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,15 @@
1
+ require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
+ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'module_context')
3
+ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'singleton_method_context')
4
+ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'stop_context')
5
+
6
+ include Reek::Core
7
+
8
+ describe SingletonMethodContext do
9
+ it "reports full context" do
10
+ element = StopContext.new
11
+ element = ModuleContext.new(element, 'mod', s(:module, :mod, nil))
12
+ element = SingletonMethodContext.new(element, s(:defs, s(:call, nil, :a, s(:arglist)), :b, s(:args)))
13
+ element.full_name.should match(/mod#a\.b/)
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
+ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'smell_configuration')
3
+
4
+ include Reek::Core
5
+
6
+ describe SmellConfiguration do
7
+ it 'returns the default value when key not found' do
8
+ cf = SmellConfiguration.new({})
9
+ cf.value('fred', nil, 27).should == 27
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
+ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'stop_context')
3
+
4
+ include Reek
5
+ include Reek::Core
6
+
7
+ describe StopContext do
8
+ before :each do
9
+ @stop = StopContext.new
10
+ end
11
+
12
+ context 'full_name' do
13
+ it "reports full context" do
14
+ @stop.full_name.should == ''
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,42 @@
1
+ require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'spec_helper')
2
+ require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'lib', 'reek', 'examiner')
3
+
4
+ include Reek
5
+
6
+ describe Examiner do
7
+ it 'detects smells in a file' do
8
+ dirty_file = Dir['spec/samples/two_smelly_files/*.rb'][0]
9
+ Examiner.new(File.new(dirty_file)).should be_smelly
10
+ end
11
+ it 'doesnt match a fragrant String' do
12
+ examiner = Examiner.new('def good() true; end')
13
+ examiner.all_active_smells.should == []
14
+ end
15
+ it 'matches a smelly String' do
16
+ Examiner.new('def fine() y = 4; end').all_active_smells.length.should == 1
17
+ end
18
+
19
+ context 'checking code in a Dir' do
20
+ it 'matches a smelly Dir' do
21
+ smelly_dir = Dir['spec/samples/all_but_one_masked/*.rb']
22
+ Examiner.new(smelly_dir).all_active_smells.length.should == 1
23
+ end
24
+ it 'doesnt match a fragrant Dir' do
25
+ clean_dir = Dir['spec/samples/three_clean_files/*.rb']
26
+ Examiner.new(clean_dir).all_active_smells.length.should == 0
27
+ end
28
+ end
29
+
30
+ context 'checking code in a File' do
31
+ it 'matches a smelly File' do
32
+ smelly_file = File.new(Dir['spec/samples/all_but_one_masked/d*.rb'][0])
33
+ Examiner.new(smelly_file).all_active_smells.length.should == 1
34
+ end
35
+
36
+ it 'doesnt match a fragrant File' do
37
+ clean_file = File.new(Dir['spec/samples/three_clean_files/*.rb'][0])
38
+ Examiner.new(clean_file).all_active_smells.length.should == 0
39
+ end
40
+ end
41
+
42
+ end
@@ -1,7 +1,5 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
-
3
- require 'reek/smell_warning'
4
- require 'reek/smells/feature_envy'
1
+ require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'spec_helper')
2
+ require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'lib', 'reek', 'smell_warning')
5
3
 
6
4
  include Reek
7
5
 
@@ -9,8 +7,8 @@ describe SmellWarning do
9
7
  context 'sort order' do
10
8
  context 'smells differing only by masking' do
11
9
  before :each do
12
- @first = SmellWarning.new(Smells::FeatureEnvy.new, "self", 27, "self", true)
13
- @second = SmellWarning.new(Smells::FeatureEnvy.new, "self", 27, "self", false)
10
+ @first = SmellWarning.new('FeatureEnvy', "self", 27, "self", true)
11
+ @second = SmellWarning.new('FeatureEnvy', "self", 27, "self", false)
14
12
  end
15
13
 
16
14
  it 'should hash equal when the smell is the same' do
@@ -46,8 +44,8 @@ describe SmellWarning do
46
44
 
47
45
  context 'smells differing only by detector' do
48
46
  before :each do
49
- @first = SmellWarning.new(Smells::Duplication.new, "self", 27, "self", false)
50
- @second = SmellWarning.new(Smells::FeatureEnvy.new, "self", 27, "self", true)
47
+ @first = SmellWarning.new('Duplication', "self", 27, "self", false)
48
+ @second = SmellWarning.new('FeatureEnvy', "self", 27, "self", true)
51
49
  end
52
50
 
53
51
  it_should_behave_like 'first sorts ahead of second'
@@ -55,8 +53,8 @@ describe SmellWarning do
55
53
 
56
54
  context 'smells differing only by context' do
57
55
  before :each do
58
- @first = SmellWarning.new(Smells::FeatureEnvy.new, "first", 27, "self", true)
59
- @second = SmellWarning.new(Smells::FeatureEnvy.new, "second", 27, "self", false)
56
+ @first = SmellWarning.new('FeatureEnvy', "first", 27, "self", true)
57
+ @second = SmellWarning.new('FeatureEnvy', "second", 27, "self", false)
60
58
  end
61
59
 
62
60
  it_should_behave_like 'first sorts ahead of second'
@@ -64,8 +62,8 @@ describe SmellWarning do
64
62
 
65
63
  context 'smells differing only by message' do
66
64
  before :each do
67
- @first = SmellWarning.new(Smells::FeatureEnvy.new, "context", 27, "first", true)
68
- @second = SmellWarning.new(Smells::FeatureEnvy.new, "context", 27, "second", false)
65
+ @first = SmellWarning.new('FeatureEnvy', "context", 27, "first", true)
66
+ @second = SmellWarning.new('FeatureEnvy', "context", 27, "second", false)
69
67
  end
70
68
 
71
69
  it_should_behave_like 'first sorts ahead of second'
@@ -73,8 +71,8 @@ describe SmellWarning do
73
71
 
74
72
  context 'message takes precedence over smell name' do
75
73
  before :each do
76
- @first = SmellWarning.new(Smells::UtilityFunction.new, "context", 27, "first", true)
77
- @second = SmellWarning.new(Smells::FeatureEnvy.new, "context", 27, "second", false)
74
+ @first = SmellWarning.new('UtilityFunction', "context", 27, "first", true)
75
+ @second = SmellWarning.new('FeatureEnvy', "context", 27, "second", false)
78
76
  end
79
77
 
80
78
  it_should_behave_like 'first sorts ahead of second'
@@ -82,8 +80,8 @@ describe SmellWarning do
82
80
 
83
81
  context 'smells differing everywhere' do
84
82
  before :each do
85
- @first = SmellWarning.new(Smells::UncommunicativeName.new, "Dirty", 27, "has the variable name '@s'", true)
86
- @second = SmellWarning.new(Smells::Duplication.new, 'Dirty#a', 27, "calls @s.title twice", false)
83
+ @first = SmellWarning.new('UncommunicativeName', "Dirty", 27, "has the variable name '@s'", true)
84
+ @second = SmellWarning.new('Duplication', 'Dirty#a', 27, "calls @s.title twice", false)
87
85
  end
88
86
 
89
87
  it_should_behave_like 'first sorts ahead of second'
@@ -106,8 +104,8 @@ describe SmellWarning do
106
104
  end
107
105
 
108
106
  before :each do
109
- @masked = SmellWarning.new(Smells::FeatureEnvy.new, 'Fred', 27, "self", true)
110
- @visible = SmellWarning.new(Smells::FeatureEnvy.new, 'Fred', 27, "self", false)
107
+ @masked = SmellWarning.new('FeatureEnvy', 'Fred', 27, "self", true)
108
+ @visible = SmellWarning.new('FeatureEnvy', 'Fred', 27, "self", false)
111
109
  end
112
110
 
113
111
  it 'reports as masked when masked' do
@@ -127,25 +125,76 @@ describe SmellWarning do
127
125
 
128
126
  context 'YAML representation' do
129
127
  before :each do
130
- @message = 'message'
128
+ @message = 'test message'
129
+ @lines = [24, 513]
130
+ @class = 'FeatureEnvy'
131
+ @context_name = 'Module::Class#method/block'
132
+ @is_active = true
131
133
  # Use a random string and a random bool
132
- warning = SmellWarning.new(Smells::FeatureEnvy.new, 'Fred', 27, @message, true)
133
- @yaml = warning.to_yaml
134
- end
135
- it 'includes the smell class' do
136
- @yaml.should match(/smell:\s*FeatureEnvy/)
137
134
  end
138
- it 'includes the context' do
139
- @yaml.should match(/context:\s*Fred/)
140
- end
141
- it 'includes the message' do
142
- @yaml.should match(/message:\s*#{@message}/)
135
+
136
+ shared_examples_for 'common fields' do
137
+ it 'includes the smell class' do
138
+ @yaml.should match(/class:\s*FeatureEnvy/)
139
+ end
140
+ it 'includes the context' do
141
+ @yaml.should match(/context:\s*#{@context_name}/)
142
+ end
143
+ it 'includes the message' do
144
+ @yaml.should match(/message:\s*#{@message}/)
145
+ end
146
+ it 'indicates the masking' do
147
+ @yaml.should match(/is_active:\s*#{@is_active}/)
148
+ end
149
+ it 'includes the line numbers' do
150
+ @lines.each do |line|
151
+ @yaml.should match(/lines:[\s\d-]*- #{line}/)
152
+ end
153
+ end
143
154
  end
144
- it 'indicates the masking' do
145
- @yaml.should match(/is_masked:\s*true/)
155
+
156
+ context 'with all details specified' do
157
+ before :each do
158
+ @source = 'a/ruby/source/file.rb'
159
+ @subclass = 'TooManyParties'
160
+ @parameters = {'one' => 34, 'two' => 'second'}
161
+ warning = SmellWarning.new(@class, @context_name, @lines, @message, @is_masked,
162
+ @source, @subclass, @parameters)
163
+ @yaml = warning.to_yaml
164
+ end
165
+
166
+ it_should_behave_like 'common fields'
167
+
168
+ it 'includes the subclass' do
169
+ @yaml.should match(/subclass:\s*#{@subclass}/)
170
+ end
171
+ it 'includes the source' do
172
+ @yaml.should match(/source:\s*#{@source}/)
173
+ end
174
+ it 'includes the parameters' do
175
+ @parameters.each do |key,value|
176
+ @yaml.should match(/#{key}:\s*#{value}/)
177
+ end
178
+ end
146
179
  end
147
- it 'includes the line number' do
148
- @yaml.should match(/line:\s*27/)
180
+
181
+ context 'with all defaults used' do
182
+ before :each do
183
+ warning = SmellWarning.new(@class, @context_name, @lines, @message, @is_masked)
184
+ @yaml = warning.to_yaml
185
+ end
186
+
187
+ it_should_behave_like 'common fields'
188
+
189
+ it 'includes no subclass' do
190
+ @yaml.should match(/subclass:\s*""/)
191
+ end
192
+ it 'includes no source' do
193
+ @yaml.should match(/source:\s*""/)
194
+ end
195
+ it 'includes empty parameters' do
196
+ @yaml.should_not match(/parameter/)
197
+ end
149
198
  end
150
199
  end
151
200
  end
@@ -1,15 +1,20 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
+ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'attribute')
3
+ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'class_context')
4
+ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'module_context')
5
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
2
6
 
3
- require 'reek/smells/attribute'
4
- require 'reek/class_context'
5
-
6
- include Reek
7
+ include Reek::Core
7
8
  include Reek::Smells
8
9
 
9
10
  describe Attribute do
10
11
  before :each do
11
- @detector = Attribute.new
12
+ @source_name = 'ticker'
13
+ @detector = Attribute.new(@source_name)
12
14
  end
15
+
16
+ it_should_behave_like 'SmellDetector'
17
+
13
18
  context 'with no attributes' do
14
19
  it 'records nothing in the class' do
15
20
  ctx = ClassContext.from_s('class Fred; end')
@@ -24,7 +29,7 @@ describe Attribute do
24
29
  context 'with one attribute' do
25
30
  shared_examples_for 'one attribute found' do
26
31
  it 'records the attribute' do
27
- @detector.attributes_in(@ctx).should include(:property)
32
+ @detector.attributes_in(@ctx).should include([:property, 1])
28
33
  end
29
34
  it 'records only that attribute' do
30
35
  @detector.attributes_in(@ctx).length.should == 1
@@ -95,4 +100,25 @@ describe Attribute do
95
100
  it_should_behave_like 'one attribute found'
96
101
  end
97
102
  end
103
+
104
+ context 'looking at the YAML' do
105
+ before :each do
106
+ @attr = 'prop'
107
+ src = <<EOS
108
+ module Fred
109
+ attr_writer :#{@attr}
110
+ end
111
+ EOS
112
+ @ctx = ModuleContext.from_s(src)
113
+ @detector.examine_context(@ctx)
114
+ warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
115
+ @yaml = warning.to_yaml
116
+ end
117
+ it 'reports the attribute' do
118
+ @yaml.should match(/attribute:\s*#{@attr}/)
119
+ end
120
+ it 'reports the declaration line number' do
121
+ @yaml.should match(/lines:[\s-]*3/)
122
+ end
123
+ end
98
124
  end
@@ -0,0 +1,76 @@
1
+ require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
+ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'boolean_parameter')
3
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
4
+
5
+ include Reek::Smells
6
+
7
+ describe BooleanParameter do
8
+ context 'parameter defaulted with boolean' do
9
+ context 'in a method' do
10
+ it 'reports a parameter defaulted to true' do
11
+ 'def cc(arga = true) end'.should reek_of(:BooleanParameter, /arga/)
12
+ end
13
+ it 'reports a parameter defaulted to false' do
14
+ 'def cc(arga = false) end'.should reek_of(:BooleanParameter, /arga/)
15
+ end
16
+ it 'reports two parameters defaulted to booleans' do
17
+ src = 'def cc(nowt, arga = true, argb = false, &blk) end'
18
+ src.should reek_of(:BooleanParameter, /arga/)
19
+ src.should reek_of(:BooleanParameter, /argb/)
20
+ end
21
+ end
22
+
23
+ context 'in a singleton method' do
24
+ it 'reports a parameter defaulted to true' do
25
+ 'def self.cc(arga = true) end'.should reek_of(:BooleanParameter, /arga/)
26
+ end
27
+ it 'reports a parameter defaulted to false' do
28
+ 'def fred.cc(arga = false) end'.should reek_of(:BooleanParameter, /arga/)
29
+ end
30
+ it 'reports two parameters defaulted to booleans' do
31
+ src = 'def Module.cc(nowt, arga = true, argb = false, &blk) end'
32
+ src.should reek_of(:BooleanParameter, /arga/)
33
+ src.should reek_of(:BooleanParameter, /argb/)
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ describe BooleanParameter do
40
+ before(:each) do
41
+ @source_name = 'smokin'
42
+ @detector = BooleanParameter.new(@source_name)
43
+ end
44
+
45
+ it_should_behave_like 'SmellDetector'
46
+
47
+ context 'looking at the YAML' do
48
+ before :each do
49
+ src = <<EOS
50
+ def cc(arga = true)
51
+ end
52
+ EOS
53
+ source = src.to_reek_source
54
+ sniffer = Sniffer.new(source)
55
+ @mctx = CodeParser.new(sniffer).process_defn(source.syntax_tree)
56
+ @detector.examine(@mctx)
57
+ warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
58
+ @yaml = warning.to_yaml
59
+ end
60
+ it 'reports the source' do
61
+ @yaml.should match(/source:\s*#{@source_name}/)
62
+ end
63
+ it 'reports the class' do
64
+ @yaml.should match(/\sclass:\s*ControlCouple/)
65
+ end
66
+ it 'reports the subclass' do
67
+ @yaml.should match(/subclass:\s*BooleanParameter/)
68
+ end
69
+ it 'reports the parameter name' do
70
+ @yaml.should match(/parameter:\s*arga/)
71
+ end
72
+ it 'reports the correct line' do
73
+ @yaml.should match(/lines:\s*- 1/)
74
+ end
75
+ end
76
+ end
@@ -1,14 +1,15 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
+ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'class_variable')
3
+ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'class_context')
4
+ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'module_context')
5
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
2
6
 
3
- require 'reek/smells/class_variable'
4
- require 'reek/class_context'
5
-
6
- include Reek
7
+ include Reek::Core
7
8
  include Reek::Smells
8
9
 
9
10
  describe ClassVariable do
10
11
  before :each do
11
- @detector = ClassVariable.new
12
+ @detector = ClassVariable.new('raffles')
12
13
  end
13
14
 
14
15
  context 'with no class variables' do
@@ -30,6 +31,12 @@ describe ClassVariable do
30
31
  it 'records only that class variable' do
31
32
  @detector.class_variables_in(@ctx).length.should == 1
32
33
  end
34
+ it 'records the variable in the YAML report' do
35
+ @detector.examine_context(@ctx)
36
+ @detector.smells_found.each do |warning|
37
+ warning.to_yaml.should match(/variable:[\s]*"@@tools"/)
38
+ end
39
+ end
33
40
  end
34
41
 
35
42
  context 'declared in a class' do
@@ -112,4 +119,6 @@ describe ClassVariable do
112
119
  it_should_behave_like 'one variable found'
113
120
  end
114
121
  end
122
+
123
+ it_should_behave_like 'SmellDetector'
115
124
  end
@@ -1,10 +1,17 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- require 'reek/smells/control_couple'
1
+ require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
2
+ require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'control_couple')
3
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
4
4
 
5
5
  include Reek::Smells
6
6
 
7
7
  describe ControlCouple do
8
+ before(:each) do
9
+ @source_name = 'lets get married'
10
+ @detector = ControlCouple.new(@source_name)
11
+ end
12
+
13
+ it_should_behave_like 'SmellDetector'
14
+
8
15
  context 'conditional on a parameter' do
9
16
  it 'should report a ternary check on a parameter' do
10
17
  'def simple(arga) arga ? @ivar : 3 end'.should reek_only_of(:ControlCouple, /arga/)
@@ -20,33 +27,37 @@ describe ControlCouple do
20
27
  end
21
28
  end
22
29
 
23
- context 'parameter defaulted with boolean' do
24
- context 'in a method' do
25
- it 'reports a parameter defaulted to true' do
26
- 'def cc(arga = true) end'.should reek_of(:ControlCouple, /arga/)
27
- end
28
- it 'reports a parameter defaulted to false' do
29
- 'def cc(arga = false) end'.should reek_of(:ControlCouple, /arga/)
30
- end
31
- it 'reports two parameters defaulted to booleans' do
32
- src = 'def cc(nowt, arga = true, argb = false, &blk) end'
33
- src.should reek_of(:ControlCouple, /arga/)
34
- src.should reek_of(:ControlCouple, /argb/)
35
- end
30
+ context 'looking at the YAML' do
31
+ before :each do
32
+ src = <<EOS
33
+ def things(arg)
34
+ @text.map do |blk|
35
+ arg ? blk : "blk"
36
+ end
37
+ puts "hello" if arg
38
+ end
39
+ EOS
40
+ source = src.to_reek_source
41
+ sniffer = Sniffer.new(source)
42
+ @mctx = CodeParser.new(sniffer).process_defn(source.syntax_tree)
43
+ @detector.examine_context(@mctx)
44
+ warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
45
+ @yaml = warning.to_yaml
36
46
  end
37
-
38
- context 'in a singleton method' do
39
- it 'reports a parameter defaulted to true' do
40
- 'def self.cc(arga = true) end'.should reek_of(:ControlCouple, /arga/)
41
- end
42
- it 'reports a parameter defaulted to false' do
43
- 'def fred.cc(arga = false) end'.should reek_of(:ControlCouple, /arga/)
44
- end
45
- it 'reports two parameters defaulted to booleans' do
46
- src = 'def Module.cc(nowt, arga = true, argb = false, &blk) end'
47
- src.should reek_of(:ControlCouple, /arga/)
48
- src.should reek_of(:ControlCouple, /argb/)
49
- end
47
+ it 'reports the source' do
48
+ @yaml.should match(/source:\s*#{@source_name}/)
49
+ end
50
+ it 'reports the class' do
51
+ @yaml.should match(/class:\s*ControlCouple/)
52
+ end
53
+ it 'reports the subclass' do
54
+ @yaml.should match(/subclass:\s*ControlParameter/)
55
+ end
56
+ it 'reports the control parameter' do
57
+ @yaml.should match(/parameter:\s*arg/)
58
+ end
59
+ it 'reports all conditional locations' do
60
+ @yaml.should match(/lines:\s*- 3\s*- 6/)
50
61
  end
51
62
  end
52
63
  end