metric_fu 4.5.2 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46897614ca929038813939aee14aa38e21431508
4
- data.tar.gz: cc2c7c8b8e2f56cd7c21f1d9c48075de60ec1697
3
+ metadata.gz: d03acf0e261d588a802cd44d3f777942d397844b
4
+ data.tar.gz: 8cb84875a028571b062d807aa91a3f53a2ba2097
5
5
  SHA512:
6
- metadata.gz: 7da5faf38132acc88c0f438c7a5c280f2c6329667e2d94e91480b9a5990f3fc2a1dac4900769c8ef095a6c74af02271f765aec63401ecb77576724a90aba2706
7
- data.tar.gz: 999e1ca52251e8c5398348969b8c6dae0334cb3f432e9cc0225ac17b8c367c1384aa992b090d75e5c85d125b4c2faf579b8dab5dd43d60d8d060e175c84ff1e0
6
+ metadata.gz: cb45ff86efe04d805e5cd6f5effda3ea34efe76209146b9806a1de16ff2a52132da389c31d3302c2e042dc77f8693ea3a09d2bed3a1a1c47aaa805a9260888d0
7
+ data.tar.gz: 4fb34d3006988447c3b3568980296f236622a3cee744b72f2843bf31aed81e17b21ded0ec7b6f8293cc112df1a6393b347f7461c76d96beff6a8b2dc34cb337b
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/HISTORY.md CHANGED
@@ -10,6 +10,15 @@ As such, a _Feature_ would map to either major or minor. A _bug fix_ to a patch.
10
10
  * Fixes
11
11
  * Misc
12
12
 
