metric_fu 4.10.0 → 4.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -2
  4. data/.simplecov +42 -0
  5. data/.travis.yml +7 -6
  6. data/CONTRIBUTING.md +1 -1
  7. data/DEV.md +4 -3
  8. data/Gemfile +29 -7
  9. data/HISTORY.md +29 -3
  10. data/README.md +6 -1
  11. data/Rakefile +33 -11
  12. data/checksum/metric_fu-4.10.0.gem.sha512 +1 -1
  13. data/gem_tasks/usage_test.rake +0 -11
  14. data/lib/metric_fu.rb +12 -0
  15. data/lib/metric_fu/configuration.rb +1 -5
  16. data/lib/metric_fu/environment.rb +3 -3
  17. data/lib/metric_fu/formatter.rb +1 -1
  18. data/lib/metric_fu/formatter/html.rb +9 -9
  19. data/lib/metric_fu/gem_run.rb +2 -2
  20. data/lib/metric_fu/{metrics/generator.rb → generator.rb} +0 -0
  21. data/lib/metric_fu/loader.rb +30 -23
  22. data/lib/metric_fu/logger.rb +65 -0
  23. data/lib/metric_fu/logging/mf_debugger.rb +13 -48
  24. data/lib/metric_fu/metric.rb +3 -3
  25. data/lib/metric_fu/metrics/cane/{cane.rb → generator.rb} +0 -0
  26. data/lib/metric_fu/metrics/cane/{cane_grapher.rb → grapher.rb} +0 -0
  27. data/lib/metric_fu/metrics/cane/{init.rb → metric.rb} +1 -1
  28. data/lib/metric_fu/metrics/cane/{template_awesome/cane.html.erb → report.html.erb} +0 -0
  29. data/lib/metric_fu/metrics/churn/{churn.rb → generator.rb} +0 -0
  30. data/lib/metric_fu/metrics/churn/{churn_hotspot.rb → hotspot.rb} +0 -0
  31. data/lib/metric_fu/metrics/churn/{init.rb → metric.rb} +0 -0
  32. data/lib/metric_fu/metrics/churn/{template_awesome/churn.html.erb → report.html.erb} +0 -0
  33. data/lib/metric_fu/metrics/flay/{flay.rb → generator.rb} +16 -2
  34. data/lib/metric_fu/metrics/flay/{flay_grapher.rb → grapher.rb} +0 -0
  35. data/lib/metric_fu/metrics/flay/{flay_hotspot.rb → hotspot.rb} +0 -0
  36. data/lib/metric_fu/metrics/flay/{init.rb → metric.rb} +1 -1
  37. data/lib/metric_fu/metrics/flay/{template_awesome/flay.html.erb → report.html.erb} +0 -0
  38. data/lib/metric_fu/metrics/flog/{flog.rb → generator.rb} +0 -0
  39. data/lib/metric_fu/metrics/flog/{flog_grapher.rb → grapher.rb} +0 -0
  40. data/lib/metric_fu/metrics/flog/{flog_hotspot.rb → hotspot.rb} +0 -0
  41. data/lib/metric_fu/metrics/flog/{init.rb → metric.rb} +1 -1
  42. data/lib/metric_fu/metrics/flog/{template_awesome/flog.html.erb → report.html.erb} +0 -0
  43. data/lib/metric_fu/metrics/hotspots/{hotspots.rb → generator.rb} +1 -1
  44. data/lib/metric_fu/metrics/hotspots/{init.rb → metric.rb} +0 -0
  45. data/lib/metric_fu/metrics/hotspots/{template_awesome/hotspots.html.erb → report.html.erb} +0 -0
  46. data/lib/metric_fu/metrics/rails_best_practices/{rails_best_practices.rb → generator.rb} +0 -0
  47. data/lib/metric_fu/metrics/rails_best_practices/{rails_best_practices_grapher.rb → grapher.rb} +0 -0
  48. data/lib/metric_fu/metrics/rails_best_practices/{init.rb → metric.rb} +1 -1
  49. data/lib/metric_fu/metrics/rails_best_practices/{template_awesome/rails_best_practices.html.erb → report.html.erb} +0 -0
  50. data/lib/metric_fu/metrics/rcov/{rcov.rb → generator.rb} +0 -0
  51. data/lib/metric_fu/metrics/rcov/{rcov_grapher.rb → grapher.rb} +0 -0
  52. data/lib/metric_fu/metrics/rcov/{rcov_hotspot.rb → hotspot.rb} +0 -0
  53. data/lib/metric_fu/metrics/rcov/{init.rb → metric.rb} +0 -0
  54. data/lib/metric_fu/metrics/rcov/rcov_format_coverage.rb +57 -9
  55. data/lib/metric_fu/metrics/rcov/{template_awesome/rcov.html.erb → report.html.erb} +0 -0
  56. data/lib/metric_fu/metrics/rcov/simplecov_formatter.rb +13 -2
  57. data/lib/metric_fu/metrics/reek/{reek.rb → generator.rb} +0 -0
  58. data/lib/metric_fu/metrics/reek/{reek_grapher.rb → grapher.rb} +0 -0
  59. data/lib/metric_fu/metrics/reek/{reek_hotspot.rb → hotspot.rb} +1 -1
  60. data/lib/metric_fu/metrics/reek/{init.rb → metric.rb} +0 -0
  61. data/lib/metric_fu/metrics/reek/{template_awesome/reek.html.erb → report.html.erb} +0 -0
  62. data/lib/metric_fu/metrics/roodi/{roodi.rb → generator.rb} +0 -0
  63. data/lib/metric_fu/metrics/roodi/{roodi_grapher.rb → grapher.rb} +0 -0
  64. data/lib/metric_fu/metrics/roodi/{roodi_hotspot.rb → hotspot.rb} +0 -0
  65. data/lib/metric_fu/metrics/roodi/{init.rb → metric.rb} +0 -0
  66. data/lib/metric_fu/metrics/roodi/{template_awesome/roodi.html.erb → report.html.erb} +0 -0
  67. data/lib/metric_fu/metrics/saikuro/{saikuro.rb → generator.rb} +0 -0
  68. data/lib/metric_fu/metrics/saikuro/{saikuro_hotspot.rb → hotspot.rb} +0 -0
  69. data/lib/metric_fu/metrics/saikuro/{init.rb → metric.rb} +0 -0
  70. data/lib/metric_fu/metrics/saikuro/{template_awesome/saikuro.html.erb → report.html.erb} +0 -0
  71. data/lib/metric_fu/metrics/stats/{stats.rb → generator.rb} +1 -1
  72. data/lib/metric_fu/metrics/stats/{stats_grapher.rb → grapher.rb} +0 -0
  73. data/lib/metric_fu/metrics/stats/{stats_hotspot.rb → hotspot.rb} +0 -0
  74. data/lib/metric_fu/metrics/stats/{init.rb → metric.rb} +0 -0
  75. data/lib/metric_fu/metrics/stats/{template_awesome/stats.html.erb → report.html.erb} +0 -0
  76. data/lib/metric_fu/{metrics → reporting/graphs}/graph.rb +0 -0
  77. data/lib/metric_fu/{reporting/templates/awesome → templates}/_graph.html.erb +0 -0
  78. data/lib/metric_fu/{reporting/templates/awesome → templates}/_report_footer.html.erb +0 -0
  79. data/lib/metric_fu/templates/configuration.rb +3 -2
  80. data/lib/metric_fu/{reporting/templates/awesome → templates}/index.html.erb +1 -1
  81. data/lib/metric_fu/{reporting/templates → templates}/javascripts/bluff-min.js +0 -0
  82. data/lib/metric_fu/{reporting/templates → templates}/javascripts/bluff_graph.js +0 -0
  83. data/lib/metric_fu/{reporting/templates → templates}/javascripts/excanvas.js +0 -0
  84. data/lib/metric_fu/{reporting/templates → templates}/javascripts/highcharts.js +0 -0
  85. data/lib/metric_fu/{reporting/templates → templates}/javascripts/highcharts_graph.js +0 -0
  86. data/lib/metric_fu/{reporting/templates → templates}/javascripts/js-class.js +0 -0
  87. data/lib/metric_fu/{reporting/templates → templates}/javascripts/standalone-framework.js +0 -0
  88. data/lib/metric_fu/{reporting/templates → templates}/javascripts/utils.js +0 -0
  89. data/lib/metric_fu/{reporting/templates/awesome → templates}/layout.html.erb +1 -1
  90. data/lib/metric_fu/templates/metrics_template.rb +68 -0
  91. data/lib/metric_fu/templates/report.rb +11 -3
  92. data/lib/metric_fu/{metrics/base_template.rb → templates/template.rb} +8 -24
  93. data/lib/metric_fu/utility.rb +25 -0
  94. data/lib/metric_fu/version.rb +1 -1
  95. data/metric_fu.gemspec +2 -0
  96. data/spec/capture_warnings.rb +48 -0
  97. data/spec/dummy/lib/bad_encoding.rb +6 -0
  98. data/spec/fixtures/coverage-153.rb +11 -0
  99. data/spec/fixtures/rcov_output.txt +135 -0
  100. data/spec/metric_fu/configuration_spec.rb +4 -265
  101. data/spec/metric_fu/formatter/configuration_spec.rb +46 -0
  102. data/spec/metric_fu/formatter/html_spec.rb +17 -25
  103. data/spec/metric_fu/formatter/yaml_spec.rb +1 -1
  104. data/spec/metric_fu/{metrics/generator_spec.rb → generator_spec.rb} +0 -0
  105. data/spec/metric_fu/metrics/cane/configuration_spec.rb +22 -0
  106. data/spec/metric_fu/metrics/cane/{cane_spec.rb → generator_spec.rb} +1 -1
  107. data/spec/metric_fu/metrics/churn/configuration_spec.rb +15 -0
  108. data/spec/metric_fu/metrics/churn/{churn_spec.rb → generator_spec.rb} +1 -1
  109. data/spec/metric_fu/metrics/flay/configuration_spec.rb +15 -0
  110. data/spec/metric_fu/metrics/flay/{flay_spec.rb → generator_spec.rb} +2 -2
  111. data/spec/metric_fu/metrics/flay/{flay_grapher_spec.rb → grapher_spec.rb} +1 -1
  112. data/spec/metric_fu/metrics/flog/configuration_spec.rb +20 -0
  113. data/spec/metric_fu/metrics/flog/{flog_spec.rb → generator_spec.rb} +1 -1
  114. data/spec/metric_fu/metrics/flog/{flog_grapher_spec.rb → grapher_spec.rb} +1 -1
  115. data/spec/metric_fu/metrics/hotspots/{hotspots_spec.rb → generator_spec.rb} +1 -1
  116. data/spec/metric_fu/metrics/rails_best_practices/configuration_spec.rb +47 -0
  117. data/spec/metric_fu/metrics/rails_best_practices/{rails_best_practices_spec.rb → generator_spec.rb} +1 -1
  118. data/spec/metric_fu/metrics/rails_best_practices/{rails_best_practices_grapher_spec.rb → grapher_spec.rb} +1 -1
  119. data/spec/metric_fu/metrics/rcov/configuration_spec.rb +30 -0
  120. data/spec/metric_fu/metrics/rcov/generator_spec.rb +26 -0
  121. data/spec/metric_fu/metrics/rcov/{rcov_grapher_spec.rb → grapher_spec.rb} +1 -1
  122. data/spec/metric_fu/metrics/rcov/{rcov_hotspot_spec.rb → hotspot_spec.rb} +2 -2
  123. data/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +40 -12
  124. data/spec/metric_fu/metrics/reek/configuration_spec.rb +13 -0
  125. data/spec/metric_fu/metrics/reek/{reek_spec.rb → generator_spec.rb} +1 -1
  126. data/spec/metric_fu/metrics/reek/{reek_grapher_spec.rb → grapher_spec.rb} +1 -1
  127. data/spec/metric_fu/metrics/roodi/configuration_spec.rb +16 -0
  128. data/spec/metric_fu/metrics/roodi/{roodi_spec.rb → generator_spec.rb} +1 -1
  129. data/spec/metric_fu/metrics/roodi/{roodi_grapher_spec.rb → grapher_spec.rb} +1 -1
  130. data/spec/metric_fu/metrics/saikuro/configuration_spec.rb +26 -0
  131. data/spec/metric_fu/metrics/saikuro/{saikuro_spec.rb → generator_spec.rb} +1 -1
  132. data/spec/metric_fu/metrics/stats/{stats_spec.rb → generator_spec.rb} +1 -1
  133. data/spec/metric_fu/metrics/stats/{stats_grapher_spec.rb → grapher_spec.rb} +1 -1
  134. data/spec/metric_fu/{metrics → reporting/graphs}/graph_spec.rb +1 -1
  135. data/spec/metric_fu/run_spec.rb +1 -1
  136. data/spec/metric_fu/templates/configuration_spec.rb +57 -0
  137. data/spec/metric_fu/templates/report_spec.rb +15 -0
  138. data/spec/metric_fu/{metrics/base_template_spec.rb → templates/template_spec.rb} +0 -0
  139. data/spec/quality_spec.rb +86 -0
  140. data/spec/shared/configured.rb +47 -0
  141. data/spec/shared/test_coverage.rb +99 -0
  142. data/spec/spec_helper.rb +9 -5
  143. data/spec/support/helper_methods.rb +3 -2
  144. data/spec/support/matcher_create_file.rb +2 -2
  145. data/spec/support/matcher_create_files.rb +2 -2
  146. data/spec/support/usage_test.rb +24 -7
  147. data/spec/usage_test_spec.rb +28 -2
  148. metadata +165 -112
  149. metadata.gz.sig +0 -0
  150. data/Gemfile.devtools +0 -39
  151. data/lib/metric_fu/reporting/templates/awesome/awesome_template.rb +0 -62
  152. data/spec/metric_fu/metrics/rcov/rcov_spec.rb +0 -185
@@ -1,5 +1,13 @@
1
+ if defined?(JRUBY_VERSION)
2
+ if ENV["JRUBY_OPTS"].to_s !~ /-Xcli.debug=true/
3
+ warn "Coverage may be inaccurate; Try setting JRUBY_OPTS=\"-Xcli.debug=true --debug\""
4
+ # see https://github.com/metricfu/metric_fu/pull/226
5
+ # https://github.com/jruby/jruby/issues/1196
6
+ # https://jira.codehaus.org/browse/JRUBY-6106
7
+ # https://github.com/colszowka/simplecov/issues/86
8
+ end
9
+ end
1
10
  require 'simplecov'
2
- require 'metric_fu'
3
11
  require_relative 'external_client'
4
12
  require_relative 'rcov_format_coverage'
5
13
 
@@ -35,6 +43,7 @@ class SimpleCov::Formatter::MetricFu
35
43
  'rcov.txt'
36
44
  end
37
45
 
46
+ # report should reference file used to build it
38
47
  class FormatLikeRCov
39
48
  def initialize(result)
40
49
  @result = result
@@ -48,7 +57,9 @@ class SimpleCov::Formatter::MetricFu
48
57
  content << "=" * 80
49
58
  content << "\n"
50
59
  source_file.lines.each do |line|
