duvet 0.3.0 → 0.3.1

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.
data/README.md CHANGED
@@ -14,7 +14,8 @@ You can change the defaults by passing an options hash to Duvet.start, eg
14
14
  Duvet.start :dir => 'coverage', :filter => 'app/lib'
15
15
 
16
16
  `:dir` is the directory to write the coverage to.
17
- `:filter` allows you to display only coverage for files that include the string.
17
+ `:filter` allows you to display only coverage for files that include the string, or you can
18
+ match against a regular expression for more control.
18
19
 
19
20
  You can see what the output of running duvet on itself is [here](http://hawx.github.com/duvet).
20
21
 
data/lib/duvet.rb CHANGED
@@ -1,12 +1,10 @@
1
- $: << File.join(File.dirname(__FILE__), '..')
2
-
3
1
  # Add this to test/helper.rb at the before __anything__ else
4
2
  #
5
3
  # require 'duvet'
6
4
  # Duvet.start
7
5
  #
6
+
8
7
  require 'coverage'
9
- require 'ostruct'
10
8
  require 'pathname'
11
9
  require 'haml'
12
10
  require 'sass'
@@ -22,7 +20,13 @@ module Duvet
22
20
 
23
21
  DEFAULTS = {:dir => 'cov', :style => 'rcov'}
24
22
 
25
- TEMPLATE_PATH = File.join File.dirname(__FILE__), '..', 'templates'
23
+ TEMPLATE_PATH = Pathname.new(__FILE__).dirname + '..' + 'templates'
24
+
25
+ TEMPLATE_HASH = {
26
+ 'time' => Time.now,
27
+ 'version' => VERSION,
28
+ 'name' => 'duvet'
29
+ }
26
30
 
27
31
  # Start tracking
28
32
  def self.start(opts={})
@@ -37,8 +41,9 @@ module Duvet
37
41
  cov = Coverage.result if running?
38
42
  if @opts[:filter]
39
43
  filtered = {}
44
+ @opts[:filter] = /#{@opts[:filter]}/ unless @opts[:filter].is_a?(Regexp)
40
45
  cov.each do |k, v|
41
- if k.include?(@opts[:filter])
46
+ if @opts[:filter] =~ k
42
47
  filtered[k] = v
43
48
  end
44
49
  end
@@ -51,7 +56,7 @@ module Duvet
51
56
 
52
57
  # Write results
53
58
  def self.write
54
- self.result.write(@opts[:dir], @opts[:style]) if running?
59
+ self.result.write(Pathname.new(@opts[:dir])) if running?
55
60
  end
56
61
 
57
62
  # Proc to call when exiting
@@ -64,15 +69,6 @@ module Duvet
64
69
  def self.running?
65
70
  @running
66
71
  end
67
-
68
- # @return [Hash] hash to merge for templating
69
- def self.template_hash
70
- {
71
- 'time' => Time.now,
72
- 'version' => VERSION,
73
- 'name' => 'duvet'
74
- }
75
- end
76
72
 
77
73
  end
78
74
 
@@ -15,14 +15,3 @@ class Pathname
15
15
  end
16
16
 
17
17
  end
18
-
19
- class String
20
-
21
- # Converts the String to a Pathname object
22
- #
23
- # @return [Pathname]
24
- def to_p
25
- Pathname.new(self)
26
- end
27
-
28
- end
data/lib/duvet/cov.rb CHANGED
@@ -91,14 +91,13 @@ module Duvet
91
91
  def format
92
92
  template = File.read File.join(TEMPLATE_PATH, 'html', 'file.haml')
93
93
  haml_engine = Haml::Engine.new(template)
94
- output = haml_engine.render(nil, Duvet.template_hash.merge(self.data))
94
+ output = haml_engine.render(nil, TEMPLATE_HASH.merge(self.data))
95
95
  output
96
96
  end
97
97
 
98
- def write(dir='cov')
99
- pa = (dir.to_p + @path.file_name).to_s + '.html'
100
- File.new(pa, 'w')
101
- File.open(pa, 'w') {|f| f.puts(self.format) }
98
+ def write(dir)
99
+ path = (dir + @path.file_name).to_s + '.html'
100
+ File.open(path, 'w') {|f| f.write(self.format) }
102
101
  end
103
102
 
104
103
  end
data/lib/duvet/covs.rb CHANGED
@@ -9,107 +9,43 @@ module Duvet
9
9
  end
10
10
 
11
11
  def report
12
- self.each do |i|
13
- puts i.report
14
- end
15
- end
16
-
17
- def format
18
- self.each do |i|
19
- puts i.format
20
- end
21
- end
22
-
23
-
24
- # @group Totals
25
-
26
- # @return [Integer]
27
- def total_lines
28
- self.inject(0) {|a, e| a + e.lines.size }
29
- end
30
-
31
- # @return [Integer]
32
- def total_code_lines
33
- self.inject(0) {|a, e| a + e.code_lines.size }
34
- end
35
-
36
- # @return [Integer]
37
- def total_ran_lines
38
- self.inject(0) {|a, e| a + e.ran_lines.size }
12
+ map {|i| i.report }.join('')
39
13
  end
40
14
 
41
- # @return [String] total lines run / total lines, as percentage
42
- def total_total_cov
43
- "%.2f%" % (total_ran_lines.to_f / total_lines.to_f*100)
44
- end
45
-
46
- # @return [String] total lines run / total lines of code, as percentage
47
- def total_code_cov
48
- "%.2f%" % (total_ran_lines.to_f / total_code_lines.to_f*100)
49
- end
50
-
51
- # @endgroup
52
-
53
-
54
15
  def data
55
- r = []
56
- self.each do |i|
57
- r << i.data
58
- end
59
- {
60
- 'files' => r,
61
- 'total' => {
62
- 'lines' => total_lines,
63
- 'lines_code' => total_code_lines,
64
- 'lines_ran' => total_ran_lines,
65
- 'total_cov' => total_total_cov,
66
- 'code_cov' => total_code_cov
67
- }
68
- }
16
+ { 'files' => map {|i| i.data } }
69
17
  end
70
18
 
71
- def format(dir='cov')
72
- template = File.read File.join(TEMPLATE_PATH, 'html', 'index.haml')
19
+ def format
20
+ template = (TEMPLATE_PATH + 'html' + 'index.haml').read
73
21
  haml_engine = Haml::Engine.new(template)
74
- output = haml_engine.render(nil, Duvet.template_hash.merge(self.data))
75
- output
22
+ haml_engine.render(nil, TEMPLATE_HASH.merge(self.data))
76
23
  end
77
24
 
78
- def write(dir='cov', style='rcov')
79
- if self.size > 0
80
- FileUtils.mkdir_p dir
81
-
82
- f = File.new( dir.to_p + 'index.html', "w")
83
- f.write(format)
25
+ def write(dir)
26
+ if size > 0
27
+ FileUtils.mkdir_p(dir)
28
+ File.open(dir + 'index.html', 'w') {|f| f.write(format) }
29
+
30
+ each {|c| c.write(dir) }
84
31
 
85
- self.each do |i|
86
- i.write(dir)
87
- end
88
- write_resources(dir, style)
32
+ write_resources(dir)
89
33
  else
90
- warn "no files"
34
+ warn "No files to create coverage for."
91
35
  end
92
36
  end
93
37
 
94
38
  # @todo Allow you to change style used
95
- def write_resources(dir, style)
96
- js_dir = File.join(TEMPLATE_PATH, 'js')
97
- css_dir = File.join(TEMPLATE_PATH, 'css')
98
-
99
- Dir.glob("#{css_dir}/*").each do |i|
100
- if i.include?(style)
101
- write_path = dir.to_p + 'styles.css'
102
- f = File.new(write_path, "w")
103
- f.write Sass::Engine.new( File.read(i) ).render
104
- end
105
- end
106
-
107
- Dir.glob("#{js_dir}/*").each do |i|
108
- write_path = dir.to_p + i.to_p.basename
109
- f = File.new(write_path, "w")
110
- f.write(File.read(i))
39
+ def write_resources(dir)
40
+ Pathname.glob(TEMPLATE_PATH + 'css' + '*').each do |i|
41
+ f = File.new(dir + 'styles.css', 'w')
42
+ f.write Sass::Engine.new(i.read).render
111
43
  end
112
44
 
45
+ Pathname.glob(TEMPLATE_PATH + 'js' + '*').each do |i|
46
+ f = File.new(dir + i.basename, 'w')
47
+ f.write(i.read)
48
+ end
113
49
  end
114
50
 
115
51
  end
data/lib/duvet/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Duvet
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
File without changes
@@ -28,11 +28,11 @@
28
28
  %tfoot
29
29
  %tr{:class => "totals"}
30
30
  %td Total
31
- %td{:class => "lines"}= total['lines']
32
- %td{:class => "loc"}= total['lines_code']
33
- %td{:class => "ran"}= total['lines_ran']
34
- %td{:class => "cov"}= total['total_cov']
35
- %td{:class => "code"}= total['code_cov']
31
+ %td{:class => "lines"}
32
+ %td{:class => "loc"}
33
+ %td{:class => "ran"}
34
+ %td{:class => "cov"}
35
+ %td{:class => "code"}
36
36
 
37
37
  %tbody
38
38
  - files.each do |f|
data/templates/js/main.js CHANGED
@@ -1,9 +1,7 @@
1
1
  $(document).ready(function() {
2
-
3
- t = $('table.sort');
4
2
 
5
3
  $('#filter').keyup(function() {
6
- $.uiTableFilter(t, this.value);
4
+ $.uiTableFilter($('table.sort'), this.value);
7
5
  calculate_totals();
8
6
  });
9
7
 
@@ -17,7 +15,7 @@ $(document).ready(function() {
17
15
 
18
16
  // Need to get the cov and code totals to be weighted, if possible, to
19
17
  // the number of lines as in the ruby.
20
- function calculate_totals(col) {
18
+ function calculate_totals() {
21
19
  var sum = 0;
22
20
  var rows = [];
23
21
 
@@ -52,5 +50,7 @@ $(document).ready(function() {
52
50
  $('table.sort tfoot td.code').text('0.00%');
53
51
  }
54
52
  }
53
+
54
+ calculate_totals();
55
55
 
56
56
  });
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duvet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: haml
17
- requirement: &2153468120 !ruby/object:Gem::Requirement
17
+ requirement: &2152746840 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.0.25
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2153468120
25
+ version_requirements: *2152746840
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: thoughtbot-shoulda
28
- requirement: &2153467660 !ruby/object:Gem::Requirement
28
+ requirement: &2152746380 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2153467660
36
+ version_requirements: *2152746380
37
37
  description: ! " A simple code coverage tool for Ruby 1.9. Add 'Duvet.start' to
38
38
  the top\n of your test helper, to have it write code coverage stuff to 'cov/'.\n"
39
39
  email: m@hawx.me
@@ -47,12 +47,9 @@ files:
47
47
  - lib/duvet/core_ext.rb
48
48
  - lib/duvet/cov.rb
49
49
  - lib/duvet/covs.rb
50
- - lib/duvet/test_helper.rb
51
50
  - lib/duvet/version.rb
52
51
  - lib/duvet.rb
53
- - templates/css/dark.sass
54
- - templates/css/light.sass
55
- - templates/css/rcov.sass
52
+ - templates/css/styles.sass
56
53
  - templates/html/file.haml
57
54
  - templates/html/index.haml
58
55
  - templates/js/jquery.js
@@ -1,16 +0,0 @@
1
- # Allows duvet to generate it's own code coverage
2
-
3
- require 'coverage'
4
-
5
- module Duvet
6
-
7
- DEFAULTS = {:dir => 'cov', :style => 'rcov'}
8
-
9
- def self.start(opts={})
10
- @opts = DEFAULTS.merge(opts)
11
-
12
- Coverage.start
13
- @running = true
14
- end
15
-
16
- end
@@ -1,166 +0,0 @@
1
- $text: #ddd
2
-
3
- $black: #222
4
- $dark-grey: #111
5
- $light-grey: #ccc
6
- $white: #ddd
7
-
8
- $excluded: #bbb
9
- $unran: #ce5256
10
- $ran: #8dd291
11
-
12
- // Main
13
- body
14
- background: $black
15
- color: $white
16
- font: 12px/1.3em Helvetica
17
- text-shadow: 0 1px 0 rgba(0, 0, 0, .5)
18
-
19
- a
20
- text-decoration: none
21
-
22
-
23
- // Header
24
- header
25
- margin: 2em .5em
26
-
27
- h1, h1 a
28
- color: $light-grey
29
- font-weight: normal
30
-
31
- h2
32
- color: darken($light-grey, 20%)
33
- font-size: 16px
34
- font-weight: normal
35
-
36
- // Filter/Search Box
37
- #filter
38
- position: absolute
39
- color: $white
40
- top: 20px
41
- right: 8px
42
- border: 1px solid darken($light-grey, 50%)
43
- background: $black
44
- -webkit-border-radius: 5px
45
- padding: 3px
46
-
47
-
48
- // Table
49
- .table-wrapper
50
- min-width: 700px
51
-
52
- table
53
- border: 1px solid darken($light-grey, 50%)
54
- background: $dark-grey
55
- border-collapse: collapse
56
- width: 100%
57
- margin-bottom: 1em
58
-
59
- table.source, pre, code
60
- font: 11px/1.2em Menlo
61
-
62
- td pre
63
- margin: 0
64
-
65
-
66
- // Summary
67
- .summary
68
- margin-bottom: 1em
69
- background: lighten($dark-grey, 10%)
70
-
71
- tbody
72
- .name, .name a
73
- color: $text
74
-
75
- tbody tr:hover
76
- background: lighten($dark-grey, 15%)
77
-
78
- thead
79
- background: $dark-grey
80
- color: $light-grey
81
- border-bottom: 1px solid darken($light-grey, 50%)
82
-
83
- tr
84
- text-align: left
85
-
86
- th, td
87
- padding: .5em
88
-
89
- .header::after
90
- font-size: 10px
91
- margin-left: 10px
92
-
93
- .descending::after
94
- content: '▼'
95
-
96
- .ascending::after
97
- content: '▲'
98
-
99
- .lines, .loc, .ran, .cov, .code
100
- width: 100px
101
-
102
- // Totals
103
- .totals
104
- border-top: 1px solid darken($light-grey, 50%)
105
- background: darken($dark-grey, 10%)
106
- font-weight: bold
107
-
108
-
109
- // Source
110
- .source tr
111
- pre
112
- margin-left: 3px
113
-
114
- .count
115
- background: $black
116
- color: $white
117
- -webkit-border-radius: 4px
118
- -webkit-border-top-left-radius: 0px
119
- -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .2)
120
- border: 1px solid $dark-grey
121
- display: block
122
- padding: 3px
123
- position: absolute
124
- margin-top: -10px
125
- margin-left: -15px
126
- opacity: 0
127
-
128
- .no
129
- color: $light-grey
130
- background: $dark-grey
131
- padding: 0 0 0 3px
132
- width: 25px
133
- border-right: 1px solid darken($light-grey, 50%)
134
-
135
- &:hover
136
- .count
137
- opacity: 1
138
-
139
- .no
140
- color: $white
141
-
142
- // line colouring
143
- &.excluded
144
- color: $excluded
145
- &:hover
146
- background: darken($excluded, 55%)
147
-
148
- &.unran
149
- color: $unran
150
- &:hover
151
- background: darken($unran, 40%)
152
-
153
- &.ran
154
- color: $ran
155
- &:hover
156
- background: darken($ran, 55%)
157
-
158
-
159
- // Footer
160
- footer
161
- color: fade-out($white, .4)
162
-
163
- a
164
- color: $white
165
-
166
-
@@ -1,163 +0,0 @@
1
- $text: rgb(0, 0, 0)
2
- $blue: #4080C7
3
-
4
- $black: #000
5
- $dark-grey: darken($blue, 30%)
6
- $light-grey: #fcfcfc
7
- $white: #fff
8
-
9
- $excluded: #666
10
- $unran: #d20d20
11
- $ran: $blue
12
-
13
- // Main
14
- body
15
- background: #fff
16
- font: 12px/1.3em Helvetica
17
- color: $black
18
-
19
- a
20
- text-decoration: none
21
-
22
-
23
- // Header
24
- header
25
- margin: 2em .5em
26
-
27
- h1, h1 a
28
- color: $black
29
-
30
- h2
31
- color: darken($blue, 20%)
32
- font-size: 16px
33
-
34
- // Filter/Search Box
35
- #filter
36
- position: absolute
37
- top: 20px
38
- right: 8px
39
- border: 1px solid $dark-grey
40
- background: $light-grey
41
- -webkit-border-radius: 5px
42
- padding: 3px
43
-
44
- &:focus
45
- border: 1px solid transparent
46
-
47
-
48
- // Table
49
- .table-wrapper
50
- min-width: 700px
51
-
52
- table
53
- border: 1px solid $dark-grey
54
- background: $light-grey
55
- border-collapse: collapse
56
- width: 100%
57
- margin-bottom: 1em
58
-
59
- table.source, pre, code
60
- font: 11px/1.2em Menlo
61
-
62
- td pre
63
- margin: 0
64
-
65
-
66
- // Summary
67
- .summary
68
- margin-bottom: 1em
69
- background: $light-grey
70
-
71
- tbody
72
- .name, .name a
73
- color: $text
74
- font-weight: bold
75
-
76
- tbody tr:hover
77
- background: lighten($excluded, 55%)
78
-
79
- thead
80
- background: $dark-grey
81
- color: $light-grey
82
-
83
- tr
84
- text-align: left
85
-
86
- th, td
87
- padding: .5em
88
-
89
- .header::after
90
- font-size: 10px
91
- margin-left: 10px
92
-
93
- .descending::after
94
- content: '▼'
95
-
96
- .ascending::after
97
- content: '▲'
98
-
99
- .lines, .loc, .ran, .cov, .code
100
- width: 100px
101
-
102
- // Totals
103
- .totals
104
- border-top: 1px solid black
105
- background: $light-grey
106
- font-weight: bold
107
-
108
-
109
- // Source
110
- .source tr
111
- pre
112
- margin-left: 3px
113
-
114
- .count
115
- background: $white
116
- -webkit-border-radius: 4px
117
- -webkit-border-top-left-radius: 0px
118
- -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .2)
119
- border: 1px solid black
120
- display: block
121
- padding: 3px
122
- position: absolute
123
- margin-top: -10px
124
- margin-left: -15px
125
- opacity: 0
126
- color: $black
127
-
128
- .no
129
- color: $dark-grey
130
- background: darken($light-grey, 10%)
131
- padding: 0 0 0 3px
132
- border-right: 1px solid $dark-grey
133
- width: 25px
134
-
135
- &:hover
136
- .count
137
- opacity: 1
138
-
139
- // line colouring
140
- &.excluded
141
- color: $excluded
142
- &:hover
143
- background: lighten($excluded, 55%)
144
-
145
- &.unran
146
- color: $unran
147
- &:hover
148
- background: lighten($unran, 50%)
149
-
150
- &.ran
151
- color: $ran
152
- &:hover
153
- background: lighten($ran, 40%)
154
-
155
-
156
- // Footer
157
- footer
158
- color: rgba(0, 0, 0, .6)
159
-
160
- a
161
- color: rgb(0, 0, 0)
162
-
163
-