suiteview 2.0.1 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/suiteview.rb +62 -27
  3. metadata +45 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c709ba98435b663cba7c18f576061a1bae25fce3fdb152d69f9a2708a647cff2
4
- data.tar.gz: d9f6efe857796d8dc432c1f8949cf8e8447fabf87783d5294370ff7044569efd
3
+ metadata.gz: bc3d14c800ffc83b237e71923484783cd7360bd84f37151f53fed9cfe33ea1c6
4
+ data.tar.gz: baae20f73d79a8e79810a8ef0993e82a0526ca14362043767ea55c79cdeaada1
5
5
  SHA512:
6
- metadata.gz: 170a7e0a5443c10d95223dc1f6b070abc861dcc1881905d8b309a4d692976a40ee622d6b50cb789d8811e61abe635f79430f81c8197142284c069ad119cdb6b0
7
- data.tar.gz: f5c5ecff8920a67b7800c0f90c58f42e2b214130a4df28c6e5d1751db9a2ea40e67b289fd7785568b0d5084617624cf20c0b62ecd16e58c6080ebcdb228f047b
6
+ metadata.gz: 0bfe734a751c11ce061faba67253d4c41e9a80c0f430589cdc73e5e02cd1d0432b6d2c6bd8d8529f3793401d04532d03ca5c8175f99eabe8d7e7a4d0bfcc41ab
7
+ data.tar.gz: cf21d411cebda7188151d8ff5434499db1fdab2092305e10df76e433b043de66bcc23b06f7c238fb14d8465aeb9796225a29b900bf1141f962bd9101b333bc47
data/lib/suiteview.rb CHANGED
@@ -1,29 +1,24 @@
1
1
  require 'cql'
2
2
  require 'csv'
3
+ require_relative './suitestat'
4
+ # SuiteView is responsible for providing consumable Ruby Cucumber suite stats
3
5
  class SuiteView
4
6
  attr_accessor :repo, :include_tags, :output
7
+
5
8
  def initialize(opts)
6
9
  self.output = nil
7
10
  self.repo = CQL::Repository.new(opts[:repo])
8
- self.include_tags = opts[:include_tags]
11
+ self.include_tags = opts[:include_tags] || ""
12
+ self.include_tags = self.include_tags.split(',')
9
13
  end
10
14
 
11
15
  def outline_tag_count(tag)
12
- self.output = self.repo.query do
13
- select examples
14
- transform examples => lambda {|examples| examples[0].rows.drop(1) }
15
- from outlines
16
- with { |outline| outline.tags.map(&:name).include?(tag)}
17
- end.map {|item| item['examples']}.flatten.count
16
+ self.output = outline_query(tag).map { |item| item['examples'] }.flatten.count
18
17
  self
19
18
  end
20
19
 
21
20
  def scenario_tag_count(tag)
22
- self.output = self.repo.query do
23
- select name
24
- from scenarios
25
- with { |scenario| scenario.tags.map(&:name).include?(tag)}
26
- end.map {|item| item['name']}.count
21
+ self.output = scenario_query(tag).map { |item| item['name'] }.count
27
22
  self
28
23
  end
29
24
 
@@ -32,26 +27,24 @@ class SuiteView
32
27
  self
33
28
  end
34
29
 
35
- def percentages
36
- output = [%w(tag percent)]
37
- total_count = 0
38
- tag_counts = {}
39
- self.include_tags.split(',').each do |include_tag|
40
- total_count += total_tag_count(include_tag).render
41
- tag_counts[include_tag] = total_tag_count(include_tag).render
42
- end
43
- self.include_tags.split(',').each do |include_tag|
44
- output << [include_tag, ((tag_counts[include_tag]/total_count.to_f)*100).to_s]
30
+ def total_tags_count
31
+ output = [%w(tag count)]
32
+ self.include_tags.each do |tag|
33
+ output << [tag, total_tag_count(tag).render.to_s]
45
34
  end
46
35
  self.output = output
47
36
  self
48
37
  end
49
38
 
