cucumber-blanket 0.0.2 → 0.0.3

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: 2cc556e69fcc4d91fd37b57b8318d2ac67dbcaa9
4
- data.tar.gz: 4d37ca8867d062e68b8c91181146d3acf64bd69a
3
+ metadata.gz: b714356da5e34fa7ad85c6e4aa0e84fe02375e7c
4
+ data.tar.gz: f0098ff584b7ef9efed4acb1fdf45bbef8aef8e0
5
5
  SHA512:
6
- metadata.gz: 1af5a99c05f9401982483090f4ba19b47817d6bb2534a181c92427857141c6689f4681d6f1d2777676f8e77fb9609d2c2843a110b0a84c27ad1c9398aca360df
7
- data.tar.gz: f489b94aa98581a06cfddc74be41ce31ef537a0c1afa745675c2a23a7304a8e2a71da21cec3f69e155831734f40f359a7f8113f3bca9339665ae6674df89d534
6
+ metadata.gz: ff7bfbf589cf87174b1954234836b6eaaa9f29f0460cd3bc70698457dc35baae3ba75b1d89cfbe06163bb4e5f7c60df8ef92600c930dacf71114e10646b27e57
7
+ data.tar.gz: 28722ff3dbd10ef8ed147e2da0d7ad6a61ae1631ff6915443d47eb1833208892e2ae5ea3f0833754241b5064ed7fef1309ea0afbed04104e9c5de411e1a3d563
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
1
  # Cucumber::Blanket
2
2
 
3
- **WIP** -- will be done soon though, it's close, I just need to complete
4
- the report generator
5
-
6
- Works to extract [Blanket.js](https://github.com/alex-seville/blanket) coverage data
7
- from the browser from Cucumber.
3
+ Works to extract accumulated [Blanket.js](https://github.com/alex-seville/blanket) coverage data
4
+ from the browser from a Cucumber environment. Accumulated, in this context, means that coverage data
5
+ is accumulated from scenario to scenario, in an additive fashion.
8
6
 
9
7
  ## Installation
10
8
 
@@ -57,15 +55,24 @@ such Cucumber::Blanket OR's the lines. In other words, if line 10 of
57
55
  File A was covered in Scenario X, but not in Scenario Y, line 10 is
58
56
  considered covered when Cucumber has finished running.
59
57
 
60
- Finally, to generate a report **not done yet**, you can do:
58
+ Finally, to gain access to the accumulated coverage data, you can use the shorthand `Cucumber::Blanket.files`:
61
59
 
62
60
  ```ruby
63
61
  after_exit do
64
- puts Cucumber::Blanket.generate_report
62
+ covdata = # do something with it
63
+ File.open("tmp/coverage.json", "w") do |file|
64
+ file.write Cucumber::Blanket.files.to_json
65
+ # writes out JSON of this form of ruby hash:
66
+ # => {"http://127.0.0.1:32344/js/collections/assets.js"=>
67
+ # [3, 3, 3, nil, 3, nil, nil, nil, 0, 0, nil, 0, nil, nil, nil, nil, 0, 0]}
68
+ # {filename=>[lineCov,lineCov,lineCov]}
69
+ # At this stage you can fetch the files and create a nice HTML report, etc
70
+ end
65
71
  end
66
72
  ```
67
73
 
68
- I have both of these in my `features/support/hooks.rb` file.
74
+ I have both of these in my `features/support/hooks.rb` file. As far as doing something useful
75
+ with the coverage data, that's left up to the user, another gem, or maybe blanket.js itself from Node.js.
69
76
 
70
77
  ## Contributing
71
78
 
@@ -10,6 +10,14 @@ module Cucumber
10
10
  @@coverage_data
11
11
  end
12
12
 
13
+ def reset!
14
+ @@coverage_data = CoverageData.new
15
+ end
16
+
17
+ def files
18
+ self.coverage_data.files
19
+ end
20
+
13
21
  # Grab code coverage from the frontend
14
22
  # Currently this adds >1 second to every scenario, but it's worth it
15
23
  def extract_from page
@@ -21,11 +29,6 @@ module Cucumber
21
29
  @@coverage_data.accrue! page_data
22
30
  return page_data
23
31
  end
24
-
25
- def generate_report
26
- # but for now, so you know it's there...
27
- puts "coverage data length: #{@@coverage_data.inspect}"
28
- end
29
32
  end
30
33
  end
31
34
  end
@@ -8,45 +8,46 @@ module Cucumber
8
8
  attr_reader :data
9
9
 
10
10
  def initialize
11
- @data = nil
11
+ @data = {'files'=>{}}
12
12
  end
13
13
 
14
14
  def method_missing *args
15
- @data[0].send(*args)
15
+ @data.send(*args)
16
+ end
17
+
18
+ def files
19
+ self.data['files']
16
20
  end
17
21
 
18
22
  def accrue! page_data
19
- # go through every line of every file and OR it all together
20
- # e.g. line 1 is 1 and 0, so it is 1
21
- #binding.pry
22
23
  if @data.nil?
23
24
  @data = page_data
24
25
  else
25
26
  # for files in page_data ...
26
- page_data[0]['files'].each do |filename, linedata|
27
+ page_data['files'].each do |filename, linedata|
27
28
  # that exist in @data
28
- if @data[0]['files'].has_key? page_data[0]['files'].first[0]
29
+ if @data['files'][filename]
29
30
  # accrue coverage data, meaning:
30
31
  # get a handle on existing linedata and iterate
31
- @data[0]['files'][filename].each_with_index do |cov_stat, line_no|
32
- new_cov_stat = page_data[0]['files'][filename][line_no]
32
+ @data['files'][filename].each_with_index do |cov_stat, line_no|
33
+ new_cov_stat = page_data['files'][filename][line_no]
33
34
  # first we need to deal with nils, as we cannot add them
34
35
  # either side can be nil -- and we want to be strictly additive
35
36
  next if new_cov_stat.nil? # this is not additive, next line
36
37
  # So now we know the new data is definitely not nil
37
38
  # but the existing data could be, so we'll handle that now
38
39
  if cov_stat.nil?
39
- @data[0]['files'][filename][line_no] = new_cov_stat
40
+ @data['files'][filename][line_no] = new_cov_stat
40
41
  # We replaced it with the new data, next line please
41
42
  next
42
43
  end
43
44
  # if we ever get here, we're dealing strictly with integers
44
45
  # as a result we just need to sum the two stats
45
- @data[0]['files'][filename][line_no] = cov_stat + new_cov_stat
46
+ @data['files'][filename][line_no] = cov_stat + new_cov_stat
46
47
  end
47
48
  else # if it does not exist
48
49
  # add it to 'files' as is
49
- @data[0]['files'][filename] = linedata
50
+ @data['files'][filename] = linedata
50
51
  end
51
52
  end
52
53
  end
@@ -1,5 +1,5 @@
1
1
  module Cucumber
2
2
  module Blanket
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- [{
1
+ {
2
2
  "files": {
3
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
4
  },
@@ -12,4 +12,4 @@
12
12
  "suites": 0,
13
13
  "tests": 1
14
14
  }
15
- }]
15
+ }
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Cucumber::Blanket::CoverageData do
4
+ before(:each) { Cucumber::Blanket.reset! }
4
5
  let(:page) { FakePage.new }
5
6
  let(:covdata) do
6
7
  Cucumber::Blanket.extract_from(page)
@@ -10,7 +11,7 @@ describe Cucumber::Blanket::CoverageData do
10
11
  describe "#accrue!" do
11
12
  let(:new_page_data) do
12
13
  page_data = Marshal.load(Marshal.dump(covdata.data))
13
- page_data[0]['files'].first[1][0] = 3 # add coverage on that line
14
+ page_data['files'].first[1][0] = 3 # add coverage on that line
14
15
  page_data
15
16
  end
16
17
  it "squishes coverage datasets together" do
@@ -20,5 +21,30 @@ describe Cucumber::Blanket::CoverageData do
20
21
  covdata["files"].first[1][0].should eq 3
21
22
  covdata["files"].first[1][1].should eq 2
22
23
  end
24
+
25
+ context "filename exists but is not iterable" do
26
+ let(:new_page_data) do
27
+ Marshal.load(Marshal.dump(covdata.data))
28
+ end
29
+ before do
30
+ @data_copy = new_page_data
31
+ @filename = covdata['files'].first[0]
32
+ covdata['files'][@filename] = nil
33
+ end
34
+ it "will not try to iterate over nil" do
35
+ expect {covdata.accrue! @data_copy}.not_to raise_error
36
+ end
37
+ end
38
+ end
39
+
40
+
41
+ describe "#files" do
42
+ it "shorthand for accessing the files hash" do
43
+ covdata.files.should eq covdata.data['files']
44
+ covdata.files.should be_a Hash
45
+ end
46
+ it "has a shortcut that produces the same data" do
47
+ Cucumber::Blanket.files.should eq covdata.files
48
+ end
23
49
  end
24
50
  end
@@ -1,6 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Cucumber::Blanket do
4
+
5
+ describe "#files" do
6
+ it "is a shortcut for coverage_data#files" do
7
+ subject.files.should eq subject.coverage_data.files
8
+ end
9
+ end
10
+
4
11
  describe "#extract_from" do
5
12
  let(:page) { FakePage.new }
6
13
  context "Selenium-returned blanket.js coverage data structure characteristics" do
data/spec/spec_helper.rb CHANGED
@@ -19,12 +19,5 @@ class FakePage
19
19
  self.coverage_data
20
20
  end
21
21
  end
22
-
23
- ##
24
- # Helper to change the lines of coverage for testing flattening
25
- # of two sets of coverage data
26
- def cov_lines
27
-
28
- end
29
22
  end
30
23
 
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keyvan Fatehi