51
- content << (line.missed? ? '!!' : ' ')
60
+ content << '!!' if line.missed?
61
+ content << '--' if line.never? || line.skipped?
62
+ content << ' ' if line.covered?
52
63
  content << " #{line.src.chomp}\n"
53
64
  end
54
65
  content << "\n"
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- class ReekHotspot < MetricFu::Hotspot
2
+ class MetricFu::ReekHotspot < MetricFu::Hotspot
3
3
 
4
4
  # Note that in practice, the prefix reek__ is appended to each one
5
5
  # This was a partially implemented idea to avoid column name collisions
File without changes
File without changes
@@ -8,7 +8,7 @@ module MetricFu
8
8
 
9
9
  def emit
10
10
  require 'code_metrics/statistics'
11
- @output = MfDebugger::Logger.capture_output do
11
+ @output = MetricFu::Utility.capture_output do
12
12
  CodeMetrics::Statistics.new(*dirs).to_s
13
13
  end
14
14
  end
File without changes
@@ -1,3 +1,4 @@
1
+ MetricFu.lib_require { 'templates/metrics_template' }
1
2
  module MetricFu::Templates
2
3
  class Configuration
3
4
 
@@ -5,7 +6,7 @@ module MetricFu::Templates
5
6
 
6
7
  def initialize
