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
@@ -1,9 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Run metrics with Heckle'
4
- task :ci => %w[ ci:metrics metrics:heckle ]
5
-
6
- namespace :ci do
7
- desc 'Run metrics (except heckle) and spec'
8
- task :metrics => %w[ spec metrics:verify_measurements metrics:flog metrics:flay metrics:reek metrics:roodi metrics:all ]
9
- end
@@ -1,53 +0,0 @@
1
- # encoding: utf-8
2
-
3
- PLATFORM = defined?(RUBY_ENGINE) && RUBY_ENGINE || 'ruby'
4
-
5
- namespace :metrics do
6
- if RUBY_VERSION >= '1.9.3' && PLATFORM == 'ruby'
7
- begin
8
- require 'flay'
9
- require 'yaml'
10
-
11
- config = YAML.load_file(File.expand_path('../../../config/flay.yml', __FILE__)).freeze
12
- threshold = config.fetch('threshold').to_i
13
- total_score = config.fetch('total_score').to_f
14
- files = Flay.expand_dirs_to_files(config.fetch('path', 'lib')).sort
15
-
16
- # original code by Marty Andrews:
17
- # http://blog.martyandrews.net/2009/05/enforcing-ruby-code-quality.html
18
- desc 'Analyze for code duplication'
19
- task :flay do
20
- # run flay once without a threshold to ensure the max mass matches the threshold
21
- flay = Flay.new(:fuzzy => false, :verbose => false, :mass => 0)
22
- flay.process(*files)
23
-
24
- max = (flay.masses.map { |hash, mass| mass.to_f / flay.hashes[hash].size }.max) || 0
25
- unless max >= threshold
26
- raise "Adjust flay threshold down to #{max}"
27
- end
28
-
29
- total = flay.masses.reduce(0.0) { |total, (hash, mass)| total + (mass.to_f / flay.hashes[hash].size) }
30
- unless total == total_score
31
- raise "Flay total is now #{total}, but expected #{total_score}"
32
- end
33
-
34
- # run flay a second time with the threshold set
35
- flay = Flay.new(:fuzzy => false, :verbose => false, :mass => threshold.succ)
36
- flay.process(*files)
37
-
38
- if flay.masses.any?
39
- flay.report
40
- raise "#{flay.masses.size} chunks of code have a duplicate mass > #{threshold}"
41
- end
42
- end
43
- rescue LoadError
44
- task :flay do
45
- $stderr.puts 'Flay is not available. In order to run flay, you must: gem install flay'
46
- end
47
- end
48
- else
49
- task :flay do
50
- $stderr.puts "Flay is disabled under #{PLATFORM}-#{RUBY_VERSION} since it is not score compatible with other implementations"
51
- end
52
- end
53
- end
@@ -1,44 +0,0 @@
1
- # encoding: utf-8
2
-
3
- namespace :metrics do
4
- begin
5
- require 'backports'
6
- require 'flog'
7
- require 'yaml'
8
-
9
- config = YAML.load_file(File.expand_path('../../../config/flog.yml', __FILE__)).freeze
10
- threshold = config.fetch('threshold').to_f.round(1)
11
-
12
- # original code by Marty Andrews:
13
- # http://blog.martyandrews.net/2009/05/enforcing-ruby-code-quality.html
14
- desc 'Analyze for code complexity'
15
- task :flog do
16
- flog = Flog.new
17
- flog.flog Array(config.fetch('path', 'lib'))
18
-
19
- totals = flog.totals.select { |name, score| name[-5, 5] != '#none' }.
20
- map { |name, score| [ name, score.round(1) ] }.
21
- sort_by { |name, score| score }
22
-
23
- if totals.any?
24
- max = totals.last[1]
25
- unless max >= threshold
26
- raise "Adjust flog score down to #{max}"
27
- end
28
- end
29
-
30
- bad_methods = totals.select { |name, score| score > threshold }
31
- if bad_methods.any?
32
- bad_methods.reverse_each do |name, score|
33
- puts '%8.1f: %s' % [ score, name ]
34
- end
35
-
36
- raise "#{bad_methods.size} methods have a flog complexity > #{threshold}"
37
- end
38
- end
39
- rescue LoadError
40
- task :flog do
41
- $stderr.puts 'Flog is not available. In order to run flog, you must: gem install flog'
42
- end
43
- end
44
- end
@@ -1,52 +0,0 @@
1
- # original code by Ashley Moran:
2
- # http://aviewfromafar.net/2007/11/1/rake-task-for-heckling-your-specs
3
- desc 'Heckle each module and class'
4
- task 'metrics:heckle' => 'metrics:coverage' do
5
- root_module = 'Yardstick'
6
- spec_files = FileList['spec/uni/**/*_spec.rb']
7
-
8
- current_module = nil
9
- current_method = nil
10
-
11
- heckle_caught_modules = Hash.new { |hash, key| hash[key] = [] }
12
- unhandled_mutations = 0
13
-
14
- IO.popen("spec --heckle #{root_module} #{spec_files} 2>/dev/null") do |pipe|
15
- while line = pipe.gets
16
- case line = line.chomp
17
- when /\A\*\*\*\s+(#{root_module}(?:::)?(?:\w+(?:::)?)*)#(\S+)/
18
- current_module, current_method = $1, $2
19
- when "The following mutations didn't cause test failures:"
20
- heckle_caught_modules[current_module] << current_method
21
- when '+++ mutation'
22
- unhandled_mutations += 1
23
- end
24
-
25
- puts line
26
- end
27
- end
28
-
29
- if unhandled_mutations > 0
30
- error_message_lines = [ "*************\n" ]
31
-
32
- error_message_lines << "Heckle found #{unhandled_mutations} " \
33
- "mutation#{"s" unless unhandled_mutations == 1} " \
34
- "that didn't cause spec violations\n"
35
-
36
- heckle_caught_modules.each do |mod, methods|
37
- error_message_lines << "#{mod} contains the following " \
38
- 'poorly-specified methods:'
39
- methods.each do |method|
40
- error_message_lines << " - #{method}"
41
- end
42
- error_message_lines << ''
43
- end
44
-
45
- error_message_lines << 'Get your act together and come back ' \
46
- 'when your specs are doing their job!'
47
-
48
- raise error_message_lines.join("\n")
49
- else
50
- puts 'Well done! Your code withstood a heckling.'
51
- end
52
- end
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
-
3
- begin
4
- require 'metric_fu'
5
- require 'json'
6
-
7
- # XXX: temporary hack until metric_fu is fixed
8
- MetricFu::Saikuro.class_eval { include FileUtils }
9
-
10
- MetricFu::Configuration.run do |config|
11
- config.rcov = {
12
- :environment => 'test',
13
- :test_files => %w[ spec/**/*_spec.rb ],
14
- :rcov_opts => %w[
15
- --sort coverage
16
- --no-html
17
- --text-coverage
18
- --no-color
19
- --profile
20
- --exclude spec/,^/
21
- --include lib:spec
22
- ],
23
- }
24
- end
25
- rescue LoadError
26
- namespace :metrics do
27
- task :all do
28
- $stderr.puts 'metric_fu is not available. In order to run metrics:all, you must: gem install metric_fu'
29
- end
30
- end
31
- end
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
-
3
- namespace :metrics do
4
- begin
5
- require 'reek/rake/task'
6
-
7
- RBX_18_MODE = RUBY_VERSION < '1.9' && defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
8
-
9
- Reek::Rake::Task.new do |t|
10
- # reek has some problems under rbx in 1.8 mode that cause the underlying
11
- # script to raise an exception. Rather than halt the "rake ci" process due
12
- # to one bug, we choose to ignore it in this specific case until reek can be
13
- # fixed.
14
- t.fail_on_error = ! RBX_18_MODE # always true, except under rbx 18 mode
15
- end
16
- rescue LoadError
17
- task :reek do
18
- $stderr.puts 'Reek is not available. In order to run reek, you must: gem install reek'
19
- end
20
- end
21
- end
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
-
3
- namespace :metrics do
4
- begin
5
- require 'roodi'
6
- require 'rake/tasklib'
7
- require 'roodi_task'
8
-
9
- RoodiTask.new do |t|
10
- t.verbose = false
11
- t.config = File.expand_path('../../../config/roodi.yml', __FILE__)
12
- t.patterns = %w[ lib/**/*.rb ]
13
- end
14
- rescue LoadError
15
- task :roodi do
16
- $stderr.puts 'Roodi is not available. In order to run roodi, you must: gem install roodi'
17
- end
18
- end
19
- end
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
-
3
- namespace :metrics do
4
- begin
5
- $LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
6
-
7
- require 'yardstick/rake/measurement'
8
- require 'yardstick/rake/verify'
9
- require 'yaml'
10
-
11
- config = YAML.load_file(File.expand_path('../../../config/yardstick.yml', __FILE__))
12
-
13
- # yardstick_measure task
14
- Yardstick::Rake::Measurement.new
15
-
16
- # verify_measurements task
17
- Yardstick::Rake::Verify.new do |verify|
18
- verify.threshold = config.fetch('threshold')
19
- end
20
- rescue LoadError
21
- %w[ yardstick_measure verify_measurements ].each do |name|
22
- task name.to_s do
23
- $stderr.puts "Yardstick is not available. In order to run #{name}, you must: gem install yardstick"
24
- end
25
- end
26
- end
27
- end
data/tasks/spec.rake DELETED
@@ -1,64 +0,0 @@
1
- # encoding: utf-8
2
-
3
- spec_defaults = lambda do |spec|
4
- spec.ruby_opts = %w[ -r./spec/support/config_alias ]
5
- spec.spec_opts << '--options' << 'spec/spec.opts'
6
- end
7
-
8
- begin
9
- require 'spec/rake/spectask'
10
-
11
- desc 'Run all specs'
12
- task :spec => %w[ spec:unit spec:integration ]
13
-
14
- namespace :spec do
15
- desc 'Run unit specs'
16
- Spec::Rake::SpecTask.new(:unit) do |unit|
17
- spec_defaults.call(unit)
18
- unit.pattern = 'spec/unit/**/*_spec.rb'
19
- end
20
-
21
- desc 'Run integration specs'
22
- Spec::Rake::SpecTask.new(:integration) do |integration|
23
- spec_defaults.call(integration)
24
- integration.pattern = 'spec/integration/**/*_spec.rb'
25
- end
26
- end
27
- rescue LoadError
28
- %w[ spec spec:unit spec:integration ].each do |name|
29
- task name do
30
- $stderr.puts "rspec is not available. In order to run #{name}, you must: gem install rspec"
31
- end
32
- end
33
- end
34
-
35
- namespace :metrics do
36
- lib = RUBY_VERSION < '1.9' ? 'rcov' : 'simplecov'
37
- begin
38
- require lib
39
-
40
- if lib == 'rcov'
41
- require 'spec/rake/spectask'
42
-
43
- desc 'Generate code coverage'
44
- Spec::Rake::SpecTask.new(:coverage) do |rcov|
45
- spec_defaults.call(rcov)
46
- rcov.rcov = true
47
- rcov.pattern = 'spec/unit/**/*_spec.rb'
48
- rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
49
- end
50
- else
51
- desc 'Generate code coverage'
52
- task :coverage do
53
- ENV['COVERAGE'] = 'true'
54
- Rake::Task['spec:unit'].execute
55
- end
56
- end
57
- rescue LoadError
58
- task :coverage do
59
- $stderr.puts "coverage is not available. In order to run #{lib}, you must: gem install #{lib}"
60
- end
61
- end
62
- end
63
-
64
- task :test => :spec
data/tasks/yard.rake DELETED
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- begin
4
- require 'yard'
5
-
6
- YARD::Rake::YardocTask.new
7
- rescue LoadError
8
- task :yard do
9
- $stderr.puts 'YARD is not available. In order to run yard, you must: gem install yard'
10
- end
11
- end