39
+ def percentages
40
+ suite_stat_dto = SuiteStat.new([%w(tag percent)], 0, {})
41
+ self.output = calc_percentage(suite_stat_dto)
42
+ self
43
+ end
44
+
50
45
  def to_csv
51
46
  self.output = CSV.generate do |csv|
52
- self.output.each do |row|
53
- csv << row
54
- end
47
+ self.output.each { |row| csv << row }
55
48
  end
56
49
  self
57
50
  end
@@ -61,8 +54,50 @@ class SuiteView
61
54
  end
62
55
 
63
56
  def render_to_file(filename)
64
- File.open(filename, "w") do |f|
65
- f.puts self.output
57
+ File.open(filename, "w") do |file|
58
+ file.puts self.output
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def calc_percentage(suite_stat_dto)
65
+ suite_stat_dto.total_count = calc_percentage_totals(suite_stat_dto)
66
+ collate_percentage_rows(suite_stat_dto)
67
+ end
68
+
69
+ def collate_percentage_rows(suite_stat_dto)
70
+ output = suite_stat_dto.output
71
+ self.include_tags.each do |include_tag|
72
+ output << [include_tag, ((suite_stat_dto.tag_counts[include_tag] / suite_stat_dto.total_count.to_f) * 100).to_s]
73
+ end
74
+ output
75
+ end
76
+
77
+ def calc_percentage_totals(suite_stat_dto)
78
+ total_count = suite_stat_dto.total_count
79
+ self.include_tags.each do |include_tag|
80
+ count_for_tag = total_tag_count(include_tag)
81
+ total_count += count_for_tag.render
82
+ suite_stat_dto.tag_counts[include_tag] = count_for_tag.render
83
+ end
84
+ total_count
85
+ end
86
+
87
+ def outline_query(tag)
88
+ self.repo.query do
89
+ select examples
90
+ transform examples => lambda { |examples| examples[0].rows.drop(1) }
91
+ from outlines
92
+ with { |outline| outline.tags.map(&:name).include?(tag) }
93
+ end
94
+ end
95
+
96
+ def scenario_query(tag)
97
+ self.repo.query do
98
+ select name
99
+ from scenarios
100
+ with { |scenario| scenario.tags.map(&:name).include?(tag) }
66
101
  end
67
102
  end
68
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: suiteview
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David West
@@ -66,8 +66,50 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
- description: suiteview is a tool to help show the contents of a cucumber suite with
70
- your unique specifications
69
+ description: |
70
+ suiteview is a tool to help show the contents of a cucumber suite with your unique specifications
71
+
72
+ `my_suiteview.rb`
73
+
74
+ ```ruby
75
+ require "suiteview"
76
+
77
+ # Instantiate the SuiteView class and give it the location of your Cucumber Suite (repo)
78
+ sv = SuiteView.new({repo: "features", include_tags: "@tweets,@followers"})
79
+
80
+ # Get a count of all Scenarios directly tagged with a particular tag
81
+ sv.percentages.to_csv.render_to_file("my.csv")
82
+ ```
83
+
84
+ And you'll have your output
85
+
86
+ `my.csv`
87
+
88
+ ```csv
89
+ tag,percent
90
+ @tweets,80.0
91
+ @followers,20.0
92
+ ```
93
+
94
+ `my_suiteview2.rb`
95
+
96
+ ```ruby
97
+ require "suiteview"
98
+
99
+ # Instantiate the SuiteView class and give it the location of your Cucumber Suite (repo)
100
+ sv = SuiteView.new({repo: "features", include_tags: "@tweets,@followers"})
101
+
102
+ # Get a count of all Scenarios directly tagged with a particular tag
103
+ sv.total_tags_count.to_csv.render_to_file("my2.csv")
104
+ ```
105
+
106
+ `my2.csv`
107
+
108
+ ```csv
109
+ tag,count
110
+ @tweets,4
111
+ @followers,1
112
+ ```
71
113
  email: support@suiteview.xyz
72
114
  executables: []
73
115
  extensions: []