cucumber-blanket 0.0.1 → 0.0.2

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: 2a325cf61c6c342d6e9066eecf5368b9062e1f12
4
- data.tar.gz: 8405f3fc01145224245f6c2904ebeac73687d96d
3
+ metadata.gz: 2cc556e69fcc4d91fd37b57b8318d2ac67dbcaa9
4
+ data.tar.gz: 4d37ca8867d062e68b8c91181146d3acf64bd69a
5
5
  SHA512:
6
- metadata.gz: 878b4d48cf083cdc5790c1cf80b9481c9a39a2c4d12e3e440ede1b05c6be27f9fc09cca286a8c6dee34275b218b93e30e0df5f0204102be552dd5b8cb29310cf
7
- data.tar.gz: 496cbf56f4aa29607853dc5b9d6d79f034ad5d759c987885410f8d39130a169c79d789cb045c7eba53ec2e146415da014011053bb61a8a01e4b3be76f4f38779
6
+ metadata.gz: 1af5a99c05f9401982483090f4ba19b47817d6bb2534a181c92427857141c6689f4681d6f1d2777676f8e77fb9609d2c2843a110b0a84c27ad1c9398aca360df
7
+ data.tar.gz: f489b94aa98581a06cfddc74be41ce31ef537a0c1afa745675c2a23a7304a8e2a71da21cec3f69e155831734f40f359a7f8113f3bca9339665ae6674df89d534
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Cucumber::Blanket
2
2
 
3
- **WIP** -- will be done soon though, it's close, I just need to flatten
4
- the data as it comes in and complete the report generator
3
+ **WIP** -- will be done soon though, it's close, I just need to complete
4
+ the report generator
5
5
 