13
+ ### MetricFu [4.6.0 / 2013-11-20](https://github.com/metricfu/metric_fu/compare/v4.5.2...v4.6.0)
14
+
15
+ * Features
16
+ * Allow configuration of the generation template, eg link_prefix (Adrien Montfort, #171)
17
+ * Fixes
18
+ * Return 0% coverage when the file has no lines. (Chirag Viradiya #152, Benjamin Fleischer, Michael Foley)
19
+ * Return stats code to test ratio of 0.0 when NaN (Benjamin Fleischer, reported by Greg Allen)
20
+ * Misc
21
+
13
22
  ### MetricFu [4.5.2 / 2013-11-07](https://github.com/metricfu/metric_fu/compare/v4.4.4...v4.5.2)
14
23
 
15
24
  * Misc
data/README.md CHANGED
@@ -208,3 +208,7 @@ This is the official repository for metric_fu. The original repository by Jake
208
208
  * Historical Homepage: http://metric-fu.rubyforge.org/
209
209
  * Jake's Blog: http://jakescruggs.blogspot.com/
210
210
  * Jake's Post about stepping down: http://jakescruggs.blogspot.com/2012/08/why-i-abandoned-metricfu.html
211
+
212
+
213
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/metricfu/metric_fu/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
214
+
@@ -0,0 +1 @@
1
+ cecb4dabfef6d7f955f394a9af5a8755cae4269196dfe6f4447f0d465426a8c4bb777572d3dc8404de352c0e64dd74562b6b8e65687ca79bdd247d3fbafe6e69
data/gem_tasks/build.rake CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'rubygems'
3
3
  require 'digest/sha2'
4
4
 
5
+ # Based on https://github.com/bundler/bundler/blob/ec0621d/lib/bundler/gem_helpers.rb
5
6
  GEM_TASKS = Class.new(Rake::TaskLib) do
6
7
  include Rake::DSL if defined? Rake::DSL
7
8
  attr_reader :base
@@ -53,7 +54,7 @@ GEM_TASKS = Class.new(Rake::TaskLib) do
53
54
  raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output" unless out[/Successfully installed/]
54
55
  STDOUT.puts "#{name} (#{version}) installed."
55
56
  end
56
-
57
+ # Based on https://github.com/YorickPeterse/ruby-lint/blob/3e946/task/checksum.rake
57
58
  def add_checksum(built_gem_path=nil)
58
59
  guard_clean
59
60
  built_gem_path ||= build_gem
@@ -184,6 +185,7 @@ GEM_TASKS = Class.new(Rake::TaskLib) do
184
185
 
185
186
  end.new.install
186
187
 
188
+ # Based on https://github.com/YorickPeterse/ruby-lint/blob/3e946e6/task/todo.rake
187
189
  desc 'Extracts TODO tags and the likes'
188
190
  task :todo do
189
191
  regex = %w{NOTE: FIXME: TODO: THINK: @todo}.join('|')
@@ -0,0 +1,11 @@
1
+ module MetricFu
2
+ module Calculate
3
+ module_function
4
+
5
+ def integer_percent(num, total)
6
+ return 0 if total.zero?
7
+ (Float(num) / Float(total) * 100).round
8
+ end
9
+
10
+ end
11
+ end
@@ -56,6 +56,8 @@ module MetricFu
56
56
  require_relative 'environment'
57
57
  require_relative 'io'
58
58
  require_relative 'formatter'
59
+ require_relative 'templates/configuration'
60
+
59
61
  # TODO: Remove need to include the module
60
62
  include MetricFu::Environment
61
63
 
@@ -75,7 +77,8 @@ module MetricFu
75
77
  # template/filesystem/metric/graph/environment, etc settings
76
78
  # from the configuration instance
77
79
  MetricFu::Io::FileSystem.set_directories
78
- MetricFu::Formatter::Templates.configure_template(self)
80
+ @templates_configuration = MetricFu::Templates::Configuration.new
81
+ MetricFu::Formatter::Templates.templates_configuration = @templates_configuration
79
82
  @formatters = []
80
83
  end
81
84
 
@@ -135,5 +138,22 @@ module MetricFu
135
138
  :bluff
136
139
  end
137
140
 
141
+ # This allows us to configure the templates with:
142
+ #
143
+ # MetricFu.run do |config|
144
+ # config.templates_configuration do |templates_config|
145
+ # templates_config.link_prefix = 'http:/'
146
+ # end
147
+ # end
148
+ def templates_configuration
149
+ yield @templates_configuration
150
+ end
151
+
152
+ # @param option [String, Symbol] the requested template option
153
+ # @return [String] the configured template option
154
+ def templates_option(option)
155
+ @templates_configuration.option(option)
156
+ end
157
+
138
158
  end
139
159
  end
@@ -25,21 +25,16 @@ module MetricFu
25
25
 
26
26
  module_function
27
27
 
28
- def options
29
- @options ||= {}
28
+ def templates_configuration=(templates_configuration)
29
+ @templates_configuration = templates_configuration
30
30
  end
31
+
31
32
  def option(name)
32
- options.fetch(name) { raise "No such template option: #{name}" }
33
+ templates_configuration.option(name)
33
34
  end
34
35
 
35
- # TODO: Remove config argument
36
- def configure_template(config)
37
- @options = {}
38
- @options['template_class'] = AwesomeTemplate
39
- @options['link_prefix'] = nil
40
- @options['darwin_txmt_protocol_no_thanks'] = true
41
- # # turning off syntax_highlighting may avoid some UTF-8 issues
42
- @options['syntax_highlighting'] = true
36
+ def templates_configuration
37
+ @templates_configuration ||= MetricFu::Templates::Configuration.new
43
38
  end
44
39
 
45
40
  end
@@ -175,15 +175,17 @@ module MetricFu
175
175
  def file_url(name, line) # :nodoc:
176
176
  return '' unless name
177
177
  filename = complete_file_path(name)
178
- link_prefix = MetricFu::Formatter::Templates.option('link_prefix')
179
- if link_prefix
180
- "#{link_prefix}/#{name.gsub(/:.*$/, '')}"
181
- elsif render_as_txmt_protocol?
178
+
179
+ if render_as_txmt_protocol?
182
180
  "txmt://open/?url=file://#{filename}" << (line ? "&line=#{line}" : "")
183
- # elsif render_as_mvim_protocol?
184
- # "mvim://open/?url=file://#{filename}" << (line ? "&line=#{line}" : "")
185
181
  else
186
- "file://#{filename}"
182
+ link_prefix = MetricFu.configuration.templates_option('link_prefix')
183
+ if link_prefix == MetricFu::Templates::Configuration::FILE_PREFIX
184
+ path = filename
185
+ else
186
+ path = name.gsub(/:.*$/, '')
187
+ end
188
+ "#{link_prefix}/#{path}"
187
189
  end
188
190
  end
189
191
 
@@ -197,15 +199,7 @@ module MetricFu
197
199
 
198
200
  def render_as_txmt_protocol? # :nodoc:
199
201
  if MetricFu.configuration.osx?
200
- !MetricFu::Formatter::Templates.option('darwin_txmt_protocol_no_thanks')
201
- else
202
- false
203
- end
204
- end
205
-
206
- def render_as_mvim_protocol? # :nodoc:
207
- if MetricFu.configuration.osx?
208
- !MetricFu::Formatter::Templates.option('darwin_mvim_protocol_no_thanks')
202
+ !MetricFu.configuration.templates_option('darwin_txmt_protocol_no_thanks')
209
203
  else
210
204
  false
211
205
  end
@@ -1,4 +1,5 @@
1
1
  MetricFu.lib_require { 'utility' }
2
+ MetricFu.lib_require { 'calculate' }
2
3
 
3
4
  module MetricFu
4
5
 
@@ -118,7 +119,8 @@ module MetricFu
118
119
  files.each_pair {|fname, content| files[fname] = content.split("\n") }
119
120
  files.each_pair do |fname, content|
120
121
  content.map! do |raw_line|
121
- Line.new(raw_line[3..-1], !raw_line.match(/^!!/)).to_h
122
+ covered_line = raw_line.match(/^!!/).nil?
123
+ Line.new(raw_line[3..-1], covered_line).to_h
122
124
  end
123
125
  content.reject! {|line| line[:content].to_s == '' }
124
126
  files[fname] = {:lines => content}
@@ -126,13 +128,19 @@ module MetricFu
126
128
  files
127
129
  end
128
130
 
131
+ # TODO: remove multiple side effects
132
+ # sets global ivars and
133
+ # modifies the param passed in
129
134
  def add_coverage_percentage(files)
130
135
  files.each_pair do |fname, content|
131
136
  lines = content[:lines]
132
- @global_total_lines_run += lines_run = lines.find_all {|line| line[:was_run] == true }.length
133
- @global_total_lines += total_lines = lines.length
134
- percent_run = ((lines_run.to_f / total_lines.to_f) * 100).round
135
- files[fname][:percent_run] = percent_run
137
+ lines_run = lines.count {|line| line[:was_run] }
138
+ total_lines = lines.length
139
+ integer_percent = Calculate.integer_percent(lines_run, total_lines)
140
+
141
+ files[fname][:percent_run] = integer_percent
142
+ @global_total_lines_run += lines_run
143
+ @global_total_lines += total_lines
136
144
  end
137
145
  end
138
146
 
@@ -39,10 +39,16 @@ module MetricFu
39
39
 
40
40
  def set_global_stats(totals)
41
41
  return if totals.nil?
42
- totals = totals.split(" ").find_all {|el| ! el.empty? }
43
- @stats[:codeLOC] = totals[0].match(/\d.*/)[0].to_i
44
- @stats[:testLOC] = totals[1].match(/\d.*/)[0].to_i
45
- @stats[:code_to_test_ratio] = totals[2].match(/1\:(\d.*)/)[1].to_f
42
+ parsed_totals = totals.split(" ").find_all {|el| ! el.empty? }
43
+ @stats[:codeLOC] = parsed_totals.shift.match(/\d.*/)[0].to_i
44
+ @stats[:testLOC] = parsed_totals.shift.match(/\d.*/)[0].to_i
45
+ matched_numbers = Array(parsed_totals.shift.match(/1\:(\d.*)/))
46
+ if matched_numbers.size == 2
47
+ @stats[:code_to_test_ratio] = matched_numbers[1].to_f
48
+ else
49
+ mf_log "Unexpected code to test ratio #{matched_numbers.inspect} over directories #{dirs.inspect}"
50
+ @stats[:code_to_test_ratio] = 0.0
51
+ end
46
52
  end
47
53
 
48
54
  def set_granular_stats(lines)
@@ -0,0 +1,27 @@
1
+ module MetricFu::Templates
2
+ class Configuration
3
+
4
+ FILE_PREFIX = 'file:/'
5
+
6
+ def initialize
7
+ @options = {}
8
+ @options[:template_class] = AwesomeTemplate
9
+ @options[:darwin_txmt_protocol_no_thanks] = true
10
+ # turning off syntax_highlighting may avoid some UTF-8 issues
11
+ @options[:syntax_highlighting] = true
12
+ @options[:link_prefix] = FILE_PREFIX
13
+ end
14
+
15
+ [:template_class, :link_prefix, :syntax_highlighting, :darwin_txmt_protocol_no_thanks].each do |option|
16
+ define_method("#{option}=") do |arg|
17
+ @options[option] = arg
18
+ end
19
+ end
20
+
21
+ def option(name)
22
+ @options.fetch(name.to_sym) { raise "No such template option: #{name}" }
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -1,3 +1,3 @@
1
1
  module MetricFu
2
- VERSION = '4.5.2'
2
+ VERSION = '4.6.0'
3
3
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ MetricFu.lib_require { 'calculate' }
3
+
4
+ describe MetricFu::Calculate do
5
+ describe "returns a percent rounded to the nearest integer" do
6
+ specify "3 / 10 == 30" do
7
+ expect(MetricFu::Calculate.integer_percent(3, 10)).to eq(30)
8
+ end
9
+ specify "3.0 / 10 == 30" do
10
+ expect(MetricFu::Calculate.integer_percent(3.0, 10)).to eq(30)
11
+ end
12
+ it "raises an ArgumentError on non-numeric input" do
13
+ expect {
14
+ MetricFu::Calculate.integer_percent("", 10)
15
+ }.to raise_error(ArgumentError)
16
+ end
17
+ it "returns 0 when the denominator is 0" do
18
+ expect(MetricFu::Calculate.integer_percent(3,0)).to eq(0)
19
+ end
20
+ end
21
+ end
@@ -132,10 +132,41 @@ describe MetricFu::Configuration do
132
132
  output_directory.should == output_dir
133
133
  end
134
134
 
135
- it 'should set @template_class to AwesomeTemplate' do
135
+ it 'should set @template_class to AwesomeTemplate by default' do
136
136
  template_class.should == AwesomeTemplate
137
137
  end
138
138
 
139
+ describe 'when a templates configuration is given' do
140
+
141
+ before do
142
+ class DummyTemplate;end
143
+
144
+ @config.templates_configuration do |config|
145
+ config.template_class = DummyTemplate
146
+ config.link_prefix = 'http:/'
147
+ config.syntax_highlighting = false
148
+ config.darwin_txmt_protocol_no_thanks = false
149
+ end
150
+ end
151
+
152
+ it 'should set given template_class' do
153
+ expect(template_class).to eq(DummyTemplate)
154
+ end
155
+
156
+ it 'should set given link_prefix' do
157
+ expect(MetricFu::Formatter::Templates.option('link_prefix')).to eq('http:/')
158
+ end
159
+
160
+ it 'should set given darwin_txmt_protocol_no_thanks' do
161
+ expect(MetricFu::Formatter::Templates.option('darwin_txmt_protocol_no_thanks')).to be_false
162
+ end
163
+
164
+ it 'should set given syntax_highlighting' do
165
+ expect(MetricFu::Formatter::Templates.option('syntax_highlighting')).to be_false
166
+ end
167
+
168
+ end
169
+
139
170
  it 'should set @flay to {:dirs_to_flay => @code_dirs}' do
140
171
  load_metric 'flay'
141
172
  expect(MetricFu::Metric.get_metric(:flay).run_options).to eq(
@@ -90,8 +90,8 @@ describe MetricFu::Template do
90
90
  config = double("configuration")
91
91
  config.stub(:osx?).and_return(true)
92
92
  config.stub(:platform).and_return('universal-darwin-9.0')
93
- MetricFu::Formatter::Templates.stub(:option).with('darwin_txmt_protocol_no_thanks').and_return(false)
94
- MetricFu::Formatter::Templates.stub(:option).with('link_prefix').and_return(nil)
93
+ config.stub(:templates_option).with('darwin_txmt_protocol_no_thanks').and_return(false)
94
+ config.stub(:templates_option).with('link_prefix').and_return(nil)
95
95
  MetricFu.stub(:configuration).and_return(config)
96
96
  end
97
97
 
@@ -121,9 +121,8 @@ describe MetricFu::Template do
121
121
  config = double("configuration")
122
122
  config.stub(:osx?).and_return(true)
123
123
  config.stub(:platform).and_return('universal-darwin-9.0')
124
- config.stub(:link_prefix).and_return(nil)
125
- MetricFu::Formatter::Templates.stub(:option).with('darwin_txmt_protocol_no_thanks').and_return(true)
126
- MetricFu::Formatter::Templates.stub(:option).with('link_prefix').and_return(nil)
124
+ config.stub(:templates_option).with('darwin_txmt_protocol_no_thanks').and_return(true)
125
+ config.stub(:templates_option).with('link_prefix').and_return('file:/')
127
126
  MetricFu.stub(:configuration).and_return(config)
128
127
  @template.should_receive(:complete_file_path).and_return('filename')
129
128
  end
@@ -149,7 +148,7 @@ describe MetricFu::Template do
149
148
  before(:each) do
150
149
  config = double("configuration")
151
150
  config.should_receive(:osx?).and_return(false)
152
- MetricFu::Formatter::Templates.stub(:option).with('link_prefix').and_return(nil)
151
+ config.stub(:templates_option).with('link_prefix').and_return('file:/')
153
152
  MetricFu.stub(:configuration).and_return(config)
154
153
  @template.should_receive(:complete_file_path).and_return('filename')
155
154
  end
@@ -163,7 +162,9 @@ describe MetricFu::Template do
163
162
  describe "when configured with a link_prefix" do
164
163
  before(:each) do
165
164
  config = double("configuration")
166
- MetricFu::Formatter::Templates.stub(:option).with('link_prefix').and_return('http://example.org/files')
165
+ config.stub(:templates_option).with('darwin_txmt_protocol_no_thanks').and_return(true)
166
+ config.stub(:templates_option).with('link_prefix').and_return('http://example.org/files')
167
+ config.stub(:osx?).and_return(true)
167
168
  MetricFu.stub(:configuration).and_return(config)
168
169
  @template.should_receive(:complete_file_path).and_return('filename')
169
170
  end
@@ -61,6 +61,24 @@ describe StatsGenerator do
61
61
  model_data[:methods_per_class].should == 3
62
62
  model_data[:loc_per_method].should == 7
63
63
  end
64
+
65
+ it 'handles code to test ratio is ratio is 1:NaN' do
66
+ lines = <<-HERE.gsub(/^\s*/, "")
67
+ +----------------------+-------+-------+---------+---------+-----+-------+
68
+ | Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
69
+ +----------------------+-------+-------+---------+---------+-----+-------+
70
+ +----------------------+-------+-------+---------+---------+-----+-------+
71
+ Code LOC: 0 Test LOC: 0 Code to Test Ratio: 1:NaN
72
+
73
+ HERE
74
+ ENV['CC_BUILD_ARTIFACTS'] = nil
75
+ MetricFu.configure.reset
76
+ File.stub(:directory?).and_return(true)
77
+ stats = MetricFu::StatsGenerator.new(MetricFu::Metric.get_metric(:stats).run_options)
78
+ stats.instance_variable_set('@output', lines)
79
+ @results = stats.analyze
80
+ expect(@results[:code_to_test_ratio]).to eq(0.0)
81
+ end
64
82
  end
65
83
 
66
84
  describe "to_h method" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metric_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.2
4
+ version: 4.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Scruggs
@@ -42,7 +42,7 @@ cert_chain:
42
42
  WONz9vT6h053kHZYMrd4Gs/NdaA4tJSxrhZlXdajAm/0vAOzLIqUHHQk3R0tf7aY
43
43
  d/w=
44
44
  -----END CERTIFICATE-----
45
- date: 2013-11-08 00:00:00.000000000 Z
45
+ date: 2013-11-20 00:00:00.000000000 Z
46
46
  dependencies:
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: flay
@@ -296,10 +296,12 @@ files:
296
296
  - checksum/metric_fu-4.4.4.gem.sha512
297
297
  - checksum/metric_fu-4.5.0.gem.sha512
298
298
  - checksum/metric_fu-4.5.1.gem.sha512
299
+ - checksum/metric_fu-4.5.2.gem.sha512
299
300
  - config/roodi_config.yml
300
301
  - gem_tasks/build.rake
301
302
  - gemfiles/Gemfile.travis
302
303
  - lib/metric_fu.rb
304
+ - lib/metric_fu/calculate.rb
303
305
  - lib/metric_fu/cli/client.rb
304
306
  - lib/metric_fu/cli/helper.rb
305
307
  - lib/metric_fu/cli/parser.rb
@@ -407,6 +409,7 @@ files:
407
409
  - lib/metric_fu/reporting/templates/javascripts/js-class.js
408
410
  - lib/metric_fu/run.rb
409
411
  - lib/metric_fu/tasks/metric_fu.rake
412
+ - lib/metric_fu/templates/configuration.rb
410
413
  - lib/metric_fu/utility.rb
411
414
  - lib/metric_fu/version.rb
412
415
  - metric_fu.gemspec
@@ -435,6 +438,7 @@ files:
435
438
  - spec/fixtures/saikuro/app/controllers/users_controller.rb_cyclo.html
436
439
  - spec/fixtures/saikuro/index_cyclo.html
437
440
  - spec/fixtures/saikuro_sfiles/thing.rb_cyclo.html
441
+ - spec/metric_fu/calculate_spec.rb
438
442
  - spec/metric_fu/configuration_spec.rb
439
443
  - spec/metric_fu/data_structures/line_numbers_spec.rb
440
444
  - spec/metric_fu/data_structures/location_spec.rb
@@ -537,6 +541,7 @@ test_files:
537
541
  - spec/fixtures/saikuro/app/controllers/users_controller.rb_cyclo.html
538
542
  - spec/fixtures/saikuro/index_cyclo.html
539
543
  - spec/fixtures/saikuro_sfiles/thing.rb_cyclo.html
544
+ - spec/metric_fu/calculate_spec.rb
540
545
  - spec/metric_fu/configuration_spec.rb
541
546
  - spec/metric_fu/data_structures/line_numbers_spec.rb
542
547
  - spec/metric_fu/data_structures/location_spec.rb
metadata.gz.sig CHANGED
Binary file