metric_fu 4.2.1 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.metrics +19 -1
- data/.travis.yml +2 -2
- data/Gemfile +2 -1
- data/HISTORY.md +24 -0
- data/README.md +60 -1
- data/TODO.md +1 -0
- data/bin/mf-saikuro +8 -0
- data/checksum/metric_fu-4.3.0.gem.sha512 +1 -0
- data/gemfiles/Gemfile.travis +9 -0
- data/lib/metric_fu.rb +1 -1
- data/lib/metric_fu/cli/client.rb +2 -2
- data/lib/metric_fu/cli/helper.rb +3 -3
- data/lib/metric_fu/cli/parser.rb +37 -16
- data/lib/metric_fu/configuration.rb +9 -1
- data/lib/metric_fu/constantize.rb +57 -0
- data/lib/metric_fu/data_structures/line_numbers.rb +19 -3
- data/lib/metric_fu/data_structures/location.rb +8 -3
- data/lib/metric_fu/formatter.rb +24 -0
- data/lib/metric_fu/formatter/html.rb +91 -0
- data/lib/metric_fu/formatter/yaml.rb +18 -0
- data/lib/metric_fu/initial_requires.rb +0 -1
- data/lib/metric_fu/io.rb +69 -0
- data/lib/metric_fu/load_files.rb +5 -2
- data/lib/metric_fu/logging/mf_debugger.rb +23 -0
- data/lib/metric_fu/metrics/base_template.rb +10 -4
- data/lib/metric_fu/metrics/cane/cane.rb +2 -1
- data/lib/metric_fu/metrics/cane/cane_bluff_grapher.rb +10 -9
- data/lib/metric_fu/metrics/cane/cane_gchart_grapher.rb +25 -0
- data/lib/metric_fu/metrics/flay/flay_bluff_grapher.rb +10 -9
- data/lib/metric_fu/metrics/flay/flay_gchart_grapher.rb +14 -11
- data/lib/metric_fu/metrics/flog/flog_bluff_grapher.rb +11 -10
- data/lib/metric_fu/metrics/flog/flog_gchart_grapher.rb +22 -15
- data/lib/metric_fu/metrics/generator.rb +10 -10
- data/lib/metric_fu/metrics/graph.rb +2 -2
- data/lib/metric_fu/metrics/hotspots/analysis/scoring_strategies.rb +3 -3
- data/lib/metric_fu/metrics/hotspots/hotspot.rb +4 -3
- data/lib/metric_fu/metrics/hotspots/hotspot_analyzer.rb +19 -10
- data/lib/metric_fu/metrics/hotspots/hotspots.rb +1 -1
- data/lib/metric_fu/metrics/hotspots/template_awesome/hotspots.html.erb +45 -45
- data/lib/metric_fu/metrics/rails_best_practices/rails_best_practices_bluff_grapher.rb +10 -9
- data/lib/metric_fu/metrics/rails_best_practices/rails_best_practices_gchart_grapher.rb +21 -15
- data/lib/metric_fu/metrics/rcov/rcov.rb +1 -1
- data/lib/metric_fu/metrics/rcov/rcov_bluff_grapher.rb +10 -9
- data/lib/metric_fu/metrics/rcov/rcov_gchart_grapher.rb +13 -8
- data/lib/metric_fu/metrics/reek/reek_bluff_grapher.rb +9 -13
- data/lib/metric_fu/metrics/reek/reek_gchart_grapher.rb +22 -17
- data/lib/metric_fu/metrics/roodi/roodi_bluff_grapher.rb +10 -9
- data/lib/metric_fu/metrics/roodi/roodi_gchart_grapher.rb +14 -11
- data/lib/metric_fu/metrics/saikuro/saikuro.rb +5 -34
- data/lib/metric_fu/metrics/stats/stats.rb +2 -1
- data/lib/metric_fu/metrics/stats/stats_bluff_grapher.rb +11 -10
- data/lib/metric_fu/metrics/stats/stats_gchart_grapher.rb +21 -14
- data/lib/metric_fu/reporter.rb +37 -0
- data/lib/metric_fu/reporting/graphs/engines/bluff.rb +20 -0
- data/lib/metric_fu/reporting/graphs/engines/gchart.rb +41 -3
- data/lib/metric_fu/reporting/graphs/grapher.rb +9 -2
- data/lib/metric_fu/reporting/result.rb +51 -0
- data/lib/metric_fu/reporting/templates/awesome/awesome_template.rb +8 -8
- data/lib/metric_fu/run.rb +34 -39
- data/lib/metric_fu/version.rb +1 -1
- data/lib/metric_fu_requires.rb +50 -33
- data/metric_fu.gemspec +30 -39
- data/spec/cli/helper_spec.rb +15 -0
- data/spec/metric_fu/configuration_spec.rb +40 -2
- data/spec/metric_fu/formatter/html_spec.rb +134 -0
- data/spec/metric_fu/formatter/yaml_spec.rb +59 -0
- data/spec/metric_fu/formatter_spec.rb +49 -0
- data/spec/metric_fu/metrics/base_template_spec.rb +23 -23
- data/spec/metric_fu/metrics/cane/cane_spec.rb +2 -2
- data/spec/metric_fu/metrics/churn/churn_spec.rb +1 -1
- data/spec/metric_fu/metrics/flay/flay_spec.rb +4 -4
- data/spec/metric_fu/metrics/flog/flog_spec.rb +7 -7
- data/spec/metric_fu/metrics/generator_spec.rb +21 -21
- data/spec/metric_fu/metrics/graph_spec.rb +9 -9
- data/spec/metric_fu/metrics/hotspots/hotspots_spec.rb +1 -1
- data/spec/metric_fu/metrics/rcov/rcov_spec.rb +8 -8
- data/spec/metric_fu/metrics/reek/reek_spec.rb +1 -1
- data/spec/metric_fu/metrics/saikuro/saikuro_spec.rb +5 -5
- data/spec/metric_fu/metrics/stats/stats_spec.rb +4 -4
- data/spec/metric_fu/reporter_spec.rb +41 -0
- data/spec/metric_fu/reporting/graphs/engines/gchart_spec.rb +7 -7
- data/spec/metric_fu/reporting/result_spec.rb +51 -0
- data/spec/run_spec.rb +167 -27
- data/spec/spec_helper.rb +1 -0
- data/spec/support/matcher_create_file.rb +7 -2
- data/spec/support/matcher_create_files.rb +41 -0
- data/spec/support/suite.rb +32 -0
- metadata +27 -6
- data/lib/metric_fu/reporting/report.rb +0 -111
- data/spec/metric_fu/reporting/report_spec.rb +0 -148
@@ -1,111 +0,0 @@
|
|
1
|
-
module MetricFu
|
2
|
-
|
3
|
-
# MetricFu.report memoizes access to a Report object, that will be
|
4
|
-
# used throughout the lifecycle of the MetricFu app.
|
5
|
-
def self.report
|
6
|
-
@report ||= Report.new
|
7
|
-
end
|
8
|
-
|
9
|
-
# = Report
|
10
|
-
#
|
11
|
-
# The Report class is responsible two things:
|
12
|
-
#
|
13
|
-
# It adds information to the yaml report, produced by the system
|
14
|
-
# as a whole, for each of the generators used in this test run.
|
15
|
-
#
|
16
|
-
# It also handles passing the information from each generator used
|
17
|
-
# in this test run out to the template class set in
|
18
|
-
# MetricFu::Configuration.
|
19
|
-
class Report
|
20
|
-
|
21
|
-
# Renders the result of the report_hash into a yaml serialization
|
22
|
-
# ready for writing out to a file.
|
23
|
-
#
|
24
|
-
# @return YAML
|
25
|
-
# A YAML object containing the results of the report generation
|
26
|
-
# process
|
27
|
-
def as_yaml
|
28
|
-
report_hash.to_yaml
|
29
|
-
end
|
30
|
-
|
31
|
-
def per_file_data
|
32
|
-
@per_file_data ||= {}
|
33
|
-
end
|
34
|
-
|
35
|
-
def report_hash #:nodoc:
|
36
|
-
@report_hash ||= {}
|
37
|
-
end
|
38
|
-
|
39
|
-
# Instantiates a new template class based on the configuration set
|
40
|
-
# in MetricFu::Configuration, or through the MetricFu.config block
|
41
|
-
# in your rake file (defaults to the included AwesomeTemplate),
|
42
|
-
# assigns the report_hash to the report_hash in the template, and
|
43
|
-
# tells the template to to write itself out.
|
44
|
-
def save_templatized_report
|
45
|
-
@template = MetricFu.template_class.new
|
46
|
-
@template.report = report_hash
|
47
|
-
@template.per_file_data = per_file_data
|
48
|
-
@template.write
|
49
|
-
end
|
50
|
-
|
51
|
-
# Adds a hash from a passed report, produced by one of the Generator
|
52
|
-
# classes to the aggregate report_hash managed by this hash.
|
53
|
-
#
|
54
|
-
# @param report_type Hash
|
55
|
-
# The hash to add to the aggregate report_hash
|
56
|
-
def add(report_type)
|
57
|
-
mf_debug "report requested #{report_type}"
|
58
|
-
clazz = MetricFu.const_get(report_type.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase })
|
59
|
-
mf_debug "report class found #{clazz}"
|
60
|
-
metric_options = MetricFu.send(report_type)
|
61
|
-
inst = clazz.new(metric_options)
|
62
|
-
|
63
|
-
report_hash.merge!(inst.generate_report)
|
64
|
-
|
65
|
-
inst.per_file_info(per_file_data) if inst.respond_to?(:per_file_info)
|
66
|
-
end
|
67
|
-
|
68
|
-
# Saves the passed in content to the passed in directory. If
|
69
|
-
# a filename is passed in it will be used as the name of the
|
70
|
-
# file, otherwise it will default to 'index.html'
|
71
|
-
#
|
72
|
-
# @param content String
|
73
|
-
# A string containing the content (usually html) to be written
|
74
|
-
# to the file.
|
75
|
-
#
|
76
|
-
# @param dir String
|
77
|
-
# A dir containing the path to the directory to write the file in.
|
78
|
-
#
|
79
|
-
# @param file String
|
80
|
-
# A filename to save the path as. Defaults to 'index.html'.
|
81
|
-
#
|
82
|
-
def save_output(content, dir, file='index.html')
|
83
|
-
open("#{dir}/#{file}", "w") do |f|
|
84
|
-
f.puts content
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# Checks to discover whether we should try and open the results
|
89
|
-
# of the report in the browser on this system. We only try and open
|
90
|
-
# in the browser if we're on OS X and we're not running in a
|
91
|
-
# CruiseControl.rb environment. See MetricFu.configuration for more
|
92
|
-
# details about how we make those guesses.
|
93
|
-
#
|
94
|
-
# @return Boolean
|
95
|
-
# Should we open in the browser or not?
|
96
|
-
def open_in_browser?
|
97
|
-
MetricFu.configuration.platform.include?('darwin') &&
|
98
|
-
! MetricFu.configuration.is_cruise_control_rb?
|
99
|
-
end
|
100
|
-
|
101
|
-
# Shows 'index.html' from the passed directory in the browser
|
102
|
-
# if we're able to open the browser on this platform.
|
103
|
-
#
|
104
|
-
# @param dir String
|
105
|
-
# The directory path where the 'index.html' we want to open is
|
106
|
-
# stored
|
107
|
-
def show_in_browser(dir)
|
108
|
-
system("open #{dir}/index.html") if open_in_browser?
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
@@ -1,148 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe MetricFu do
|
4
|
-
|
5
|
-
describe "#report" do
|
6
|
-
it 'should return an instance of Report' do
|
7
|
-
MetricFu.report.instance_of?(Report).should be(true)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe MetricFu::Report do
|
13
|
-
|
14
|
-
before(:each) do
|
15
|
-
@report = MetricFu::Report.new
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#as_yaml" do
|
19
|
-
it 'should call #report_hash' do
|
20
|
-
report_hash = mock('report_hash')
|
21
|
-
report_hash.should_receive(:to_yaml)
|
22
|
-
|
23
|
-
@report.should_receive(:report_hash).and_return(report_hash)
|
24
|
-
@report.as_yaml
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "#report_hash" do
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#save_templatized_report" do
|
32
|
-
it 'should create a new template class assign a report_hash '\
|
33
|
-
'to the template class, and ask it to write itself out' do
|
34
|
-
template_class = mock('template_class')
|
35
|
-
template_class.should_receive(:new).and_return(template_class)
|
36
|
-
MetricFu.should_receive(:template_class).and_return(template_class)
|
37
|
-
template_class.should_receive(:report=)
|
38
|
-
template_class.should_receive(:per_file_data=)
|
39
|
-
template_class.should_receive(:write)
|
40
|
-
@report.save_templatized_report
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "#add" do
|
45
|
-
it 'should add a passed hash to the report_hash instance variable' do
|
46
|
-
report_type = mock('report_type')
|
47
|
-
report_type.should_receive(:to_s).any_number_of_times.and_return('type')
|
48
|
-
|
49
|
-
report_inst = mock('report_inst')
|
50
|
-
report_type.should_receive(:new).and_return(report_inst)
|
51
|
-
|
52
|
-
report_inst.should_receive(:generate_report).and_return({:a => 'b'})
|
53
|
-
report_inst.should_receive(:respond_to?).and_return(false)
|
54
|
-
|
55
|
-
MetricFu.should_receive(:send).with(report_type).and_return({})
|
56
|
-
MetricFu.should_receive(:const_get).
|
57
|
-
with('Type').and_return(report_type)
|
58
|
-
report_hash = mock('report_hash')
|
59
|
-
report_hash.should_receive(:merge!).with({:a => 'b'})
|
60
|
-
@report.should_receive(:report_hash).and_return(report_hash)
|
61
|
-
@report.add(report_type)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "#save_output" do
|
66
|
-
it 'should write the passed content to dir/index.html' do
|
67
|
-
f = mock('file')
|
68
|
-
content = 'content'
|
69
|
-
@report.should_receive(:open).with('dir/file', 'w').and_yield(f)
|
70
|
-
f.should_receive(:puts).with(content)
|
71
|
-
@report.save_output(content, 'dir', 'file')
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#open_in_browser? ' do
|
76
|
-
|
77
|
-
before(:each) do
|
78
|
-
@config = mock('configuration')
|
79
|
-
end
|
80
|
-
|
81
|
-
describe 'when the platform is os x ' do
|
82
|
-
|
83
|
-
before(:each) do
|
84
|
-
@config.should_receive(:platform).and_return('darwin')
|
85
|
-
end
|
86
|
-
|
87
|
-
describe 'and we are in cruise control ' do
|
88
|
-
|
89
|
-
before(:each) do
|
90
|
-
@config.should_receive(:is_cruise_control_rb?).and_return(true)
|
91
|
-
MetricFu.stub!(:configuration).and_return(@config)
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should return false' do
|
95
|
-
@report.open_in_browser?.should be_false
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe 'and we are not in cruise control' do
|
100
|
-
|
101
|
-
before(:each) do
|
102
|
-
@config.should_receive(:is_cruise_control_rb?).and_return(false)
|
103
|
-
MetricFu.stub!(:configuration).and_return(@config)
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'should return true' do
|
107
|
-
@report.open_in_browser?.should be_true
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe 'when the platform is not os x ' do
|
113
|
-
before(:each) do
|
114
|
-
@config.should_receive(:platform).and_return('other')
|
115
|
-
end
|
116
|
-
|
117
|
-
describe 'and we are in cruise control' do
|
118
|
-
before(:each) do
|
119
|
-
MetricFu.stub!(:configuration).and_return(@config)
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'should return false' do
|
123
|
-
@report.open_in_browser?.should be_false
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe 'and we are not in cruise control' do
|
128
|
-
before(:each) do
|
129
|
-
MetricFu.stub!(:configuration).and_return(@config)
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'should return false' do
|
133
|
-
@report.open_in_browser?.should be_false
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
describe '#show_in_browser' do
|
141
|
-
it 'should call open with the passed directory' do
|
142
|
-
@report.should_receive(:open_in_browser?).and_return(true)
|
143
|
-
@report.should_receive(:system).with("open my_dir/index.html")
|
144
|
-
@report.show_in_browser('my_dir')
|
145
|
-
end
|
146
|
-
|
147
|
-
end
|
148
|
-
end
|