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.
- checksums.yaml +8 -8
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -2
- data/.simplecov +42 -0
- data/.travis.yml +7 -6
- data/CONTRIBUTING.md +1 -1
- data/DEV.md +4 -3
- data/Gemfile +29 -7
- data/HISTORY.md +29 -3
- data/README.md +6 -1
- data/Rakefile +33 -11
- data/checksum/metric_fu-4.10.0.gem.sha512 +1 -1
- data/gem_tasks/usage_test.rake +0 -11
- data/lib/metric_fu.rb +12 -0
- data/lib/metric_fu/configuration.rb +1 -5
- data/lib/metric_fu/environment.rb +3 -3
- data/lib/metric_fu/formatter.rb +1 -1
- data/lib/metric_fu/formatter/html.rb +9 -9
- data/lib/metric_fu/gem_run.rb +2 -2
- data/lib/metric_fu/{metrics/generator.rb → generator.rb} +0 -0
- data/lib/metric_fu/loader.rb +30 -23
- data/lib/metric_fu/logger.rb +65 -0
- data/lib/metric_fu/logging/mf_debugger.rb +13 -48
- data/lib/metric_fu/metric.rb +3 -3
- data/lib/metric_fu/metrics/cane/{cane.rb → generator.rb} +0 -0
- data/lib/metric_fu/metrics/cane/{cane_grapher.rb → grapher.rb} +0 -0
- data/lib/metric_fu/metrics/cane/{init.rb → metric.rb} +1 -1
- data/lib/metric_fu/metrics/cane/{template_awesome/cane.html.erb → report.html.erb} +0 -0
- data/lib/metric_fu/metrics/churn/{churn.rb → generator.rb} +0 -0
- data/lib/metric_fu/metrics/churn/{churn_hotspot.rb → hotspot.rb} +0 -0
- data/lib/metric_fu/metrics/churn/{init.rb → metric.rb} +0 -0
- data/lib/metric_fu/metrics/churn/{template_awesome/churn.html.erb → report.html.erb} +0 -0
- data/lib/metric_fu/metrics/flay/{flay.rb → generator.rb} +16 -2
- data/lib/metric_fu/metrics/flay/{flay_grapher.rb → grapher.rb} +0 -0
- data/lib/metric_fu/metrics/flay/{flay_hotspot.rb → hotspot.rb} +0 -0
- data/lib/metric_fu/metrics/flay/{init.rb → metric.rb} +1 -1
- data/lib/metric_fu/metrics/flay/{template_awesome/flay.html.erb → report.html.erb} +0 -0
- data/lib/metric_fu/metrics/flog/{flog.rb → generator.rb} +0 -0
- data/lib/metric_fu/metrics/flog/{flog_grapher.rb → grapher.rb} +0 -0
- data/lib/metric_fu/metrics/flog/{flog_hotspot.rb → hotspot.rb} +0 -0
- data/lib/metric_fu/metrics/flog/{init.rb → metric.rb} +1 -1
- data/lib/metric_fu/metrics/flog/{template_awesome/flog.html.erb → report.html.erb} +0 -0
- data/lib/metric_fu/metrics/hotspots/{hotspots.rb → generator.rb} +1 -1
- data/lib/metric_fu/metrics/hotspots/{init.rb → metric.rb} +0 -0
- data/lib/metric_fu/metrics/hotspots/{template_awesome/hotspots.html.erb → report.html.erb} +0 -0
- data/lib/metric_fu/metrics/rails_best_practices/{rails_best_practices.rb → generator.rb} +0 -0
- data/lib/metric_fu/metrics/rails_best_practices/{rails_best_practices_grapher.rb → grapher.rb} +0 -0
- data/lib/metric_fu/metrics/rails_best_practices/{init.rb → metric.rb} +1 -1
- data/lib/metric_fu/metrics/rails_best_practices/{template_awesome/rails_best_practices.html.erb → report.html.erb} +0 -0
- data/lib/metric_fu/metrics/rcov/{rcov.rb → generator.rb} +0 -0
- data/lib/metric_fu/metrics/rcov/{rcov_grapher.rb → grapher.rb} +0 -0
- data/lib/metric_fu/metrics/rcov/{rcov_hotspot.rb → hotspot.rb} +0 -0
- data/lib/metric_fu/metrics/rcov/{init.rb → metric.rb} +0 -0
- data/lib/metric_fu/metrics/rcov/rcov_format_coverage.rb +57 -9
- data/lib/metric_fu/metrics/rcov/{template_awesome/rcov.html.erb → report.html.erb} +0 -0
- data/lib/metric_fu/metrics/rcov/simplecov_formatter.rb +13 -2
- data/lib/metric_fu/metrics/reek/{reek.rb → generator.rb} +0 -0
- data/lib/metric_fu/metrics/reek/{reek_grapher.rb → grapher.rb} +0 -0
- data/lib/metric_fu/metrics/reek/{reek_hotspot.rb → hotspot.rb} +1 -1
- data/lib/metric_fu/metrics/reek/{init.rb → metric.rb} +0 -0
- data/lib/metric_fu/metrics/reek/{template_awesome/reek.html.erb → report.html.erb} +0 -0
- data/lib/metric_fu/metrics/roodi/{roodi.rb → generator.rb} +0 -0
- data/lib/metric_fu/metrics/roodi/{roodi_grapher.rb → grapher.rb} +0 -0
- data/lib/metric_fu/metrics/roodi/{roodi_hotspot.rb → hotspot.rb} +0 -0
- data/lib/metric_fu/metrics/roodi/{init.rb → metric.rb} +0 -0
- data/lib/metric_fu/metrics/roodi/{template_awesome/roodi.html.erb → report.html.erb} +0 -0
- data/lib/metric_fu/metrics/saikuro/{saikuro.rb → generator.rb} +0 -0
- data/lib/metric_fu/metrics/saikuro/{saikuro_hotspot.rb → hotspot.rb} +0 -0
- data/lib/metric_fu/metrics/saikuro/{init.rb → metric.rb} +0 -0
- data/lib/metric_fu/metrics/saikuro/{template_awesome/saikuro.html.erb → report.html.erb} +0 -0
- data/lib/metric_fu/metrics/stats/{stats.rb → generator.rb} +1 -1
- data/lib/metric_fu/metrics/stats/{stats_grapher.rb → grapher.rb} +0 -0
- data/lib/metric_fu/metrics/stats/{stats_hotspot.rb → hotspot.rb} +0 -0
- data/lib/metric_fu/metrics/stats/{init.rb → metric.rb} +0 -0
- data/lib/metric_fu/metrics/stats/{template_awesome/stats.html.erb → report.html.erb} +0 -0
- data/lib/metric_fu/{metrics → reporting/graphs}/graph.rb +0 -0
- data/lib/metric_fu/{reporting/templates/awesome → templates}/_graph.html.erb +0 -0
- data/lib/metric_fu/{reporting/templates/awesome → templates}/_report_footer.html.erb +0 -0
- data/lib/metric_fu/templates/configuration.rb +3 -2
- data/lib/metric_fu/{reporting/templates/awesome → templates}/index.html.erb +1 -1
- data/lib/metric_fu/{reporting/templates → templates}/javascripts/bluff-min.js +0 -0
- data/lib/metric_fu/{reporting/templates → templates}/javascripts/bluff_graph.js +0 -0
- data/lib/metric_fu/{reporting/templates → templates}/javascripts/excanvas.js +0 -0
- data/lib/metric_fu/{reporting/templates → templates}/javascripts/highcharts.js +0 -0
- data/lib/metric_fu/{reporting/templates → templates}/javascripts/highcharts_graph.js +0 -0
- data/lib/metric_fu/{reporting/templates → templates}/javascripts/js-class.js +0 -0
- data/lib/metric_fu/{reporting/templates → templates}/javascripts/standalone-framework.js +0 -0
- data/lib/metric_fu/{reporting/templates → templates}/javascripts/utils.js +0 -0
- data/lib/metric_fu/{reporting/templates/awesome → templates}/layout.html.erb +1 -1
- data/lib/metric_fu/templates/metrics_template.rb +68 -0
- data/lib/metric_fu/templates/report.rb +11 -3
- data/lib/metric_fu/{metrics/base_template.rb → templates/template.rb} +8 -24
- data/lib/metric_fu/utility.rb +25 -0
- data/lib/metric_fu/version.rb +1 -1
- data/metric_fu.gemspec +2 -0
- data/spec/capture_warnings.rb +48 -0
- data/spec/dummy/lib/bad_encoding.rb +6 -0
- data/spec/fixtures/coverage-153.rb +11 -0
- data/spec/fixtures/rcov_output.txt +135 -0
- data/spec/metric_fu/configuration_spec.rb +4 -265
- data/spec/metric_fu/formatter/configuration_spec.rb +46 -0
- data/spec/metric_fu/formatter/html_spec.rb +17 -25
- data/spec/metric_fu/formatter/yaml_spec.rb +1 -1
- data/spec/metric_fu/{metrics/generator_spec.rb → generator_spec.rb} +0 -0
- data/spec/metric_fu/metrics/cane/configuration_spec.rb +22 -0
- data/spec/metric_fu/metrics/cane/{cane_spec.rb → generator_spec.rb} +1 -1
- data/spec/metric_fu/metrics/churn/configuration_spec.rb +15 -0
- data/spec/metric_fu/metrics/churn/{churn_spec.rb → generator_spec.rb} +1 -1
- data/spec/metric_fu/metrics/flay/configuration_spec.rb +15 -0
- data/spec/metric_fu/metrics/flay/{flay_spec.rb → generator_spec.rb} +2 -2
- data/spec/metric_fu/metrics/flay/{flay_grapher_spec.rb → grapher_spec.rb} +1 -1
- data/spec/metric_fu/metrics/flog/configuration_spec.rb +20 -0
- data/spec/metric_fu/metrics/flog/{flog_spec.rb → generator_spec.rb} +1 -1
- data/spec/metric_fu/metrics/flog/{flog_grapher_spec.rb → grapher_spec.rb} +1 -1
- data/spec/metric_fu/metrics/hotspots/{hotspots_spec.rb → generator_spec.rb} +1 -1
- data/spec/metric_fu/metrics/rails_best_practices/configuration_spec.rb +47 -0
- data/spec/metric_fu/metrics/rails_best_practices/{rails_best_practices_spec.rb → generator_spec.rb} +1 -1
- data/spec/metric_fu/metrics/rails_best_practices/{rails_best_practices_grapher_spec.rb → grapher_spec.rb} +1 -1
- data/spec/metric_fu/metrics/rcov/configuration_spec.rb +30 -0
- data/spec/metric_fu/metrics/rcov/generator_spec.rb +26 -0
- data/spec/metric_fu/metrics/rcov/{rcov_grapher_spec.rb → grapher_spec.rb} +1 -1
- data/spec/metric_fu/metrics/rcov/{rcov_hotspot_spec.rb → hotspot_spec.rb} +2 -2
- data/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +40 -12
- data/spec/metric_fu/metrics/reek/configuration_spec.rb +13 -0
- data/spec/metric_fu/metrics/reek/{reek_spec.rb → generator_spec.rb} +1 -1
- data/spec/metric_fu/metrics/reek/{reek_grapher_spec.rb → grapher_spec.rb} +1 -1
- data/spec/metric_fu/metrics/roodi/configuration_spec.rb +16 -0
- data/spec/metric_fu/metrics/roodi/{roodi_spec.rb → generator_spec.rb} +1 -1
- data/spec/metric_fu/metrics/roodi/{roodi_grapher_spec.rb → grapher_spec.rb} +1 -1
- data/spec/metric_fu/metrics/saikuro/configuration_spec.rb +26 -0
- data/spec/metric_fu/metrics/saikuro/{saikuro_spec.rb → generator_spec.rb} +1 -1
- data/spec/metric_fu/metrics/stats/{stats_spec.rb → generator_spec.rb} +1 -1
- data/spec/metric_fu/metrics/stats/{stats_grapher_spec.rb → grapher_spec.rb} +1 -1
- data/spec/metric_fu/{metrics → reporting/graphs}/graph_spec.rb +1 -1
- data/spec/metric_fu/run_spec.rb +1 -1
- data/spec/metric_fu/templates/configuration_spec.rb +57 -0
- data/spec/metric_fu/templates/report_spec.rb +15 -0
- data/spec/metric_fu/{metrics/base_template_spec.rb → templates/template_spec.rb} +0 -0
- data/spec/quality_spec.rb +86 -0
- data/spec/shared/configured.rb +47 -0
- data/spec/shared/test_coverage.rb +99 -0
- data/spec/spec_helper.rb +9 -5
- data/spec/support/helper_methods.rb +3 -2
- data/spec/support/matcher_create_file.rb +2 -2
- data/spec/support/matcher_create_files.rb +2 -2
- data/spec/support/usage_test.rb +24 -7
- data/spec/usage_test_spec.rb +28 -2
- metadata +165 -112
- metadata.gz.sig +0 -0
- data/Gemfile.devtools +0 -39
- data/lib/metric_fu/reporting/templates/awesome/awesome_template.rb +0 -62
- data/spec/metric_fu/metrics/rcov/rcov_spec.rb +0 -185
File without changes
|
@@ -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 <<
|
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"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
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] =
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -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='
|
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.
|
19
|
+
@data = File.open(file, 'rb') {|f| f.readlines }
|
11
20
|
end
|
12
21
|
|
13
|
-
def render
|
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 :
|
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
|
-
|
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
|
90
|
-
File.join(MetricFu.metrics_dir, metric,
|
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
|
-
|
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
|
data/lib/metric_fu/utility.rb
CHANGED
@@ -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
|
data/lib/metric_fu/version.rb
CHANGED
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
|