7
8
  @options = {}
8
- @options[:template_class] = AwesomeTemplate
9
+ @options[:template_class] = MetricFu::Templates::MetricsTemplate
9
10
  @options[:darwin_txmt_protocol_no_thanks] = true
10
11
  # turning off syntax_highlighting may avoid some UTF-8 issues
11
12
  @options[:syntax_highlighting] = true
@@ -24,4 +25,4 @@ module MetricFu::Templates
24
25
 
25
26
  end
26
27
 
27
- end
28
+ end
@@ -1,4 +1,4 @@
1
- <h3>Metric Fu Results</h3>
1
+ <h3><%= MetricFu.metric_name %> Results</h3>
2
2
  <ul id='projects'>
3
3
  <% metric_links.each do |link| %>
4
4
  <li class='even failure'>
@@ -24,7 +24,7 @@
24
24
  <h1><a href="/">metrics</a> | <a href="index.html"><%= @name %></a></h1>
25
25
  <address class='watermark'>
26
26
  built with
27
- <a href='https://github.com/metricfu/metric_fu'>metric-fu</a>
27
+ <a href='<%= MetricFu.metric_url %>'><%= MetricFu.metric_name %></a>
28
28
  </address>
29
29
  </div>
30
30
  <div id='content'>
@@ -0,0 +1,68 @@
1
+ require 'fileutils'
2
+ MetricFu.lib_require { 'templates/template' }
3
+ MetricFu.lib_require { 'templates/report' }
4
+
5
+ # The MetricsTemplate class is the included template used by the HTML formatter.
6
+ # The only requirement for a template class is that it provides a #write method
7
+ # to actually write out the template.
8
+ module MetricFu
9
+ class Templates::MetricsTemplate < MetricFu::Template
10
+ attr_accessor :result, :per_file_data, :formatter, :metrics, :name, :html
11
+
12
+ def write
13
+ self.name = MetricFu.report_name
14
+
15
+ # Copy javascripts to output directory
16
+ Dir[File.join(template_directory, 'javascripts', '*')].each do |f|
17
+ FileUtils.cp(f, File.join(self.output_directory, File.basename(f)))
18
+ end
19
+
20
+ self.metrics = {}
21
+ result.each_pair do |section, contents|
22
+ if template_exists?(section)
23
+ create_instance_var(section, contents)
24
+ self.metrics[section] = contents
25
+ create_instance_var(:per_file_data, per_file_data)
26
+ mf_debug "Generating html for section #{section} with #{template(section)} for result #{result.class}"
27
+ self.html = erbify(section)
28
+ layout = erbify('layout')
29
+ fn = output_filename(section)
30
+ formatter.write_template(layout, fn)
31
+ else
32
+ mf_debug "no template for section #{section} with #{template(section)} for result #{result.class}"
33
+ end
34
+ end
35
+
36
+ # Instance variables we need should already be created from above
37
+ if template_exists?('index')
38
+ self.html = erbify('index')
39
+ layout = erbify('layout')
40
+ fn = output_filename('index')
41
+ formatter.write_template(layout, fn)
42
+ else
43
+ mf_debug "no template for section index for result #{result.class}"
44
+ end
45
+
46
+ write_file_data
47
+ end
48
+
49
+ def write_file_data
50
+ per_file_data.each_pair do |file, lines|
51
+ next if file.to_s.empty?
52
+ next unless File.file?(file)
53
+ report = MetricFu::Templates::Report.new(file, lines).render
54
+
55
+ formatter.write_template(report, html_filename(file))
56
+ end
57
+ end
58
+
59
+ def html_filename(file)
60
+ "#{file.gsub(%r{/}, '_')}.html"
61
+ end
62
+
63
+ def template_directory
64
+ File.dirname(__FILE__)
65
+ end
66
+
67
+ end
68
+ end
@@ -1,17 +1,25 @@
1
1
  MetricFu.lib_require { 'formatter/syntax' }
