coverband 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ module Coverband
4
4
  def initialize(app, settings={})
5
5
  @app = app
6
6
  root = settings[:root] || './'
7
- @project_directory = File.expand_path(root+'../')
7
+ @project_directory = File.expand_path(root)
8
8
  @enabled = true
9
9
  @function_set = false
10
10
  @files = {}
@@ -8,7 +8,7 @@ module Coverband
8
8
  require 'coverage'
9
9
  Coverage.start
10
10
  yield
11
- @project_directory = File.expand_path(Dir.pwd+'../')
11
+ @project_directory = File.expand_path(Dir.pwd)
12
12
  results = Coverage.result
13
13
  results = results.reject{|key, val| !key.match(@project_directory)}
14
14
  puts results.inspect
@@ -17,8 +17,12 @@ module Coverband
17
17
  end
18
18
 
19
19
  def self.report(redis, options = {})
20
+ roots = options.fetch(:roots){[]}
21
+ existing_coverage = options.fetch(:existing_coverage){ {} }
22
+ roots << "#{File.expand_path(Dir.pwd)}/"
23
+ puts "fixing root: #{roots.join(', ')}"
20
24
  if options.fetch(:reporter){ 'rcov' }=='rcov'
21
- report_rcov(redis, options['existing_coverage'])
25
+ report_rcov(redis, existing_coverage, roots)
22
26
  else
23
27
  redis.smembers('coverband').each{|key| report_line(redis, key) }
24
28
  end
@@ -26,11 +30,22 @@ module Coverband
26
30
 
27
31
  private
28
32
 
29
- def self.report_rcov(redis, existing_coverage)
33
+ def self.fix_file_names(report_hash, roots)
34
+ fixed_report = {} #normalize names across servers
35
+ report_hash.each_pair do |key, values|
36
+ filename = filename_from_key(key, roots)
37
+ fixed_report[filename] = values
38
+ end
39
+ fixed_report
40
+ end
41
+
42
+ def self.report_rcov(redis, existing_coverage, roots)
30
43
  rcov_style_report = {}
31
- redis.smembers('coverband').each{|key| line_data = line_hash(redis, key); rcov_style_report.merge!(line_data) if line_data }
44
+ redis.smembers('coverband').each{|key| line_data = line_hash(redis, key, roots); rcov_style_report.merge!(line_data) if line_data }
45
+ rcov_style_report = fix_file_names(rcov_style_report, roots)
46
+ existing_coverage = fix_file_names(existing_coverage, roots)
32
47
  rcov_style_report = merge_existing_coverage(rcov_style_report, existing_coverage)
33
- puts "report:"
48
+ puts "report: "
34
49
  puts rcov_style_report.inspect
35
50
  SimpleCov::Result.new(rcov_style_report).format!
36
51
  `open coverage/index.html`
@@ -61,10 +76,19 @@ module Coverband
61
76
  puts "#{key.gsub('.','/')}: #{redis.smembers("coverband#{key}").inspect}"
62
77
  end
63
78
 
79
+ def self.filename_from_key(key, roots)
80
+ filename = key.gsub('.','/').gsub('//','./').gsub('/rb','.rb').gsub('/erb','.erb')
81
+ roots.each do |root|
82
+ filename = filename.gsub(root, './')
83
+ end
84
+ filename = filename.gsub('./', roots.last)
85
+ filename
86
+ end
87
+
64
88
  # >> puts Coverage.result.inspect
65
89
  # {"/Users/danmayer/projects/hearno/script/tester.rb"=>[1, nil, 1, 1, nil, nil, nil]}
66
- def self.line_hash(redis, key)
67
- filename = key.gsub('.','/').gsub('/rb','.rb').gsub('/erb','.erb')
90
+ def self.line_hash(redis, key, roots)
91
+ filename = filename_from_key(key, roots)
68
92
  if File.exists?(filename)
69
93
  lines_hit = redis.smembers("coverband#{key}")
70
94
  count = File.foreach(filename).inject(0) {|c, line| c+1}
@@ -1,3 +1,3 @@
1
1
  module Coverband
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coverband
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-09 00:00:00.000000000 Z
12
+ date: 2013-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  segments:
110
110
  - 0
111
- hash: 1958954660094686763
111
+ hash: -1569723320352132712
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  segments:
119
119
  - 0
120
- hash: 1958954660094686763
120
+ hash: -1569723320352132712
121
121
  requirements: []
122
122
  rubyforge_project:
123
123
  rubygems_version: 1.8.25