suiteview 2.1.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 +55 -29
  3. metadata +45 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d356f59f9bdf8d487f9ca66f68d57d427a3bf167fe70b5747830f89f795f843
4
- data.tar.gz: 1c2f8d308166f27e6bbb8693b46fcb688feb6ca2a7981b707ebf6afaa9023c36
3
+ metadata.gz: bc3d14c800ffc83b237e71923484783cd7360bd84f37151f53fed9cfe33ea1c6
4
+ data.tar.gz: baae20f73d79a8e79810a8ef0993e82a0526ca14362043767ea55c79cdeaada1
5
5
  SHA512:
6
- metadata.gz: '094e329d4a113e89db20d068057600a2a498058508bf9bb43a047cd4ee009df4b2b97ea129ce7a7b31762358eb9c84b41cc837ae9e9052cb8df38698ab5f770e'
7
- data.tar.gz: 6c2884c43863302966b7457d8c821bc9d8111f36b2077efe55612e8323f43074d79cf27dbf0dddcffc0b11e3b2640de4b7eb22ee2e27ce0f32149ecd78156a72
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
 
@@ -34,7 +29,7 @@ class SuiteView
34
29
 
35
30
  def total_tags_count
36
31
  output = [%w(tag count)]
37
- self.include_tags.split(',').each do |tag|
32
+ self.include_tags.each do |tag|
38
33
  output << [tag, total_tag_count(tag).render.to_s]
39
34
  end
40
35
  self.output = output
@@ -42,25 +37,14 @@ class SuiteView
42
37
  end
43
38
 
44
39
  def percentages
45
- output = [%w(tag percent)]
46
- total_count = 0
47
- tag_counts = {}
48
- self.include_tags.split(',').each do |include_tag|
49
- total_count += total_tag_count(include_tag).render
50
- tag_counts[include_tag] = total_tag_count(include_tag).render
51
- end
52
- self.include_tags.split(',').each do |include_tag|
53
- output << [include_tag, ((tag_counts[include_tag]/total_count.to_f)*100).to_s]
54
- end
55
- self.output = output
40
+ suite_stat_dto = SuiteStat.new([%w(tag percent)], 0, {})
41
+ self.output = calc_percentage(suite_stat_dto)
56
42
  self
57
43
  end
58
44
 
59
45
  def to_csv
60
46
  self.output = CSV.generate do |csv|
61
- self.output.each do |row|
62
- csv << row
63
- end
47
+ self.output.each { |row| csv << row }
64
48
  end
65
49
  self
66
50
  end
@@ -70,8 +54,50 @@ class SuiteView
70
54
  end
71
55
 
72
56
  def render_to_file(filename)
73
- File.open(filename, "w") do |f|
74
- 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) }
75
101
  end
76
102
  end
77
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.1.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: []