2
+ MetricFu.lib_require { 'templates/template' }
2
3
 
4
+
5
+ # Creates an HTML document for a given analyzed file,
6
+ # with scored metrics annotating the relevant line.
3
7
  module MetricFu
4
8
  module Templates
5
9
  class Report < MetricFu::Template
6
10
 
11
+ # @param file [String] the analyzed file to annotate
12
+ # @param lines [Hash] of line number [String] keyed to an list [[Array] of metrics for that line. Each metric in the list is a hash containing the keys :type => metric_name, :descrption => metric_score
13
+ # @example file and lines
14
+ # file: "lib/metric_fu/gem_version.rb
15
+ # lines: {"30"=>[{:type=>:flog, :description=>"Score of 22.43"}], "42"=>[{:type=>:flog, :description=>"Score of 8.64"}]}
7
16
  def initialize(file, lines)
8
17
  @file = file
9
18
  @lines = lines
10
- @data = File.readlines(file)
19
+ @data = File.open(file, 'rb') {|f| f.readlines }
11
20
  end
12
21
 
13
- def render(metrics)
14
- @metrics = metrics
22
+ def render
15
23
  erbify('report')
16
24
  end
17
25
 
@@ -1,22 +1,17 @@
1
1
  require 'erb'
2
2
  module MetricFu
