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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b714356da5e34fa7ad85c6e4aa0e84fe02375e7c
4
- data.tar.gz: f0098ff584b7ef9efed4acb1fdf45bbef8aef8e0
3
+ metadata.gz: e23857ccf05090b02850a9edb41cafdd17ac781d
4
+ data.tar.gz: cbccd47528e369462f58c422e0b974392e9359d2
5
5
  SHA512:
6
- metadata.gz: ff7bfbf589cf87174b1954234836b6eaaa9f29f0460cd3bc70698457dc35baae3ba75b1d89cfbe06163bb4e5f7c60df8ef92600c930dacf71114e10646b27e57
7
- data.tar.gz: 28722ff3dbd10ef8ed147e2da0d7ad6a61ae1631ff6915443d47eb1833208892e2ae5ea3f0833754241b5064ed7fef1309ea0afbed04104e9c5de411e1a3d563
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
@@ -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
- def extract_from page
24
- sleep 0.5 # Give blanketJS time to setupCoverage() before we go to stop it
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 0.5 # Allow time for blanketJS and the adapter to prepare the report
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
@@ -1,5 +1,5 @@
1
1
  module Cucumber
2
2
  module Blanket
3
- VERSION = "0.0.3"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  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
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.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keyvan Fatehi