6
6
  Works to extract [Blanket.js](https://github.com/alex-seville/blanket) coverage data
7
7
  from the browser from Cucumber.
@@ -22,6 +22,16 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
+ You should be using Cucumber
26
+
27
+ Require this gem at the top of `features/support/env.rb` or before using it.
28
+
29
+ ```ruby
30
+ require 'cucumber/blanket'
31
+ ```
32
+
33
+ Install blanket.js
34
+
25
35
  Two javascript files are bundled;
26
36
  * blanket.js -- the library itself
27
37
  * cucumber-blanket.js -- a very simple modification
@@ -45,13 +55,12 @@ end
45
55
  Of course every scenario will touch on different parts of your code, as
46
56
  such Cucumber::Blanket OR's the lines. In other words, if line 10 of
47
57
  File A was covered in Scenario X, but not in Scenario Y, line 10 is
48
- considered covered when Cucumber has finished running. **not done yet**
58
+ considered covered when Cucumber has finished running.
49
59
 
50
60
  Finally, to generate a report **not done yet**, you can do:
51
61
 
52
62
  ```ruby
53
63
  after_exit do
54
- $stack.stop
55
64
  puts Cucumber::Blanket.generate_report
56
65
  end
57
66
  ```
@@ -20,4 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard-rspec"
25
+ spec.add_development_dependency "pry"
23
26
  end
@@ -1,9 +1,14 @@
1
1
  require "cucumber/blanket/version"
2
+ require "cucumber/blanket/coverage_data"
2
3
 
3
4
  module Cucumber
4
5
  module Blanket
5
6
  class << self
6
- @@coverage_data = []
7
+ @@coverage_data = CoverageData.new
8
+
9
+ def coverage_data
10
+ @@coverage_data
11
+ end
7
12
 
8
13
  # Grab code coverage from the frontend
9
14
  # Currently this adds >1 second to every scenario, but it's worth it
@@ -12,19 +17,14 @@ module Cucumber
12
17
  page.evaluate_script("blanket.onTestDone();")
13
18
  page.evaluate_script("blanket.onTestsDone();")
14
19
  sleep 0.5 # Allow time for blanketJS and the adapter to prepare the report
15
- @@coverage_data << page.evaluate_script("window.COVERAGE_RESULTS")
16
- flatten!
17
- end
18
-
19
- def flatten!
20
- # go through every line of every file and OR it all together
21
- # e.g. line 1 is 1 and 0, so it is 1
22
- # @@coverage_data should never exceed length 2
20
+ page_data = page.evaluate_script("window.COVERAGE_RESULTS")
21
+ @@coverage_data.accrue! page_data
22
+ return page_data
23
23
  end
24
24
 
25
25
  def generate_report
26
26
  # but for now, so you know it's there...
27
- puts "coverage data length: #{@@coverage_data.length}"
27
+ puts "coverage data length: #{@@coverage_data.inspect}"
28
28
  end
29
29
  end
30
30
  end
@@ -0,0 +1,56 @@
1
+ module Cucumber
2
+ module Blanket
3
+ ##
4
+ # Contains the blanketJS data structure
5
+ # primary purpose is to accumulate more of this data, flattening
6
+ # the structure against multiple runs of fresh data
7
+ class CoverageData
8
+ attr_reader :data
9
+
10
+ def initialize
11
+ @data = nil
12
+ end
13
+
14
+ def method_missing *args
15
+ @data[0].send(*args)
16
+ end
17
+
18
+ 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
+ if @data.nil?
23
+ @data = page_data
24
+ else
25
+ # for files in page_data ...
26
+ page_data[0]['files'].each do |filename, linedata|
27
+ # that exist in @data
28
+ if @data[0]['files'].has_key? page_data[0]['files'].first[0]
29
+ # accrue coverage data, meaning:
30
+ # 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]
33
+ # first we need to deal with nils, as we cannot add them
34
+ # either side can be nil -- and we want to be strictly additive
35
+ next if new_cov_stat.nil? # this is not additive, next line
36
+ # So now we know the new data is definitely not nil
37
+ # but the existing data could be, so we'll handle that now
38
+ if cov_stat.nil?
39
+ @data[0]['files'][filename][line_no] = new_cov_stat
40
+ # We replaced it with the new data, next line please
41
+ next
42
+ end
43
+ # if we ever get here, we're dealing strictly with integers
44
+ # as a result we just need to sum the two stats
45
+ @data[0]['files'][filename][line_no] = cov_stat + new_cov_stat
46
+ end
47
+ else # if it does not exist
48
+ # add it to 'files' as is
49
+ @data[0]['files'][filename] = linedata
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,5 +1,5 @@
1
1
  module Cucumber
2
2
  module Blanket
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,15 @@
1
+ [{
2
+ "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
+ },
5
+ "instrumentation": "blanket",
6
+ "stats": {
7
+ "end": {},
8
+ "failures": 0,
9
+ "passes": 1,
10
+ "pending": 0,
11
+ "start": {},
12
+ "suites": 0,
13
+ "tests": 1
14
+ }
15
+ }]
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cucumber::Blanket::CoverageData do
4
+ let(:page) { FakePage.new }
5
+ let(:covdata) do
6
+ Cucumber::Blanket.extract_from(page)
7
+ Cucumber::Blanket.coverage_data
8
+ end
9
+
10
+ describe "#accrue!" do
11
+ let(:new_page_data) do
12
+ 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
15
+ end
16
+ it "squishes coverage datasets together" do
17
+ covdata["files"].first[1][0].should be_nil
18
+ covdata["files"].first[1][1].should eq 1
19
+ covdata.accrue! new_page_data
20
+ covdata["files"].first[1][0].should eq 3
21
+ covdata["files"].first[1][1].should eq 2
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cucumber::Blanket do
4
+ describe "#extract_from" do
5
+ let(:page) { FakePage.new }
6
+ context "Selenium-returned blanket.js coverage data structure characteristics" do
7
+ let(:cov) do
8
+ subject.extract_from(page)
9
+ subject.coverage_data
10
+ end
11
+ specify { cov.should have_key 'files' }
12
+ it "shows lines of coverage for each javascript file" do
13
+ cov['files'].each do |filename,linedata|
14
+ filename.should match(/.js$/)
15
+ linedata.each_with_index do |cov_stats,line_number|
16
+ line_number.should be_a Integer
17
+ (cov_stats || 0).should be_a Integer # can be nil
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ require 'pry'
2
+ require 'json'
3
+ require 'cucumber/blanket'
4
+
5
+ class FakePage
6
+ attr_reader :coverage_data
7
+
8
+ def initialize
9
+ @coverage_data = parse_fixture_json
10
+ end
11
+
12
+ def parse_fixture_json
13
+ json = File.read(File.join(File.dirname(__FILE__),'fixtures','simple.json'))
14
+ return JSON.parse(json) # How it looks when we get it from Selenium
15
+ end
16
+
17
+ def evaluate_script script
18
+ if script == "window.COVERAGE_RESULTS"
19
+ self.coverage_data
20
+ end
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
+ end
30
+
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keyvan Fatehi
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
41
83
  description: Extract Blanket.js code coverage data from within a Ruby Cucumber environment
42
84
  email:
43
85
  - keyvanfatehi@gmail.com
@@ -46,7 +88,9 @@ extensions: []
46
88
  extra_rdoc_files: []
47
89
  files:
48
90
  - .gitignore
91
+ - .rspec
49
92
  - Gemfile
93
+ - Guardfile
50
94
  - LICENSE.txt
51
95
  - README.md
52
96
  - Rakefile
@@ -54,7 +98,12 @@ files:
54
98
  - javascript/blanket.js
55
99
  - javascript/cucumber-blanket.js
56
100
  - lib/cucumber/blanket.rb
101
+ - lib/cucumber/blanket/coverage_data.rb
57
102
  - lib/cucumber/blanket/version.rb
103
+ - spec/fixtures/simple.json
104
+ - spec/lib/cucumber/blanket/coverage_data_spec.rb
105
+ - spec/lib/cucumber/blanket_spec.rb
106
+ - spec/spec_helper.rb
58
107
  homepage: https://github.com/keyvanfatehi/cucumber-blanket
59
108
  licenses:
60
109
  - MIT
@@ -79,4 +128,8 @@ rubygems_version: 2.0.3
79
128
  signing_key:
80
129
  specification_version: 4
81
130
  summary: Extract Blanket.js code coverage data from within a Ruby Cucumber environment
82
- test_files: []
131
+ test_files:
132
+ - spec/fixtures/simple.json
133
+ - spec/lib/cucumber/blanket/coverage_data_spec.rb
134
+ - spec/lib/cucumber/blanket_spec.rb
135
+ - spec/spec_helper.rb