report_builder 1.3 → 1.4

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: 315748504568c9c1ab74986ef3b436cbe62c836e
4
- data.tar.gz: 577abdb1da309254a44f60e629d2c1839b675075
3
+ metadata.gz: 35b353893ae02902dd4b6c8d07a7f38d66ab57c6
4
+ data.tar.gz: fab6f1b0dad20645c4e8f7f68d43761da94521c6
5
5
  SHA512:
6
- metadata.gz: 5b7d081033b5e69b62ed4d811e62d853ef5d8ec1f75ad73707c6715507c2ba618bed13ba15f3067742934103758502ddd08248682a5ced053cd8b8b94997829a
7
- data.tar.gz: 70a64740b7df9ba6ee7ca2b373cf25abecab23fc7b645e167dde87bd644ad04d724c95ec276c56e5058dcd98e2da699f87183785aa0198d3f700bcf8a249831d
6
+ metadata.gz: 4403905db936a5cd577738d24cfd7553f4fa9ab458226d4f0d56d5f4bf8bcbacf31ea14f0a962360a23f68e670c8df9ca548fa6aea124bca4d62fcbba212708c
7
+ data.tar.gz: 4bb0c1e121f3935bced443fb09903a6a2f6f61893e80497c02424ece1224569af13facb623e371c1f7bc1fdc5a1b654f39aa7fc784e541de9df3acf081b1ca55
@@ -3,7 +3,19 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
 
6
- ## [Unreleased](https://github.com/rajatthareja/ReportBuilder/compare/v1.3...master)
6
+ ## [Unreleased](https://github.com/rajatthareja/ReportBuilder/compare/v1.4...master)
7
+
8
+ ## [1.4](https://github.com/rajatthareja/ReportBuilder/compare/v1.3...v1.4) - 2017-10-29
9
+ ### Fixed
10
+ - Config options Fixed
11
+ - Document Fixed
12
+
13
+ ### Added
14
+ - Grouped Features Report
15
+ - Method to set single option
16
+
17
+ ### Removed
18
+ - Sample Rake Task
7
19
 
8
20
  ## [1.3](https://github.com/rajatthareja/ReportBuilder/compare/v1.2...v1.3) - 2017-10-22
9
21
  ### Changed
