cucumber-blanket 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e23857ccf05090b02850a9edb41cafdd17ac781d
4
- data.tar.gz: cbccd47528e369462f58c422e0b974392e9359d2
3
+ metadata.gz: f1ced4349e3ba6ee92c994e022909cfc77c37005
4
+ data.tar.gz: a450503278a67cf67af97d75c5ddd14907a59d82
5
5
  SHA512:
6
- metadata.gz: b8e739b12dd7808c0a87c3629de33566df3c98ffd445b9a59ee6e70dd01b478628cc80fb2b2fab8e50d06ec23a2ae67aa2184b8f013b78f24f99f43281560d12
7
- data.tar.gz: f96e501d2d292e8bc1f5fec114df1a5e0658397e61aae9421def5d883123957439d05cb0d974ba9ff9bbf0567cd1d935700e005e46b67393177797124b02887d
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.COVERAGE_RESULTS = coverage_results; // We'll grab this on selenium side
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
@@ -1,5 +1,5 @@
1
1
  module Cucumber
2
2
  module Blanket
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -14,26 +14,34 @@ module Cucumber
14
14
  @@coverage_data = CoverageData.new
15
15
  end
16
16
 
17
- def files
18
- self.coverage_data.files
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 >1 second to every scenario, but it's worth it
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
- sleep opts[:setup_wait] # Give blanketJS time to setupCoverage() before we go to stop it
29
- page.evaluate_script("blanket.onTestDone();")
28
+ @page = page
29
+ sleep(opts[:setup_wait]) until coverage_is_setup?
30
30
  page.evaluate_script("blanket.onTestsDone();")
31
- sleep opts[:extract_wait] # Allow time for blanketJS and the adapter to prepare the report
32
- page_data = page.evaluate_script("window.COVERAGE_RESULTS")
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
@@ -1,15 +1,12 @@
1
1
  {
2
+ "done": true,
2
3
  "files": {
3
- "http://127.0.0.1:32344/js/collections/assets.js": [null, 1, 1, null, 1, null, null, null, 0, 0, null, 0, null, null, null, null, 0, 0]
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
- "instrumentation": "blanket",
6
- "stats": {
7
- "end": {},
8
- "failures": 0,
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 37.5
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.COVERAGE_RESULTS"
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.1.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-01 00:00:00.000000000 Z
11
+ date: 2014-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler