yardstick 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +4 -0
  4. data/.ruby-gemset +1 -0
  5. data/.travis.yml +11 -16
  6. data/CONTRIBUTING.md +11 -0
  7. data/Gemfile +3 -59
  8. data/Gemfile.devtools +54 -0
  9. data/Guardfile +32 -0
  10. data/LICENSE +1 -1
  11. data/README.md +71 -55
  12. data/Rakefile +2 -7
  13. data/TODO +12 -0
  14. data/bin/yardstick +1 -0
  15. data/config/devtools.yml +2 -0
  16. data/config/flay.yml +2 -2
  17. data/config/flog.yml +1 -1
  18. data/config/mutant.yml +3 -0
  19. data/config/{site.reek → reek.yml} +31 -25
  20. data/config/rubocop.yml +49 -0
  21. data/config/yardstick.yml +31 -0
  22. data/lib/yardstick.rb +35 -15
  23. data/lib/yardstick/cli.rb +7 -7
  24. data/lib/yardstick/config.rb +176 -0
  25. data/lib/yardstick/document.rb +215 -0
  26. data/lib/yardstick/document_set.rb +21 -0
  27. data/lib/yardstick/measurement.rb +18 -145
  28. data/lib/yardstick/measurement_set.rb +2 -2
  29. data/lib/yardstick/parser.rb +61 -0
  30. data/lib/yardstick/processor.rb +21 -35
  31. data/lib/yardstick/rake/measurement.rb +7 -49
  32. data/lib/yardstick/rake/verify.rb +28 -55
  33. data/lib/yardstick/report_output.rb +57 -0
  34. data/lib/yardstick/rule.rb +64 -37
  35. data/lib/yardstick/rule_config.rb +56 -0
  36. data/lib/yardstick/rules/api_tag.rb +95 -0
  37. data/lib/yardstick/rules/example_tag.rb +33 -0
  38. data/lib/yardstick/rules/return_tag.rb +21 -0
  39. data/lib/yardstick/rules/summary.rb +87 -0
  40. data/lib/yardstick/version.rb +1 -1
  41. data/lib/yardstick/yard_ext.rb +1 -6
  42. data/spec/integration/yardstick/class_methods/measure_spec.rb +22 -0
  43. data/spec/integration/yardstick/class_methods/measure_string_spec.rb +20 -0
  44. data/spec/integration/yardstick/document/file_spec.rb +16 -0
  45. data/spec/integration/yardstick/document/line_spec.rb +25 -0
  46. data/spec/integration/yardstick/document/path_spec.rb +45 -0
  47. data/spec/integration/yardstick/processor/process_string_spec.rb +401 -0
  48. data/spec/integration/yardstick/rake/measurement_spec.rb +22 -0
  49. data/spec/integration/yardstick/rake/verify_spec.rb +19 -0
  50. data/spec/shared/measured_itself_behavior.rb +15 -0
  51. data/spec/spec_helper.rb +13 -26
  52. data/spec/support/document_mock.rb +16 -0
  53. data/spec/support/rules.rb +51 -0
  54. data/spec/unit/yardstick/class_methods/measure_spec.rb +31 -0
  55. data/spec/unit/yardstick/class_methods/measure_string_spec.rb +33 -0
  56. data/spec/unit/yardstick/cli_spec.rb +11 -8
  57. data/spec/unit/yardstick/config/class_methods/coerce_spec.rb +32 -0
  58. data/spec/unit/yardstick/config/for_rule_spec.rb +47 -0
  59. data/spec/unit/yardstick/config/initialize_spec.rb +21 -0
  60. data/spec/unit/yardstick/config/output_spec.rb +15 -0
  61. data/spec/unit/yardstick/config/output_writer_spec.rb +20 -0
  62. data/spec/unit/yardstick/config/path_spec.rb +13 -0
  63. data/spec/unit/yardstick/config/path_writer_spec.rb +11 -0
  64. data/spec/unit/yardstick/config/require_exact_threshold_predicate_spec.rb +19 -0
  65. data/spec/unit/yardstick/config/require_exact_threshold_writer_spec.rb +19 -0
  66. data/spec/unit/yardstick/config/set_defaults_spec.rb +42 -0
  67. data/spec/unit/yardstick/config/threshold_writer_spec.rb +15 -0
  68. data/spec/unit/yardstick/config/verbose_predicate_spec.rb +19 -0
  69. data/spec/unit/yardstick/config/verbose_writer_spec.rb +19 -0
  70. data/spec/unit/yardstick/document/api_predicate_spec.rb +25 -0
  71. data/spec/unit/yardstick/document/class_methods/measure_spec.rb +25 -0
  72. data/spec/unit/yardstick/document/class_methods/register_rule_spec.rb +19 -0
  73. data/spec/unit/yardstick/document/class_methods/registered_rules_spec.rb +9 -0
  74. data/spec/unit/yardstick/document/docstring_spec.rb +11 -0
  75. data/spec/unit/yardstick/document/file_spec.rb +14 -0
  76. data/spec/unit/yardstick/document/has_tag_predicate_spec.rb +15 -0
  77. data/spec/unit/yardstick/document/line_spec.rb +12 -0
  78. data/spec/unit/yardstick/document/null_tag/text_spec.rb +9 -0
  79. data/spec/unit/yardstick/document/null_tag/types_spec.rb +9 -0
  80. data/spec/unit/yardstick/document/path_spec.rb +12 -0
  81. data/spec/unit/yardstick/document/summary_text_spec.rb +23 -0
  82. data/spec/unit/yardstick/document/tag_text_spec.rb +17 -0
  83. data/spec/unit/yardstick/document/tag_types_spec.rb +18 -0
  84. data/spec/unit/yardstick/document/visibility_spec.rb +22 -0
  85. data/spec/unit/yardstick/document_set/measure_spec.rb +28 -0
  86. data/spec/unit/yardstick/measurement/description_spec.rb +12 -0
  87. data/spec/unit/yardstick/measurement/initialize_spec.rb +12 -0
  88. data/spec/unit/yardstick/measurement/ok_predicate_spec.rb +21 -0
  89. data/spec/unit/yardstick/measurement/puts_spec.rb +62 -0
  90. data/spec/unit/yardstick/measurement/skip_predicate_spec.rb +27 -0
  91. data/spec/unit/yardstick/measurement_set/coverage_spec.rb +23 -0
  92. data/spec/unit/yardstick/measurement_set/failed_spec.rb +28 -0
  93. data/spec/unit/yardstick/measurement_set/initialize_spec.rb +27 -0
  94. data/spec/unit/yardstick/measurement_set/puts_spec.rb +63 -0
  95. data/spec/unit/yardstick/measurement_set/successful_spec.rb +13 -0
  96. data/spec/unit/yardstick/measurement_set/total_spec.rb +12 -0
  97. data/spec/unit/yardstick/ordered_set/each_spec.rb +18 -0
  98. data/spec/unit/yardstick/ordered_set/empty_predicate_spec.rb +19 -0
  99. data/spec/unit/yardstick/ordered_set/include_predicate_spec.rb +21 -0
  100. data/spec/unit/yardstick/ordered_set/index_spec.rb +21 -0
  101. data/spec/unit/yardstick/ordered_set/left_shift_operator_spec.rb +16 -0
  102. data/spec/unit/yardstick/ordered_set/length_spec.rb +11 -0
  103. data/spec/unit/yardstick/ordered_set/merge_spec.rb +16 -0
  104. data/spec/unit/yardstick/parser/class_methods/parse_paths_spec.rb +28 -0
  105. data/spec/unit/yardstick/parser/class_methods/parse_string_spec.rb +28 -0
  106. data/spec/unit/yardstick/processor/process_spec.rb +17 -0
  107. data/spec/unit/yardstick/processor/process_string_spec.rb +17 -0
  108. data/spec/unit/yardstick/rake/measurement/initialize_spec.rb +64 -0
  109. data/spec/unit/yardstick/rake/measurement/yardstick_measure_spec.rb +22 -0
  110. data/spec/unit/yardstick/rake/verify/initialize_spec.rb +72 -0
  111. data/spec/unit/yardstick/rake/verify/verify_measurements_spec.rb +85 -0
  112. data/spec/unit/yardstick/report_output/class_methods/coerce_spec.rb +18 -0
  113. data/spec/unit/yardstick/report_output/initialize_spec.rb +11 -0
  114. data/spec/unit/yardstick/report_output/to_s_spec.rb +12 -0
  115. data/spec/unit/yardstick/report_output/write_spec.rb +31 -0
  116. data/spec/unit/yardstick/round_percentage_spec.rb +9 -0
  117. data/spec/unit/yardstick/rule/class_methods/coerce_spec.rb +21 -0
  118. data/spec/unit/yardstick/rule/class_methods/inherited_spec.rb +15 -0
  119. data/spec/unit/yardstick/rule/enabled_predicate_spec.rb +18 -0
  120. data/spec/unit/yardstick/rule/initialize_spec.rb +25 -0
  121. data/spec/unit/yardstick/rule/validatable_predicate_spec.rb +11 -0
  122. data/spec/unit/yardstick/rule_config/enabled_for_path_predicate_spec.rb +41 -0
  123. data/spec/unit/yardstick/rule_config/initialize_spec.rb +16 -0
  124. data/spec/unit/yardstick/rules/api_tag/inclusion/valid_predicate_spec.rb +27 -0
  125. data/spec/unit/yardstick/rules/api_tag/presence/valid_predicate_spec.rb +25 -0
  126. data/spec/unit/yardstick/rules/api_tag/private_method/valid_predicate_spec.rb +21 -0
  127. data/spec/unit/yardstick/rules/api_tag/private_method/validatable_predicate_spec.rb +21 -0
  128. data/spec/unit/yardstick/rules/api_tag/protected_method/valid_predicate_spec.rb +25 -0
  129. data/spec/unit/yardstick/rules/api_tag/protected_method/validatable_predicate_spec.rb +21 -0
  130. data/spec/unit/yardstick/rules/example_tag/valid_predicate_spec.rb +25 -0
  131. data/spec/unit/yardstick/rules/example_tag/validatable_predicate_spec.rb +32 -0
  132. data/spec/unit/yardstick/rules/return_tag/valid_predicate_spec.rb +21 -0
  133. data/spec/unit/yardstick/rules/summary/delimiter/valid_predicate_spec.rb +21 -0
  134. data/spec/unit/yardstick/rules/summary/length/valid_predicate_spec.rb +27 -0
  135. data/spec/unit/yardstick/rules/summary/presence/valid_predicate_spec.rb +21 -0
  136. data/spec/unit/yardstick/rules/summary/presence/validatable_predicate_spec.rb +21 -0
  137. data/spec/unit/yardstick/rules/summary/single_line/valid_predicate_spec.rb +21 -0
  138. data/yardstick.gemspec +7 -11
  139. metadata +222 -65
  140. data/.rvmrc +0 -1
  141. data/lib/yardstick/measurable.rb +0 -67
  142. data/lib/yardstick/method.rb +0 -113
  143. data/lib/yardstick/rule_set.rb +0 -22
  144. data/spec/support/config_alias.rb +0 -5
  145. data/spec/unit/yardstick/measurement_set_spec.rb +0 -266
  146. data/spec/unit/yardstick/measurement_spec.rb +0 -257
  147. data/spec/unit/yardstick/method_spec.rb +0 -357
  148. data/spec/unit/yardstick/rake/measurement_spec.rb +0 -175
  149. data/spec/unit/yardstick/rake/verify_spec.rb +0 -231
  150. data/spec/unit/yardstick/rule_spec.rb +0 -36
  151. data/spec/unit/yardstick_spec.rb +0 -71
  152. data/tasks/metrics/ci.rake +0 -9
  153. data/tasks/metrics/flay.rake +0 -53
  154. data/tasks/metrics/flog.rake +0 -44
  155. data/tasks/metrics/heckle.rake +0 -52
  156. data/tasks/metrics/metric_fu.rake +0 -31
  157. data/tasks/metrics/reek.rake +0 -21
  158. data/tasks/metrics/roodi.rake +0 -19
  159. data/tasks/metrics/yardstick.rake +0 -27
  160. data/tasks/spec.rake +0 -64
  161. data/tasks/yard.rake +0 -11
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use @$(basename `pwd`) --create
@@ -1,67 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Yardstick
4
- module Measurable
5
- include Measurement::UtilityMethods
6
-
7
- module ClassMethods
8
-
9
- # Include the class or module with measurable class methods
10
- #
11
- # @param [Module] mod
12
- # the module to include within
13
- #
14
- # @return [undefined]
15
- #
16
- # @api private
17
- def included(mod)
18
- mod.extend(ClassMethods).rules.merge(rules)
19
- end
20
-
21
- # List of rules for this class
22
- #
23
- # @return [Yardstick::RuleSet<Rule>]
24
- # the rules for this class
25
- #
26
- # @api private
27
- def rules
28
- @rules ||= RuleSet.new
29
- end
30
-
31
- # Set the description for the rule
32
- #
33
- # @param [#to_str] description
34
- # the rule description
35
- #
36
- # @yield []
37
- # the rule to perform
38
- #
39
- # @yieldreturn [Boolean]
40
- # return true if successful, false if not
41
- #
42
- # @return [undefined]
43
- #
44
- # @api private
45
- def rule(description, &block)
46
- rules << Rule.new(description, &block)
47
- end
48
-
49
- end # module ClassMethods
50
-
51
- extend ClassMethods
52
-
53
- # Return a list of measurements for this docstring instance
54
- #
55
- # @example
56
- # docstring.measure # => [ Measurement ]
57
- #
58
- # @return [Yardstick::MeasurementSet]
59
- # a collection of measurements
60
- #
61
- # @api public
62
- def measure
63
- self.class.rules.measure(self)
64
- end
65
-
66
- end # module Measurable
67
- end # module Yardstick
@@ -1,113 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Yardstick
4
- module Method
5
- include Measurable
6
-
7
- rule 'The method summary should be specified' do
8
- skip if has_tag?('see')
9
- summary_text != ''
10
- end
11
-
12
- rule 'The method summary should be less than 80 characters in length' do
13
- summary_text.split(//).length <= 80
14
- end
15
-
16
- rule 'The method summary should not end in a period' do
17
- summary_text[-1, 1] != '.'
18
- end
19
-
20
- rule 'The method summary should be a single line' do
21
- !summary_text.include?("\n")
22
- end
23
-
24
- rule 'The public/semipublic method should have an example specified' do
25
- skip if api?(%w[ private ]) || tag_types('return') == %w[ undefined ]
26
- has_tag?('example')
27
- end
28
-
29
- rule 'The @api tag should be specified' do
30
- has_tag?('api')
31
- end
32
-
33
- rule 'The @api tag must be either public, semipublic or private' do
34
- %w[ public semipublic private ].include?(tag_text('api'))
35
- end
36
-
37
- rule 'A method with protected visibility must have an @api tag of semipublic or private' do
38
- skip unless visibility == :protected
39
- api?(%w[ semipublic private ])
40
- end
41
-
42
- rule 'A method with private visibility must have an @api tag of private' do
43
- skip unless visibility == :private
44
- api?(%w[ private ])
45
- end
46
-
47
- rule 'The @return tag should be specified' do
48
- has_tag?('return')
49
- end
50
-
51
- private
52
-
53
- # The raw text for the summary
54
- #
55
- # @return [String]
56
- # the summary text
57
- #
58
- # @api private
59
- def summary_text
60
- split(/\r?\n\r?\n/).first || ''
61
- end
62
-
63
- # The text for a specified tag
64
- #
65
- # @param [String] tag_name
66
- # the name of the tag
67
- #
68
- # @return [String, nil]
69
- # the tag text if the tag exists
70
- #
71
- # @api private
72
- def tag_text(tag_name)
73
- tag(tag_name).text if has_tag?(tag_name)
74
- end
75
-
76
- # The types for a specified tag
77
- #
78
- # @param [String] tag_name
79
- # the name of the tag
80
- #
81
- # @return [Array<String>, nil]
82
- # a collection of tag types if the tag exists
83
- #
84
- # @api private
85
- def tag_types(tag_name)
86
- tag(tag_name).types if has_tag?(tag_name)
87
- end
88
-
89
- # The method visibility: public, protected or private
90
- #
91
- # @return [Symbol]
92
- # the visibility of the method
93
- #
94
- # @api private
95
- def visibility
96
- object.visibility
97
- end
98
-
99
- # Check if the method API type matches
100
- #
101
- # @param [Array<String>] types
102
- # a collection of API types
103
- #
104
- # @return [Boolean]
105
- # true if the API type matches
106
- #
107
- # @api private
108
- def api?(types)
109
- types.include?(tag_text('api'))
110
- end
111
-
112
- end # module Method
113
- end # module Yardstick
@@ -1,22 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Yardstick
4
-
5
- # A set of rules to apply to docs
6
- class RuleSet < OrderedSet
7
-
8
- # Measure a docstring with all Rules
9
- #
10
- # @param [YARD::Docstring] docstring
11
- # the docstring to measure
12
- #
13
- # @return [MeasurementSet]
14
- # a collection of measurements
15
- #
16
- # @api private
17
- def measure(docstring)
18
- MeasurementSet.new(map { |rule| rule.measure(docstring) })
19
- end
20
-
21
- end # class RuleSet
22
- end # module Yardstick
@@ -1,5 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rbconfig'
4
-
5
- ::Config = RbConfig unless defined?(::Config)
@@ -1,266 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Yardstick::MeasurementSet do
6
- before do
7
- YARD.parse_string('def test; end')
8
-
9
- @description = 'test measurement'
10
- @docstring = YARD::Registry.all(:method).first.docstring
11
-
12
- @measurement = Yardstick::Measurement.new(@description, @docstring) { true }
13
- @measurements = Yardstick::MeasurementSet.new
14
- end
15
-
16
- it 'should be Enumerable' do
17
- Yardstick::MeasurementSet.new.should be_kind_of(Enumerable)
18
- end
19
-
20
- describe '.new' do
21
- describe 'with no arguments' do
22
- before do
23
- @measurements = Yardstick::MeasurementSet.new
24
- end
25
-
26
- it 'should return a MeasurementSet' do
27
- @measurements.should be_kind_of(Yardstick::MeasurementSet)
28
- end
29
-
30
- it 'should be empty' do
31
- @measurements.should be_empty
32
- end
33
- end
34
-
35
- describe 'with Measurements' do
36
- before do
37
- @measurements = Yardstick::MeasurementSet.new([ @measurement ])
38
- end
39
-
40
- it 'should return a MeasurementSet' do
41
- @measurements.should be_kind_of(Yardstick::MeasurementSet)
42
- end
43
-
44
- it 'should include the Measurements' do
45
- @measurements.should include(@measurement)
46
- end
47
- end
48
- end
49
-
50
- describe '#<<' do
51
- describe 'with a new Measurement' do
52
- before do
53
- @response = @measurements << @measurement
54
- end
55
-
56
- it 'should return self' do
57
- @response.should be_equal(@measurements)
58
- end
59
-
60
- it 'should append the Measurement' do
61
- @measurements.to_a.last.should equal(@measurement)
62
- end
63
- end
64
-
65
- describe 'with an equivalent Measurement' do
66
- before do
67
- @measurements << @measurement
68
- @measurements.to_a.should == [ @measurement ]
69
-
70
- @response = @measurements << Yardstick::Measurement.new(@description, @docstring) { true }
71
- end
72
-
73
- it 'should return self' do
74
- @response.should be_equal(@measurements)
75
- end
76
-
77
- it 'should not append the Measurement again' do
78
- @measurements.to_a.should == [ @measurement ]
79
- end
80
- end
81
- end
82
-
83
- describe '#merge' do
84
- before do
85
- @other = Yardstick::MeasurementSet.new
86
- @other << @measurement
87
-
88
- @response = @measurements.merge(@other)
89
- end
90
-
91
- it 'should return self' do
92
- @response.should be_equal(@measurements)
93
- end
94
-
95
- it 'should merge the other Measurements' do
96
- @measurements.should include(*@other)
97
- end
98
- end
99
-
100
- describe '#each' do
101
- before do
102
- @measurements << @measurement
103
-
104
- @yield = []
105
-
106
- @response = @measurements.each { |*args| @yield << args }
107
- end
108
-
109
- it 'should return self' do
110
- @response.should be_equal(@measurements)
111
- end
112
-
113
- it 'should yield measurements' do
114
- @yield.should eql([ [ @measurement ] ])
115
- end
116
- end
117
-
118
- describe '#empty?' do
119
- describe 'when there are no measurements' do
120
- it 'should return true' do
121
- @measurements.empty?.should be_true
122
- end
123
- end
124
-
125
- describe 'when there are measurements' do
126
- before do
127
- @measurements << @measurement
128
- end
129
-
130
- it 'should return false' do
131
- @measurements.empty?.should be_false
132
- end
133
- end
134
- end
135
-
136
- describe '#include?' do
137
- describe 'when provided an included measurement' do
138
- before do
139
- @measurements << @measurement
140
-
141
- @response = @measurements.include?(@measurement)
142
- end
143
-
144
- it 'should return true' do
145
- @response.should be_true
146
- end
147
- end
148
-
149
- describe 'when provided an excluded measurement' do
150
- before do
151
- @response = @measurements.include?(@measurement)
152
- end
153
-
154
- it 'should return false' do
155
- @response.should be_false
156
- end
157
- end
158
- end
159
-
160
- describe '#index' do
161
- describe 'when provided an included measurement' do
162
- before do
163
- @measurements << @measurement
164
-
165
- @response = @measurements.index(@measurement)
166
- end
167
-
168
- it 'should return the index' do
169
- @response.should eql(0)
170
- end
171
- end
172
-
173
- describe 'when provided an excluded measurement' do
174
- before do
175
- @response = @measurements.index(@measurement)
176
- end
177
-
178
- it 'should return nil' do
179
- @response.should == nil
180
- end
181
- end
182
- end
183
-
184
- describe '#total' do
185
- before do
186
- @measurements << @measurement
187
- end
188
-
189
- it 'should return the number of total measurements' do
190
- @measurements.total.should eql(1)
191
- end
192
- end
193
-
194
- describe '#successful' do
195
- before do
196
- @measurements << @measurement
197
- end
198
-
199
- it 'should return the number of successful measurements' do
200
- @measurements.successful.should eql(1)
201
- end
202
- end
203
-
204
- describe '#failed' do
205
- before do
206
- @measurements << @measurement
207
- end
208
-
209
- it 'should return the number of failed measurements' do
210
- @measurements.failed.should eql(0)
211
- end
212
- end
213
-
214
- describe '#coverage' do
215
- describe 'when there are no measurements' do
216
- it 'should return 1' do
217
- @measurements.coverage.should eql(1)
218
- end
219
- end
220
-
221
- describe 'when there are measurements' do
222
- before do
223
- @response = @measurements << @measurement
224
- end
225
-
226
- it 'should return a Rational' do
227
- @measurements.coverage.should be_kind_of(Rational)
228
- end
229
-
230
- it 'should return the expected value' do
231
- @measurements.coverage.should == 1
232
- end
233
- end
234
- end
235
-
236
- describe '#puts' do
237
- before do
238
- @measurements << Yardstick::Measurement.new(@description, @docstring) { false }
239
- end
240
-
241
- describe 'with no arguments' do
242
- before do
243
- capture_stdout { @measurements.puts }
244
- end
245
-
246
- it 'should output the summary' do
247
- @output.should == "(stdin):1: #test: test measurement\n" \
248
- "\nYARD-Coverage: 0.0% Success: 0 Failed: 1 Total: 1\n"
249
- end
250
- end
251
-
252
- describe 'with an object implementing #puts' do
253
- before do
254
- io = StringIO.new
255
- @measurements.puts(io)
256
- io.rewind
257
- @output = io.read
258
- end
259
-
260
- it 'should output the summary' do
261
- @output.should == "(stdin):1: #test: test measurement\n" \
262
- "\nYARD-Coverage: 0.0% Success: 0 Failed: 1 Total: 1\n"
263
- end
264
- end
265
- end
266
- end