data/README.md CHANGED
@@ -1,12 +1,17 @@
1
1
  # ReportBuilder
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/report_builder.svg)](https://badge.fury.io/rb/report_builder)
4
- [![Build status](https://travis-ci.org/rajatthareja/ReportBuilder.svg?branch=master)](https://travis-ci.org/rajatthareja/ReportBuilder)
4
+ [![Build status](https://travis-ci.org/rajatthareja/ReportBuilder.svg?branch=master)](https://travis-ci.org/rajatthareja/ReportBuilder)
5
+ [![Windows Build status](https://ci.appveyor.com/api/projects/status/s5jx2ji3wdg294u6/branch/master?svg=true)](https://ci.appveyor.com/project/rajatthareja/reportbuilder)
5
6
  [![Join the chat at https://gitter.im/rajatthareja/ReportBuilder](https://badges.gitter.im/rajatthareja/ReportBuilder.svg)](https://gitter.im/rajatthareja/ReportBuilder?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6
7
 
7
- Ruby gem to merge Cucumber JSON reports and build mobile friendly HTML Test Report, JSON report and retry file.
8
+ Ruby gem to merge Cucumber JSON reports and build mobile-friendly HTML Test Report, JSON report and retry file.
8
9
 
9
- **[View sample report](http://reportbuilder.rajatthareja.com)**
10
+ ## Sample Reports
11
+
12
+ **[Features Report](http://reportbuilder.rajatthareja.com/sample/report.html)**
13
+
14
+ **[Grouped Features Report](http://reportbuilder.rajatthareja.com/sample/group_report.html)**
10
15
 
11
16
  ## Installation
12
17
 
@@ -27,18 +32,19 @@ gem install report_builder
27
32
 
28
33
  ### Config Options:
29
34
 
30
- | Option | Type | Default | Values |
31
- |-------------------------|--------------------|---------------------|------------------------------------------------------------------------------------------|
32
- | json_path / input_path | [String] / [Array] | (current directory) | input json files path / array of json files or path |
33
- | report_path | [String] | 'test_report' | reports output file path with file name without extension |
34
- | json_report_path | [String] | (report_path) | json report output file path with file name without extension |
35
- | html_report_path | [String] | (report_path) | html report output file path with file name without extension |
36
- | retry_report_path | [String] | (report_path) | retry report output file path with file name without extension |
37
- | report_types | [Array] | [:html] | :json, :html, :retry (output file types) |
38
- | report_title | [String] | 'Test Results' | report and html title |
39
- | include_images | [Boolean] | true | true / false (If false, the size of HTML report is reduced by excluding embedded images) |
40
- | additional_info | [Hash] | {} | additional info for report summary |
41
- | additional_css | [String] | nil | additional CSS string or CSS file path or CSS file url for customizing html report |
35
+ | Option | Type | Default | Values |
36
+ |----------------------|-------------------------|---------------------|------------------------------------------------------------------------------------------|
37
+ | json_path/input_path | [String]/[Array]/[Hash] | (current directory) | input json files path / array of json files or path / hash of json files or path |
38
+ | report_path | [String] | 'test_report' | reports output file path with file name without extension |
39
+ | json_report_path | [String] | (report_path) | json report output file path with file name without extension |
40
+ | html_report_path | [String] | (report_path) | html report output file path with file name without extension |
41
+ | retry_report_path | [String] | (report_path) | retry report output file path with file name without extension |
42
+ | report_types | [Array] | [:html] | :json, :html, :retry (output file types) |
43
+ | report_title | [String] | 'Test Results' | report and html title |
44
+ | include_images | [Boolean] | true | true / false (If false, the size of HTML report is reduced by excluding embedded images) |
45
+ | additional_info | [Hash] | {} | additional info for report summary |
46
+ | additional_css | [String] | nil | additional CSS string or CSS file path or CSS file url for customizing html report |
47
+ | additional_js | [String] | nil | additional JS string or JS file path or JS file url for customizing html report |
42
48
 
43
49
  ### Code Examples:
44
50
 
@@ -72,22 +78,39 @@ gem install report_builder
72
78
 
73
79
  ```
74
80
 
81
+ ### Grouped Features Report Example:
82
+
83
+ ```ruby
84
+
85
+ ReportBuilder.configure do |config|
86
+ config.json_path = config.json_path = {
87
+ 'Group A' => ['path/of/json/files/dir1', 'path/of/json/files/dir2'],
88
+ 'Group B' => ['path/of/json/file1', 'path/of/json/file2'],
89
+ 'Group C' => 'path/of/json/files/dir'}
90
+ end
91
+
92
+ ReportBuilder.build_report
93
+
94
+ ```
95
+
96
+
75
97
  ### CLI Options:
76
98
 
77
- | Option | Values | Explanation |
78
- |---------------------|-----------------|------------------------------------------------------------------------------------|
79
- | -s, --source | x,y,z | List of input json path or files |
80
- | -o, --out | [PATH]NAME | Reports path with name without extension |
81
- | --json_out | [PATH]NAME | JSON report path with name without extension |
82
- | --html_out | [PATH]NAME | HTML report path with name without extension |
83
- | --retry_out | [PATH]NAME | Retry report path with name without extension |
84
- | -f, --format | x,y,z | List of report format - html,json,retry |
85
- | --[no-]images | | Reduce HTML report size by excluding embedded images |
86
- | -T, --title | TITLE | Report title |
87
- | -I, --info | a:x,b:y,c:z | List of additional info about test - key:value |
88
- | --css | STRING|PATH|URL | Additional CSS string or CSS file path or CSS file url for customizing html report |
89
- | -h, --help | | Show available command line switches |
90
- | -v, --version | | Show gem version |
99
+ | Option | Values | Explanation |
100
+ |---------------------|--------------|------------------------------------------------------------------------------------|
101
+ | -s, --source | x,y,z | List of input json path or files |
102
+ | -o, --out | [PATH]NAME | Reports path with name without extension |
103
+ | --json_out | [PATH]NAME | JSON report path with name without extension |
104
+ | --html_out | [PATH]NAME | HTML report path with name without extension |
105
+ | --retry_out | [PATH]NAME | Retry report path with name without extension |
106
+ | -f, --format | x,y,z | List of report format - html,json,retry |
107
+ | --[no-]images | | Reduce HTML report size by excluding embedded images |
108
+ | -T, --title | TITLE | Report title |
109
+ | -I, --info | a:x,b:y,c:z | List of additional info about test - key:value |
110
+ | --css | CSS/PATH/URL | Additional CSS string or CSS file path or CSS file url for customizing html report |
111
+ | --js | JS/PATH/URL | Additional JS string or JS file path or JS file url for customizing html report |
112
+ | -h, --help | | Show available command line switches |
113
+ | -v, --version | | Show gem version |
91
114
 
92
115
  ### CLI Example:
93
116
 
@@ -106,7 +129,13 @@ Add in Rakefile
106
129
  ```ruby
107
130
 
108
131
  require 'report_builder'
109
- load 'report_builder.rake'
132
+
133
+ desc 'Sample rake task to build report'
134
+ task :report_builder, [:json_path, :report_path] do |t, args|
135
+ args.with_defaults(:json_path => nil, :report_path => 'test_report')
136
+ options = {:json_path => args.json_path, :report_path => args.report_path}
137
+ ReportBuilder.build_report options
138
+ end
110
139
 
111
140
  ```
112
141
 
@@ -1,8 +1,9 @@
1
1
  require_relative 'report_builder/builder'
2
2
 
3
-
3
+ ##
4
+ # ReportBuilder Main module
5
+ #
4
6
  module ReportBuilder
5
-
6
7
  ##
7
8
  # Configure ReportBuilder
8
9
  #
@@ -23,6 +24,21 @@ module ReportBuilder
23
24
  builder.options = defaults.marshal_dump
24
25
  end
25
26
 
27
+ ##
28
+ # Set single option
29
+ #
30
+ # @param [String] option
31
+ # @param [Object] value
32
+ #
33
+ # Example:
34
+ #
35
+ # ReportBuilder.set_option('include_images', false)
36
+ #
37
+ def self.set_option(option, value)
38
+ builder.options ||= builder.default_options.marshal_dump
39
+ builder.options[option] = value
40
+ end
41
+
26
42
  ##
27
43
  # Build Report
28
44
  #
@@ -48,5 +64,4 @@ module ReportBuilder
48
64
  def self.builder
49
65
  @builder ||= Builder.new
50
66
  end
51
-
52
67
  end
@@ -2,31 +2,34 @@ require 'json'
2
2
  require 'erb'
3
3
  require 'pathname'
4
4
  require 'base64'
5
+ require 'ostruct'
5
6
 
6
7
  require 'report_builder/core-ext/hash'
7
8
 
8
9
  module ReportBuilder
10
+ ##
11
+ # ReportBuilder Main class
12
+ #
9
13
  class Builder
10
14
 
11
15
  attr_accessor :options
12
16
 
17
+ ##
18
+ # ReportBuilder Main method
19
+ #
13
20
  def build_report(opts = nil)
14
21
  options = self.options || default_options.marshal_dump
15
22
  options.merge! opts if opts.is_a? Hash
16
23
 
17
- raise 'Error:: Invalid report_types. Use: [:json, :html]' unless options[:report_types].is_a? Array
18
-
24
+ fail 'Error:: Invalid report_types. Use: [:json, :html]' unless options[:report_types].is_a? Array
19
25
  options[:report_types].map!(&:to_s).map!(&:upcase)
20
26
 
21
- options[:json_path] ||= options[:input_path]
22
- files = get_files options[:json_path]
23
- raise "Error:: No file(s) found at #{options[:json_path]}" if files.empty?
24
-
25
- features = get_features(files) rescue raise('Error:: Invalid Input File(s). Please provide valid cucumber JSON output file(s)')
27
+ options[:input_path] ||= options[:json_path] || Dir.pwd
28
+ groups = get_groups options[:input_path]
26
29
 
27
30
  json_report_path = options[:json_report_path] || options[:report_path]
28
31
  File.open(json_report_path + '.json', 'w') do |file|
29
- file.write JSON.pretty_generate features
32
+ file.write JSON.pretty_generate(groups.size > 1 ? groups : groups.first['features'])
30
33
  end if options[:report_types].include? 'JSON'
31
34
 
32
35
  if options[:additional_css] and Pathname.new(options[:additional_css]).file?
@@ -39,33 +42,65 @@ module ReportBuilder
39
42
 
40
43
  html_report_path = options[:html_report_path] || options[:report_path]
41
44
  File.open(html_report_path + '.html', 'w') do |file|
42
- file.write ERB.new(File.read(File.dirname(__FILE__) + '/../../template/html_report.erb')).result(binding).gsub(' ', '').gsub("\n\n", '')
45
+ file.write get(groups.size > 1 ? 'group_report' : 'report').result(binding).gsub(' ', '').gsub("\n\n", '')
43
46
  end if options[:report_types].include? 'HTML'
44
47
 
45
48
  retry_report_path = options[:retry_report_path] || options[:report_path]
46
49
  File.open(retry_report_path + '.retry', 'w') do |file|
47
- features.each do |feature|
48
- if feature['status'] == 'broken'
49
- feature['elements'].each {|scenario| file.puts "#{feature['uri']}:#{scenario['line']}" if scenario['status'] == 'failed'}
50
+ groups.each do |group|
51
+ group['features'].each do |feature|
52
+ if feature['status'] == 'broken'
53
+ feature['elements'].each {|scenario| file.puts "#{feature['uri']}:#{scenario['line']}" if scenario['status'] == 'failed'}
54
+ end
50
55
  end
51
56
  end
52
57
  end if options[:report_types].include? 'RETRY'
53
58
  [json_report_path, html_report_path, retry_report_path]
54
59
  end
55
60
 
61
+ ##
62
+ # ReportBuilder default configuration
63
+ #
56
64
  def default_options
57
- OpenStruct.new(
58
- json_path: Dir.pwd, # [String] / [Array] Input json file, array of json files/path or json files path, (Default current directory)
59
- report_path: 'test_report', # [String] Output file path with name
60
- report_types: [:html], # [Array] Output file types to build, [:json, :html] or ['html', 'json']
61
- report_title: 'Test Results', # [String] Report and html title
62
- include_images: true, # [Boolean] Set false to reducing the size of HTML report, by excluding embedded images
63
- additional_info: {} # [Hash] Additional info for report
65
+ OpenStruct.new(json_path: nil,
66
+ input_path: nil,
67
+ report_types: [:html],
68
+ report_title: 'Test Results',
69
+ include_images: true,
70
+ additional_info: {},
71
+ report_path: 'test_report',
72
+ json_report_path: nil,
73
+ html_report_path: nil,
74
+ retry_report_path: nil,
75
+ additional_css: nil,
76
+ additional_js: nil
64
77
  )
65
78
  end
66
79
 
67
80
  private
68
81
 
82
+ def get(template)
83
+ @erb ||= {}
84
+ @erb[template] ||= ERB.new(File.read(File.dirname(__FILE__) + '/../../template/' + template + '.erb'), nil, nil, '_' + template)
85
+ end
86
+
87
+ def get_groups(input_path)
88
+ groups = []
89
+ if input_path.is_a? Hash
90
+ input_path.each do |group_name, group_path|
91
+ files = get_files group_path
92
+ puts "Error:: No file(s) found at #{group_path}" if files.empty?
93
+ groups << {'name' => group_name, 'features' => get_features(files)} rescue next
94
+ end
95
+ fail 'Error:: Invalid Input File(s). Please provide valid cucumber JSON output file(s)' if groups.empty?
96
+ else
97
+ files = get_files input_path
98
+ fail "Error:: No file(s) found at #{input_path}" if files.empty?
99
+ groups << {'features' => get_features(files)} rescue fail('Error:: Invalid Input File(s). Please provide valid cucumber JSON output file(s)')
100
+ end
101
+ groups
102
+ end
103
+
69
104
  def get_files(path)
70
105
  if path.is_a?(String) and Pathname.new(path).exist?
71
106
  if Pathname.new(path).directory?
@@ -1,18 +1,18 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'report_builder'
3
- s.version = '1.3'
3
+ s.version = '1.4'
4
4
  s.bindir = 'bin'
5
5
  s.summary = 'ReportBuilder'
6
- s.description = 'Ruby gem to merge Cucumber JSON reports and build mobile friendly HTML Test Report, JSON report and retry file.'
6
+ s.description = 'Ruby gem to merge Cucumber JSON reports and build mobile-friendly HTML Test Report, JSON report and retry file.'
7
7
  s.post_install_message = 'Happy reporting!'
8
8
  s.authors = ['Rajat Thareja']
9
9
  s.email = 'rajat.thareja.1990@gmail.com'
10
- s.homepage = 'https://github.com/rajatthareja/ReportBuilder'
10
+ s.homepage = 'http://reportbuilder.rajatthareja.com'
11
11
  s.license = 'MIT'
12
12
  s.required_ruby_version = '>= 1.9.1'
13
13
  s.requirements << 'Cucumber >= 2.1.0 test results in JSON format'
14
14
 
15
- s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(docs|css|js|pkg|testing|coverage)/}) }
15
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(sample/|css/|js/|pkg/|testing/|coverage/|CNAME|.gitignore|appveyor.yml|.travis.yml|_config.yml|Gemfile|Rakefile|rb.ico)}) }
16
16
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  s.test_files = s.files.grep(%r{^(testing)/})
18
18
 
@@ -0,0 +1,21 @@
1
+ <li class="error">
2
+ <div class="collapsible-header red lighten-2 white-text waves-effect waves-light">
3
+ <i class="material-icons">bug_report</i><%= error %>
4
+ </div>
5
+
6
+ <div class="collapsible-body brown lighten-4">
7
+ <ul class="collection failedScenarioList">
8
+ <% features.each_with_index do |feature, f| %>
9
+ <% feature['elements'].each_with_index do |scenario, s| %>
10
+ <% if scenario['error'] %>
11
+ <% if scenario['error'] == error %>
12
+ <li class="collection-item failedScenario brown lighten-5 red-text">
13
+ <i class="material-icons">highlight_off</i>&nbsp;<a class="modal-trigger red-text" href="#<%= "#{gid}f#{f}s#{s}" %>"><%= scenario['name'] %></a>
14
+ </li>
15
+ <% end %>
16
+ <% end %>
17
+ <% end %>
18
+ <% end %>
19
+ </ul>
20
+ </div>
21
+ </li>
@@ -0,0 +1,5 @@
1
+ <ul class="errorList collapsible popout" data-collapsible="expandable">
2
+ <% errors.uniq.each do |error| %>
3
+ <%= get('error').result(binding) %>
4
+ <% end %>
5
+ </ul>
@@ -0,0 +1,18 @@
1
+ <li class="feature <%= feature['status'] %>">
2
+ <div class="collapsible-header brown lighten-1 waves-effect waves-light">
3
+ <i class="material-icons">featured_play_list</i>
4
+ <b><%= feature['keyword'] %></b>&nbsp;<%= feature['name'] %>&nbsp;(<%= duration(feature['duration']) %>)
5
+ </div>
6
+
7
+ <div class="collapsible-body brown lighten-4">
8
+ <ul class="collection scenarioList">
9
+ <% feature['elements'].each_with_index do |scenario, s| %>
10
+ <li class="collection-item scenario <%= scenario['status'] %>">
11
+ <a class="waves-effect waves-light modal-trigger white-text" href="#<%= "#{fid}s#{s}" %>">
12
+ <b><%= scenario['keyword'] %></b> <%= scenario['name'] %>&nbsp;(<%= duration(scenario['duration']) %>)
13
+ </a>
14
+ </li>
15
+ <% end %>
16
+ </ul>
17
+ </div>
18
+ </li>
@@ -0,0 +1,6 @@
1
+ <ul class="featureList collapsible popout" data-collapsible="expandable">
2
+ <% features.each_with_index do |feature, f| %>
3
+ <% fid = "#{gid}f#{f}" %>
4
+ <%= get('feature').result(binding) %>
5
+ <% end %>
6
+ </ul>
@@ -0,0 +1,20 @@
1
+ <footer class="page-footer brown lighten-4">
2
+ <div class="footer-copyright brown lighten-1">
3
+ <div class="container">
4
+ Happy Reporting!
5
+ <a class="white-text text-lighten-4 right" href="http://reportbuilder.rajatthareja.com">Generated by Report Builder</a>
6
+ </div>
7
+ </div>
8
+ </footer>
9
+
10
+ <script type="text/javascript" src="https://cdn.rawgit.com/rajatthareja/ReportBuilder/v1.4/js/report.builder.min.js"></script>
11
+
12
+ <% if options[:additional_js] %>
13
+ <% if options[:additional_js] =~ /^http(|s):\/\/.*\.js$/ %>
14
+ <script src="<%= options[:additional_js] %>"></script>
15
+ <% else %>
16
+ <script type="text/javascript">
17
+ <%= options[:additional_js]%>
18
+ </script>
19
+ <% end %>
20
+ <% end %>
@@ -0,0 +1,18 @@
1
+ <ul class="groupErrorList collapsible popout" data-collapsible="expandable">
2
+ <% groups.each_with_index do |group, g| %>
3
+
4
+ <% gid = "g#{g}" %>
5
+ <% features = group['features'] %>
6
+ <li class="groupError">
7
+
8
+ <div class="collapsible-header red lighten-2 white-text waves-effect waves-light">
9
+ <i class="material-icons">group_work</i>
10
+ <b><%= group['name'] %></b>
11
+ </div>
12
+
13
+ <div class="collapsible-body brown lighten-4">
14
+ <%= get('errors').result(binding) %>
15
+ </div>
16
+ </li>
17
+ <% end %>
18
+ </ul>
@@ -0,0 +1,18 @@
1
+ <ul class="groupList collapsible popout" data-collapsible="expandable">
2
+ <% groups.each_with_index do |group, g| %>
3
+
4
+ <% gid = "g#{g}" %>
5
+ <% features = group['features'] %>
6
+ <li class="group">
7
+
8
+ <div class="collapsible-header brown lighten-1 waves-effect waves-light">
9
+ <i class="material-icons">group_work</i>
10
+ <b><%= group['name'] %></b>&nbsp;(<%= duration(total_time(features)) %>)
11
+ </div>
12
+
13
+ <div class="collapsible-body brown lighten-4">
14
+ <%= get('features').result(binding) %>
15
+ </div>
16
+ </li>
17
+ <% end %>
18
+ </ul>