cucumber-blanket 0.0.3 → 0.1.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 +39 -0
- data/lib/cucumber/blanket.rb +25 -3
- data/lib/cucumber/blanket/version.rb +1 -1
- data/spec/lib/cucumber/blanket_spec.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e23857ccf05090b02850a9edb41cafdd17ac781d
|
4
|
+
data.tar.gz: cbccd47528e369462f58c422e0b974392e9359d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8e739b12dd7808c0a87c3629de33566df3c98ffd445b9a59ee6e70dd01b478628cc80fb2b2fab8e50d06ec23a2ae67aa2184b8f013b78f24f99f43281560d12
|
7
|
+
data.tar.gz: f96e501d2d292e8bc1f5fec114df1a5e0658397e61aae9421def5d883123957439d05cb0d974ba9ff9bbf0567cd1d935700e005e46b67393177797124b02887d
|
data/README.md
CHANGED
@@ -74,6 +74,45 @@ end
|
|
74
74
|
I have both of these in my `features/support/hooks.rb` file. As far as doing something useful
|
75
75
|
with the coverage data, that's left up to the user, another gem, or maybe blanket.js itself from Node.js.
|
76
76
|
|
77
|
+
## Other Features
|
78
|
+
|
79
|
+
### Percent
|
80
|
+
|
81
|
+
You can use `Cucumber::Blanket.percent` to get a float value of coverage of known lines of code.
|
82
|
+
|
83
|
+
For example, you can do something like this to watch coverage increasing on every scenario:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
After do |scenario|
|
87
|
+
old_pct = Cucumber::Blanket.percent
|
88
|
+
Cucumber::Blanket.extract_from page
|
89
|
+
current_pct = Cucumber::Blanket.percent
|
90
|
+
pct_added = current_pct - old_pct
|
91
|
+
STDOUT.puts "Coverage: #{current_pct}% (+#{pct_added}%)"
|
92
|
+
end
|
93
|
+
|
94
|
+
at_exit do
|
95
|
+
STDOUT.puts "Final coverage: #{Cucumber::Blanket.percent}%"
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
### Options
|
100
|
+
|
101
|
+
You can adjust the wait times used to allow blanket.js to work, you should adjust
|
102
|
+
this if you are getting an error like this:
|
103
|
+
|
104
|
+
```
|
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
|
+
|
112
|
+
```
|
113
|
+
Cucumber::Blanket.extract_from page, setup_wait:1, extract_wait:1 # increased each by a half-second
|
114
|
+
```
|
115
|
+
|
77
116
|
## Contributing
|
78
117
|
|
79
118
|
1. Fork it
|
data/lib/cucumber/blanket.rb
CHANGED
@@ -20,15 +20,37 @@ module Cucumber
|
|
20
20
|
|
21
21
|
# Grab code coverage from the frontend
|
22
22
|
# Currently this adds >1 second to every scenario, but it's worth it
|
23
|
-
|
24
|
-
|
23
|
+
# The waits are lame but here's what it's trying to avoid
|
24
|
+
# unknown error: You must call blanket.setupCoverage() first.
|
25
|
+
# (Session info: chrome=31.0.1650.63)
|
26
|
+
# (Driver info: chromedriver=2.6.232908,platform=Mac OS X 10.9.1 x86_64) (Selenium::WebDriver::Error::UnknownError)
|
27
|
+
def extract_from page, opts={setup_wait: 0.5, extract_wait: 0.5}
|
28
|
+
sleep opts[:setup_wait] # Give blanketJS time to setupCoverage() before we go to stop it
|
25
29
|
page.evaluate_script("blanket.onTestDone();")
|
26
30
|
page.evaluate_script("blanket.onTestsDone();")
|
27
|
-
sleep
|
31
|
+
sleep opts[:extract_wait] # Allow time for blanketJS and the adapter to prepare the report
|
28
32
|
page_data = page.evaluate_script("window.COVERAGE_RESULTS")
|
29
33
|
@@coverage_data.accrue! page_data
|
30
34
|
return page_data
|
31
35
|
end
|
36
|
+
|
37
|
+
def percent
|
38
|
+
total_lines = 0
|
39
|
+
covered_lines = 0
|
40
|
+
self.files.each do |filename, linedata|
|
41
|
+
linedata.compact.each do |cov_stat|
|
42
|
+
if cov_stat > 0
|
43
|
+
covered_lines += 1
|
44
|
+
end
|
45
|
+
total_lines += 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
if total_lines > 0
|
49
|
+
return ((covered_lines.to_f / total_lines)*100).round(2)
|
50
|
+
else
|
51
|
+
return 0.0
|
52
|
+
end
|
53
|
+
end
|
32
54
|
end
|
33
55
|
end
|
34
56
|
end
|
@@ -27,4 +27,17 @@ describe Cucumber::Blanket do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
describe "#percent" do
|
32
|
+
before(:each) { subject.reset! }
|
33
|
+
it "returns total percent coverage of known lines of code as float" do
|
34
|
+
subject.extract_from(FakePage.new)
|
35
|
+
subject.percent.should eq 37.5
|
36
|
+
end
|
37
|
+
context "no data harvested yet" do
|
38
|
+
it "returns zero" do
|
39
|
+
subject.percent.should eq 0.0
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
30
43
|
end
|