cucumber-blanket 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/javascript/cucumber-blanket.js +18 -2
- data/lib/cucumber/blanket/coverage_data.rb +10 -1
- data/lib/cucumber/blanket/version.rb +1 -1
- data/lib/cucumber/blanket.rb +15 -7
- data/spec/fixtures/simple.json +7 -10
- data/spec/lib/cucumber/blanket/coverage_data_spec.rb +10 -0
- data/spec/lib/cucumber/blanket_spec.rb +7 -1
- data/spec/spec_helper.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1ced4349e3ba6ee92c994e022909cfc77c37005
|
4
|
+
data.tar.gz: a450503278a67cf67af97d75c5ddd14907a59d82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97a967c71d181734ff136f1ce12258877a6e205266f16b19b3850b5ef0ba39ceadb05219528d8878341928b1c9a795f5b0e5ebe07911aa9e361926ff450578d1
|
7
|
+
data.tar.gz: 76f9519cb0b95bb305dbf4c61efaa82bfb3c96a931832ca870f117cccb604a77fb4683cbf5b5ea772c58a5c647e95f60f6b5099f42a53099692adf1d8085b3b0
|
data/README.md
CHANGED
@@ -113,6 +113,18 @@ When you're extracting from the page, you can adjust the defaults (they are set
|
|
113
113
|
Cucumber::Blanket.extract_from page, setup_wait:1, extract_wait:1 # increased each by a half-second
|
114
114
|
```
|
115
115
|
|
116
|
+
## Dev Notes
|
117
|
+
|
118
|
+
To create the `spec/fixtures/simple.json` with new real data, add this line
|
119
|
+
to Cucumber::Blanket#extract_from once you have a handle to page_data:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
File.open("tmp/out.json", 'w'){|f| f.write page_data.to_json}
|
123
|
+
```
|
124
|
+
|
125
|
+
Run it through jsbeautifier and add it
|
126
|
+
|
127
|
+
|
116
128
|
## Contributing
|
117
129
|
|
118
130
|
1. Fork it
|
@@ -7,7 +7,7 @@
|
|
7
7
|
* Required blanket commands:
|
8
8
|
* blanket.setupCoverage(); // Do it ASAP
|
9
9
|
* blanket.onTestStart(); // Do it ASAP
|
10
|
-
* blanket.onTestDone(); // After Scenario Hook
|
10
|
+
* blanket.onTestDone(); // After Scenario Hook (Not necessary)
|
11
11
|
* blanket.onTestsDone(); // After Scenario Hook
|
12
12
|
*/
|
13
13
|
|
@@ -15,6 +15,12 @@
|
|
15
15
|
callback: function() {
|
16
16
|
blanket.setupCoverage();
|
17
17
|
blanket.onTestStart();
|
18
|
+
window.CUCUMBER_BLANKET = {
|
19
|
+
files: {},
|
20
|
+
sources: {},
|
21
|
+
done: false,
|
22
|
+
is_setup: true
|
23
|
+
};
|
18
24
|
}
|
19
25
|
});
|
20
26
|
|
@@ -25,6 +31,16 @@
|
|
25
31
|
* that doesn't actually work so we'll override defaultReporter
|
26
32
|
*/
|
27
33
|
blanket.defaultReporter = function(coverage_results){
|
28
|
-
window.
|
34
|
+
window.CUCUMBER_BLANKET.files = coverage_results.files;
|
35
|
+
// Strangely enough it looks like we need to iterate in order to grab the `source`
|
36
|
+
// data which is necessary to know which lines of code are being reported on.
|
37
|
+
var files = Object.keys(coverage_results.files);
|
38
|
+
for (var i = 0, l = files.length; i < l; i ++) {
|
39
|
+
var file = files[i];
|
40
|
+
window.CUCUMBER_BLANKET.sources[file] = window.CUCUMBER_BLANKET.files[file].source;
|
41
|
+
}
|
42
|
+
window.CUCUMBER_BLANKET.done = true;
|
43
|
+
// Now we can grab all this on the selenium side through window.CUCUMBER_BLANKET
|
29
44
|
};
|
30
45
|
})();
|
46
|
+
|
@@ -8,7 +8,7 @@ module Cucumber
|
|
8
8
|
attr_reader :data
|
9
9
|
|
10
10
|
def initialize
|
11
|
-
@data = {'files'=>{}}
|
11
|
+
@data = {'files'=>{}, 'sources'=>{}}
|
12
12
|
end
|
13
13
|
|
14
14
|
def method_missing *args
|
@@ -19,6 +19,10 @@ module Cucumber
|
|
19
19
|
self.data['files']
|
20
20
|
end
|
21
21
|
|
22
|
+
def sources
|
23
|
+
self.data['sources']
|
24
|
+
end
|
25
|
+
|
22
26
|
def accrue! page_data
|
23
27
|
if @data.nil?
|
24
28
|
@data = page_data
|
@@ -50,6 +54,11 @@ module Cucumber
|
|
50
54
|
@data['files'][filename] = linedata
|
51
55
|
end
|
52
56
|
end
|
57
|
+
|
58
|
+
# As far as sources are concerned, we just add it if an entry doesn't exist
|
59
|
+
page_data['sources'].each do |filename, lines|
|
60
|
+
@data['sources'][filename] ||= lines
|
61
|
+
end
|
53
62
|
end
|
54
63
|
end
|
55
64
|
end
|
data/lib/cucumber/blanket.rb
CHANGED
@@ -14,26 +14,34 @@ module Cucumber
|
|
14
14
|
@@coverage_data = CoverageData.new
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
self.coverage_data.
|
17
|
+
def method_missing *args
|
18
|
+
self.coverage_data.send(*args)
|
19
19
|
end
|
20
20
|
|
21
21
|
# Grab code coverage from the frontend
|
22
|
-
# Currently this adds
|
22
|
+
# Currently this adds something like a few second or more to every scenario
|
23
23
|
# The waits are lame but here's what it's trying to avoid
|
24
24
|
# unknown error: You must call blanket.setupCoverage() first.
|
25
25
|
# (Session info: chrome=31.0.1650.63)
|
26
26
|
# (Driver info: chromedriver=2.6.232908,platform=Mac OS X 10.9.1 x86_64) (Selenium::WebDriver::Error::UnknownError)
|
27
27
|
def extract_from page, opts={setup_wait: 0.5, extract_wait: 0.5}
|
28
|
-
|
29
|
-
|
28
|
+
@page = page
|
29
|
+
sleep(opts[:setup_wait]) until coverage_is_setup?
|
30
30
|
page.evaluate_script("blanket.onTestsDone();")
|
31
|
-
sleep
|
32
|
-
page_data = page.evaluate_script("window.
|
31
|
+
sleep(opts[:extract_wait]) until data_ready?
|
32
|
+
page_data = page.evaluate_script("window.CUCUMBER_BLANKET")
|
33
33
|
@@coverage_data.accrue! page_data
|
34
34
|
return page_data
|
35
35
|
end
|
36
36
|
|
37
|
+
def coverage_is_setup?
|
38
|
+
@page.evaluate_script("window.CUCUMBER_BLANKET.is_setup")
|
39
|
+
end
|
40
|
+
|
41
|
+
def data_ready?
|
42
|
+
@page.evaluate_script("window.CUCUMBER_BLANKET.done")
|
43
|
+
end
|
44
|
+
|
37
45
|
def percent
|
38
46
|
total_lines = 0
|
39
47
|
covered_lines = 0
|
data/spec/fixtures/simple.json
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
{
|
2
|
+
"done": true,
|
2
3
|
"files": {
|
3
|
-
"http://127.0.0.1:32344/js/collections/
|
4
|
+
"http://127.0.0.1:32344/js/collections/comments.js": [null, 1, 1, null, 1],
|
5
|
+
"http://127.0.0.1:32344/js/views/plans.js": [null, 1, 1, null, 1, null, null, null, null, null, null, 0, 0]
|
4
6
|
},
|
5
|
-
"
|
6
|
-
"
|
7
|
-
"
|
8
|
-
"
|
9
|
-
"passes": 1,
|
10
|
-
"pending": 0,
|
11
|
-
"start": {},
|
12
|
-
"suites": 0,
|
13
|
-
"tests": 1
|
7
|
+
"is_setup": true,
|
8
|
+
"sources": {
|
9
|
+
"http://127.0.0.1:32344/js/collections/comments.js": ["(function () {", " 'use strict';", "", " App.Collections.Comments = Backbone.Collection.extend({", "", " model: App.Models.Comment", "", " });", "}());", "", ""],
|
10
|
+
"http://127.0.0.1:32344/js/views/plans.js": ["(function(){", " \"use strict\";", "", " App.Views.Plans = Backbone.View.extend({", " events: {", " },", "", " template: App.Templates.plans,", "", " render: function() {", " this.$el.html(this.template);", " return this;", " }", " });", "}());", ""]
|
14
11
|
}
|
15
12
|
}
|
@@ -47,4 +47,14 @@ describe Cucumber::Blanket::CoverageData do
|
|
47
47
|
Cucumber::Blanket.files.should eq covdata.files
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
describe "#sources" do
|
52
|
+
it "shorthand for accessing the sources hash" do
|
53
|
+
covdata.sources.should eq covdata.data['sources']
|
54
|
+
covdata.sources.should be_a Hash
|
55
|
+
end
|
56
|
+
it "has a shortcut that produces the same data" do
|
57
|
+
Cucumber::Blanket.sources.should eq covdata.sources
|
58
|
+
end
|
59
|
+
end
|
50
60
|
end
|
@@ -8,6 +8,12 @@ describe Cucumber::Blanket do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
describe "#sources" do
|
12
|
+
it "is a shortcut for coverage_data#sources" do
|
13
|
+
subject.sources.should eq subject.coverage_data.sources
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
11
17
|
describe "#extract_from" do
|
12
18
|
let(:page) { FakePage.new }
|
13
19
|
context "Selenium-returned blanket.js coverage data structure characteristics" do
|
@@ -32,7 +38,7 @@ describe Cucumber::Blanket do
|
|
32
38
|
before(:each) { subject.reset! }
|
33
39
|
it "returns total percent coverage of known lines of code as float" do
|
34
40
|
subject.extract_from(FakePage.new)
|
35
|
-
subject.percent.should eq
|
41
|
+
subject.percent.should eq 75.0
|
36
42
|
end
|
37
43
|
context "no data harvested yet" do
|
38
44
|
it "returns zero" do
|
data/spec/spec_helper.rb
CHANGED
@@ -15,8 +15,12 @@ class FakePage
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def evaluate_script script
|
18
|
-
if script == "window.
|
18
|
+
if script == "window.CUCUMBER_BLANKET"
|
19
19
|
self.coverage_data
|
20
|
+
elsif script == "window.CUCUMBER_BLANKET.done"
|
21
|
+
true
|
22
|
+
elsif script == "window.CUCUMBER_BLANKET.is_setup"
|
23
|
+
true
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-blanket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keyvan Fatehi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|