3
3
 
4
- # The Template class is intended as an abstract class for concrete
5
- # template classes to subclass. It provides a variety of utility
6
- # methods to make templating a bit easier. However, classes do not
7
- # have to inherit from here in order to provide a template. The only
8
- # requirement for a template class is that it provides a #write method
9
- # to actually write out the template. See AwesomeTemplate for an
10
- # example.
11
4
  class Template
12
- attr_accessor :result, :per_file_data, :formatter, :output_directory
13
-
5
+ attr_accessor :output_directory
14
6
 
15
7
  def output_directory
16
8
  @output_directory || MetricFu::Io::FileSystem.directory('output_directory')
17
9
  end
18
10
 
19
11
  # Renders a partial and add optional instance variables to the template
12
+ # @param name <String> name of partial, omitting leading underscore (_)
13
+ # @param instance_variables <Hash> of instance variable
14
+ # names and values to set
20
15
  def render_partial(name, instance_variables = {})
21
16
  create_instance_vars(instance_variables)
22
17
  erbify("_#{name}")
@@ -80,20 +75,14 @@ module MetricFu
80
75
  # TODO: each MetricFu::Metric should know about its templates
81
76
  # This class knows too much about the filesystem structure
82
77
  if MetricFu::Metric.enabled_metrics.map(&:name).include?(section) # expects a symbol
83
- File.join(template_dir(section.to_s), "#{section}.html.erb")
78
+ metric_template_path(section.to_s)
84
79
  else
85
80
  File.join(template_directory, section.to_s + ".html.erb")
86
81
  end
87
82
  end
88
83
 
89
- def template_dir(metric)
90
- File.join(MetricFu.metrics_dir, metric, metric_template_dir)
91
- end
92
-
93
- # e.g. template_awesome, template_standard
94
- def metric_template_dir
95
- template_name = self.class.name.sub('Template', '')[/^([A-Z][a-z]+)+/].downcase
96
- "template_#{template_name}"
84
+ def metric_template_path(metric)
85
+ File.join(MetricFu.metrics_dir, metric, 'report.html.erb')
97
86
  end
98
87
 
99
88
  # Determines whether a template file exists for a given section
@@ -252,13 +241,8 @@ module MetricFu
252
241
  string.split('_').collect{|word| word[0] = word[0..0].upcase; word}.join(" ")
253
242
  end
254
243
 
255
- # belive me, I tried to meta program this with an inherited hook
256
- # I couldn't get it working
257
244
  def template_directory
258
- raise "you need to define this method in each subclass with File.dirname(__FILE__)"
259
- # def template_directory
260
- # File.dirname(__FILE__)
261
- # end
245
+ fail "subclasses must specify template_directory. Usually File.dirname(__FILE__)"
262
246
  end
