cucumber-blanket 0.2.0 → 0.3.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 +4 -4
- data/README.md +6 -12
- data/cucumber-blanket.gemspec +2 -0
- data/javascript/cucumber-blanket.js +7 -6
- data/lib/cucumber/blanket.rb +13 -5
- data/lib/cucumber/blanket/coverage_data.rb +16 -0
- data/lib/cucumber/blanket/report_generator.rb +23 -0
- data/lib/cucumber/blanket/version.rb +1 -1
- data/spec/lib/cucumber/blanket/coverage_data_spec.rb +7 -0
- data/spec/lib/cucumber/blanket_spec.rb +18 -4
- data/templates/html_report.html.haml +57 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c49a4739f76a49ef5c3f52c586ca8b541cfe1bb
|
4
|
+
data.tar.gz: f53fc13a0162903bf59b0097ee937853502d57bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adb28a1c84ead4a01b2984fb94eccb9c8ae305945a97560c640155044bb919b35e1154987d3186587ca6094491c881b4612c5918f993068e597b441e7bb7ba59
|
7
|
+
data.tar.gz: 9be8b18b4cea7b819104e118b844ab6638e856268ebc5c88df18287051035913c273af620603fa430bd8e0573cf22636110e135f1c68b95dcc674c9ada8187a1
|
data/README.md
CHANGED
@@ -96,22 +96,16 @@ at_exit do
|
|
96
96
|
end
|
97
97
|
```
|
98
98
|
|
99
|
-
###
|
99
|
+
### Write HTML Report
|
100
100
|
|
101
|
-
|
102
|
-
|
101
|
+
After you've captured some coverage data, you can create an HTML report
|
102
|
+
like so:
|
103
103
|
|
104
|
+
```ruby
|
105
|
+
Cucumber::Blanket.write_html_report File.join(File.dirname(__FILE__), '../../coverage.html')
|
104
106
|
```
|
105
|
-
unknown error: You must call blanket.setupCoverage() first.
|
106
|
-
(Session info: chrome=31.0.1650.63)
|
107
|
-
(Driver info: chromedriver=2.6.232908,platform=Mac OS X 10.9.1 x86_64) (Selenium::WebDriver::Error::UnknownError)
|
108
|
-
```
|
109
|
-
|
110
|
-
When you're extracting from the page, you can adjust the defaults (they are set to half-second) -- just keep in mind that if you set one you must set the other too.
|
111
107
|
|
112
|
-
|
113
|
-
Cucumber::Blanket.extract_from page, setup_wait:1, extract_wait:1 # increased each by a half-second
|
114
|
-
```
|
108
|
+
I like to put this in `after_exit` in my Cucumber `hooks.rb` file
|
115
109
|
|
116
110
|
## Dev Notes
|
117
111
|
|
data/cucumber-blanket.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_runtime_dependency "haml"
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
24
|
spec.add_development_dependency "rake"
|
23
25
|
spec.add_development_dependency "rspec"
|
@@ -1,4 +1,10 @@
|
|
1
1
|
(function (){
|
2
|
+
window.CUCUMBER_BLANKET = {
|
3
|
+
files: {},
|
4
|
+
sources: {},
|
5
|
+
done: false,
|
6
|
+
is_setup: false
|
7
|
+
};
|
2
8
|
/* ADAPTER
|
3
9
|
*
|
4
10
|
* This blanket.js adapter is designed to autostart coverage
|
@@ -15,12 +21,7 @@
|
|
15
21
|
callback: function() {
|
16
22
|
blanket.setupCoverage();
|
17
23
|
blanket.onTestStart();
|
18
|
-
window.CUCUMBER_BLANKET =
|
19
|
-
files: {},
|
20
|
-
sources: {},
|
21
|
-
done: false,
|
22
|
-
is_setup: true
|
23
|
-
};
|
24
|
+
window.CUCUMBER_BLANKET.is_setup = true;
|
24
25
|
}
|
25
26
|
});
|
26
27
|
|
data/lib/cucumber/blanket.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "cucumber/blanket/version"
|
2
2
|
require "cucumber/blanket/coverage_data"
|
3
|
+
require "cucumber/blanket/report_generator"
|
3
4
|
|
4
5
|
module Cucumber
|
5
6
|
module Blanket
|
@@ -24,22 +25,22 @@ module Cucumber
|
|
24
25
|
# unknown error: You must call blanket.setupCoverage() first.
|
25
26
|
# (Session info: chrome=31.0.1650.63)
|
26
27
|
# (Driver info: chromedriver=2.6.232908,platform=Mac OS X 10.9.1 x86_64) (Selenium::WebDriver::Error::UnknownError)
|
27
|
-
def extract_from page
|
28
|
+
def extract_from page
|
28
29
|
@page = page
|
29
|
-
sleep(
|
30
|
+
sleep(0.2) until coverage_is_setup?
|
30
31
|
page.evaluate_script("blanket.onTestsDone();")
|
31
|
-
sleep(
|
32
|
+
sleep(0.2) until data_ready?
|
32
33
|
page_data = page.evaluate_script("window.CUCUMBER_BLANKET")
|
33
34
|
@@coverage_data.accrue! page_data
|
34
35
|
return page_data
|
35
36
|
end
|
36
37
|
|
37
38
|
def coverage_is_setup?
|
38
|
-
@page.evaluate_script("window.CUCUMBER_BLANKET.is_setup")
|
39
|
+
@page.evaluate_script("window.CUCUMBER_BLANKET.is_setup") rescue false
|
39
40
|
end
|
40
41
|
|
41
42
|
def data_ready?
|
42
|
-
@page.evaluate_script("window.CUCUMBER_BLANKET.done")
|
43
|
+
@page.evaluate_script("window.CUCUMBER_BLANKET.done") rescue false
|
43
44
|
end
|
44
45
|
|
45
46
|
def percent
|
@@ -59,6 +60,13 @@ module Cucumber
|
|
59
60
|
return 0.0
|
60
61
|
end
|
61
62
|
end
|
63
|
+
|
64
|
+
def write_html_report path
|
65
|
+
generator = ReportGenerator.new(:html, self)
|
66
|
+
File.open(path, 'w') do |file|
|
67
|
+
file.write(generator.render)
|
68
|
+
end
|
69
|
+
end
|
62
70
|
end
|
63
71
|
end
|
64
72
|
end
|
@@ -23,6 +23,22 @@ module Cucumber
|
|
23
23
|
self.data['sources']
|
24
24
|
end
|
25
25
|
|
26
|
+
def percent_covered script_url
|
27
|
+
total_lines = 0
|
28
|
+
covered_lines = 0
|
29
|
+
self.files[script_url].compact.each do |cov_stat|
|
30
|
+
if cov_stat > 0
|
31
|
+
covered_lines += 1
|
32
|
+
end
|
33
|
+
total_lines += 1
|
34
|
+
end
|
35
|
+
if total_lines > 0
|
36
|
+
return ((covered_lines.to_f / total_lines)*100).round(2)
|
37
|
+
else
|
38
|
+
return 0.0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
26
42
|
def accrue! page_data
|
27
43
|
if @data.nil?
|
28
44
|
@data = page_data
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'haml'
|
2
|
+
module Cucumber
|
3
|
+
module Blanket
|
4
|
+
class ReportGenerator
|
5
|
+
TEMPLATE_DIR = File.join(File.dirname(__FILE__), '../../../templates')
|
6
|
+
|
7
|
+
def initialize(mode, coverage_data)
|
8
|
+
case mode
|
9
|
+
when :html
|
10
|
+
template = File.join(TEMPLATE_DIR, 'html_report.html.haml')
|
11
|
+
@engine = Haml::Engine.new(File.read(template))
|
12
|
+
else
|
13
|
+
raise "Unsupported report #{mode}"
|
14
|
+
end
|
15
|
+
@data = coverage_data
|
16
|
+
end
|
17
|
+
|
18
|
+
def render
|
19
|
+
@engine.render(self)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -57,4 +57,11 @@ describe Cucumber::Blanket::CoverageData do
|
|
57
57
|
Cucumber::Blanket.sources.should eq covdata.sources
|
58
58
|
end
|
59
59
|
end
|
60
|
+
|
61
|
+
describe "#percent_covered" do
|
62
|
+
it "returns the percent covered for a given script" do
|
63
|
+
res = covdata.percent_covered covdata.files.keys[1]
|
64
|
+
res.should eq 60.0
|
65
|
+
end
|
66
|
+
end
|
60
67
|
end
|
@@ -2,6 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Cucumber::Blanket do
|
4
4
|
|
5
|
+
let(:page) { FakePage.new }
|
6
|
+
before(:each) do
|
7
|
+
subject.reset!
|
8
|
+
subject.extract_from(page)
|
9
|
+
end
|
10
|
+
|
5
11
|
describe "#files" do
|
6
12
|
it "is a shortcut for coverage_data#files" do
|
7
13
|
subject.files.should eq subject.coverage_data.files
|
@@ -15,10 +21,8 @@ describe Cucumber::Blanket do
|
|
15
21
|
end
|
16
22
|
|
17
23
|
describe "#extract_from" do
|
18
|
-
let(:page) { FakePage.new }
|
19
24
|
context "Selenium-returned blanket.js coverage data structure characteristics" do
|
20
25
|
let(:cov) do
|
21
|
-
subject.extract_from(page)
|
22
26
|
subject.coverage_data
|
23
27
|
end
|
24
28
|
specify { cov.should have_key 'files' }
|
@@ -35,15 +39,25 @@ describe Cucumber::Blanket do
|
|
35
39
|
end
|
36
40
|
|
37
41
|
describe "#percent" do
|
38
|
-
before(:each) { subject.reset! }
|
39
42
|
it "returns total percent coverage of known lines of code as float" do
|
40
|
-
subject.extract_from(FakePage.new)
|
41
43
|
subject.percent.should eq 75.0
|
42
44
|
end
|
43
45
|
context "no data harvested yet" do
|
44
46
|
it "returns zero" do
|
47
|
+
subject.reset!
|
45
48
|
subject.percent.should eq 0.0
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
52
|
+
|
53
|
+
describe "#write_html_report" do
|
54
|
+
let(:path) { '/tmp/cucumber-blanket-report.html' }
|
55
|
+
before { FileUtils.rm(path) if File.exists?(path) }
|
56
|
+
|
57
|
+
it "generates an HTML file at the desired location" do
|
58
|
+
subject.write_html_report path
|
59
|
+
File.exists?(path).should be_true
|
60
|
+
system("open #{path}") if ENV['showreport']
|
61
|
+
end
|
62
|
+
end
|
49
63
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title cucumber-blanket coverage report
|
5
|
+
:css
|
6
|
+
pre {
|
7
|
+
margin:0;
|
8
|
+
}
|
9
|
+
.ignored {
|
10
|
+
}
|
11
|
+
.missed {
|
12
|
+
background-color: #f74552;
|
13
|
+
}
|
14
|
+
.covered {
|
15
|
+
background-color: #72f779;
|
16
|
+
}
|
17
|
+
|
18
|
+
:javascript
|
19
|
+
function toggleScriptContentDisplay(a) {
|
20
|
+
var contents = a.parentElement.childNodes[3];
|
21
|
+
if (contents.style.display === "none") {
|
22
|
+
contents.style.display = "block";
|
23
|
+
} else {
|
24
|
+
contents.style.display = "none";
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
document.addEventListener('DOMContentLoaded', function () {
|
29
|
+
scripts = document.querySelectorAll('a.script_url');
|
30
|
+
for (var i = 0, l = scripts.length; i < l; i ++) {
|
31
|
+
var script = scripts[i];
|
32
|
+
script.onclick = function() {
|
33
|
+
toggleScriptContentDisplay(this);
|
34
|
+
return false;
|
35
|
+
};
|
36
|
+
}
|
37
|
+
});
|
38
|
+
|
39
|
+
|
40
|
+
%body
|
41
|
+
%table.ui.table.segment
|
42
|
+
%thead
|
43
|
+
%tr
|
44
|
+
%th Script
|
45
|
+
%th Coverage #{@data.percent}%
|
46
|
+
%tbody
|
47
|
+
- @data.files.each do |script_url, covdata|
|
48
|
+
- lines = @data.sources[script_url]
|
49
|
+
%tr
|
50
|
+
%td
|
51
|
+
%a.script_url{:href=>"#"}= script_url
|
52
|
+
.contents{style:"display:none"}
|
53
|
+
- lines.each_with_index do |line, line_no|
|
54
|
+
- cov = covdata[line_no]
|
55
|
+
%pre{:class=>(cov.nil? ? "ignored" : (cov == 0 ? 'missed' : 'covered'))}
|
56
|
+
= line.gsub(' ', ' ')
|
57
|
+
%td #{@data.percent_covered(script_url)} %
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-blanket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keyvan Fatehi
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: haml
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,11 +113,13 @@ files:
|
|
99
113
|
- javascript/cucumber-blanket.js
|
100
114
|
- lib/cucumber/blanket.rb
|
101
115
|
- lib/cucumber/blanket/coverage_data.rb
|
116
|
+
- lib/cucumber/blanket/report_generator.rb
|
102
117
|
- lib/cucumber/blanket/version.rb
|
103
118
|
- spec/fixtures/simple.json
|
104
119
|
- spec/lib/cucumber/blanket/coverage_data_spec.rb
|
105
120
|
- spec/lib/cucumber/blanket_spec.rb
|
106
121
|
- spec/spec_helper.rb
|
122
|
+
- templates/html_report.html.haml
|
107
123
|
homepage: https://github.com/keyvanfatehi/cucumber-blanket
|
108
124
|
licenses:
|
109
125
|
- MIT
|
@@ -124,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
140
|
version: '0'
|
125
141
|
requirements: []
|
126
142
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
143
|
+
rubygems_version: 2.1.10
|
128
144
|
signing_key:
|
129
145
|
specification_version: 4
|
130
146
|
summary: Extract Blanket.js code coverage data from within a Ruby Cucumber environment
|