263
247
  end
264
248
  end
@@ -43,5 +43,30 @@ module MetricFu
43
43
  File.binread(file)
44
44
  end
45
45
 
46
+ # From episode 029 of Ruby Tapas by Avdi
47
+ # https://rubytapas.dpdcart.com/subscriber/post?id=88
48
+ def capture_output(stream=STDOUT, &block)
49
+ old_stdout = stream.clone
50
+ pipe_r, pipe_w = IO.pipe
51
+ pipe_r.sync = true
52
+ output = ""
53
+ reader = Thread.new do
54
+ begin
55
+ loop do
56
+ output << pipe_r.readpartial(1024)
57
+ end
58
+ rescue EOFError
59
+ end
60
+ end
61
+ stream.reopen(pipe_w)
62
+ yield
63
+ ensure
64
+ stream.reopen(old_stdout)
65
+ pipe_w.close
66
+ reader.join
67
+ pipe_r.close
68
+ return output
69
+ end
70
+
46
71
  end
47
72
  end
@@ -1,3 +1,3 @@
1
1
  module MetricFu
2
- VERSION = '4.10.0'
2
+ VERSION = '4.11.0'
3
3
  end
data/metric_fu.gemspec CHANGED
@@ -59,6 +59,8 @@ Gem::Specification.new do |s|
59
59
  s.add_runtime_dependency 'coderay'
60
60
  # to_json support
61
61
  s.add_runtime_dependency 'multi_json'
62
+ # open browser support
63
+ s.add_runtime_dependency 'launchy', '~> 2.0'
62
64
 
63
65
  # temporary filesystem to act on
64
66
  s.add_development_dependency 'test_construct'
@@ -0,0 +1,48 @@
1
+ # https://raw.githubusercontent.com/metric_fu/metric_fu/master/spec/capture_warnings.rb
2
+ require 'rubygems' if RUBY_VERSION =~ /^1\.8/
3
+ require 'bundler/setup'
4
+ require 'rspec/core'
5
+ require 'rspec/expectations'
6
+ require 'tempfile'
7
+
8
+ stderr_file = Tempfile.new("metric_fu.stderr")
9
+ current_dir = Dir.pwd
10
+
11
+ RSpec.configure do |config|
12
+
13
+ config.before(:suite) do
14
+ $stderr.reopen(stderr_file.path)
15
+ $VERBOSE = true
16
+ end
17
+
18
+ config.after(:suite) do
19
+ stderr_file.rewind
20
+ lines = stderr_file.read.split("\n").uniq
21
+ stderr_file.close!
22
+
23
+ $stderr.reopen(STDERR)
24
+
25
+ metric_fu_warnings, other_warnings = lines.partition { |line| line.include?(current_dir) }
26
+
27
+ if metric_fu_warnings.any?
28
+ puts
29
+ puts "-" * 30 + " metric_fu warnings: " + "-" * 30
30
+ puts
31
+ puts metric_fu_warnings.join("\n")
32
+ puts
33
+ puts "-" * 75
34
+ puts
35
+ end
36
+
37
+ if other_warnings.any?
38
+ File.open('tmp/warnings.txt', 'w') { |f| f.write(other_warnings.join("\n")) }
39
+ puts
40
+ puts "Non-metric_fu warnings written to tmp/warnings.txt"
41
+ puts
42
+ end
43
+
44
+ # fail the build...
45
+ raise "Failing build due to metric_fu warnings" if metric_fu_warnings.any?
46
+ end
47
+
48
+ end
@@ -0,0 +1,6 @@
1
+ # coding: utf-8
2
+ class SomeClass
3
+ def initialize(a,b,c)
4
+ "hey, invalid ASCII\xED"
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ # from https://github.com/metricfu/metric_fu/issues/153
2
+ class A
3
+ def m(arg1)
4
+ p "this is my method" # Assume that none of the line covered in this method
5
+ if arg1 > 5
6
+ p 'more than 5'
7
+ else
8
+ p 'not more than 5'
9
+ end
10
+ end
11
+ end