rspec_pretty_html_reporter 1.1.5 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16bb422e791336c92b321c062f3b5dfa878253d81f2ce4519bed2f18d345e299
4
- data.tar.gz: 53c9e939c7616e86badb14d26d5b03e9bcc579c9c88ea929bfe7f22465b1fa66
3
+ metadata.gz: 989a30971d82398d7880345a90ff3fbea0a3a790ea0e381b90e2a15714d53b6b
4
+ data.tar.gz: 6c31be855be029651381cadd72492c999a4cbb311bcc91ea058ae5fe9ed9f294
5
5
  SHA512:
6
- metadata.gz: 81fbe3a4d4b385a52d02812ce3b2ad9beae805a654a5d018c211e4f74474a37dc22b26dc22cf24bb8848958dc7c5a5adc196cf2193435267cf5ba18f71509775
7
- data.tar.gz: d7628ba61e2b7f2a3e47516807f6cd09b40b82e365fe7828d381937e36d70020864afff2d77990d799a20a3342f72347f5f1058ef5dec4d399a550c0e0b60e4c
6
+ metadata.gz: 99859592e5abba752b44110a13f6abbc707e6557bdf1984903576beed48bf32f84f8a8a715d577d5bda500828e1aa128abdbd648445c27b2a6a61099d4f9edfc
7
+ data.tar.gz: 1f5169670f431cef993d5b56b49401353f11a198a9dafdc160e7c2c8de19ebbee0837af928a82a92a8d712b2267720c23e0c9cb161b706fbf50107e44e236d8b
data/README.md CHANGED
@@ -36,6 +36,21 @@ REPORT_PATH=reports/$(date +%s) bundle exec rspec --format RspecPrettyHtmlReport
36
36
 
37
37
  This will create the reports in the `reports` directory.
38
38
 
39
+ ## Parallel tests
40
+
41
+ The reporter supports [parallel_tests](https://github.com/grosser/parallel_tests). Give every worker the same
42
+ `REPORT_PATH`, because the default path holds the start time of each process:
43
+
44
+ ```bash
45
+ REPORT_PATH=reports/latest bundle exec parallel_rspec -- --format RspecPrettyHtmlReporter --
46
+ ```
47
+
48
+ The first worker of a run empties the report directory. Every worker adds the reports of its spec groups, and the
49
+ last worker to finish writes the overview of all the groups. The workers use a `<REPORT_PATH>.lock` file next to the
50
+ report directory.
51
+
52
+ A worker saves its groups when it finishes. If a worker crashes, the overview does not list its groups.
53
+
39
54
  ## Usage
40
55
 
41
56
  Images and videos can be embed by adding their path into example's metadata. For an example of how to do this, please
@@ -66,9 +66,9 @@ class Example
66
66
  end
67
67
 
68
68
  def set_spec(spec_text)
69
- formatter = Rouge::Formatters::HTMLLegacy.new(css_class: 'highlight')
69
+ formatter = Rouge::Formatters::HTML.new
70
70
  lexer = Rouge::Lexers::Gherkin.new
71
- @spec = formatter.format(lexer.lex(spec_text.gsub('#->', '')))
71
+ @spec = %(<div class="highlight"><pre class="highlight"><code>#{formatter.format(lexer.lex(spec_text.gsub('#->', '')))}</code></pre></div>)
72
72
  end
73
73
 
74
74
  def klass(prefix = 'badge-')
@@ -64,16 +64,19 @@ class Oopsy
64
64
  start_line = line_number - 2
65
65
  end_line = line_number + 3
66
66
  source = lines[start_line..end_line].join('').sub(lines[line_number - 1].chomp, "--->#{lines[line_number - 1].chomp}")
67
- formatter = Rouge::Formatters::HTMLLegacy.new(css_class: 'highlight', line_numbers: true, start_line: start_line + 1)
67
+ formatter = Rouge::Formatters::HTMLTable.new(
68
+ Rouge::Formatters::HTML.new,
69
+ start_line: start_line + 1
70
+ )
68
71
  lexer = Rouge::Lexers::Ruby.new
69
- original_format = formatter.format(lexer.lex(source.encode('utf-8')))
72
+ original_format = %(<div class="highlight"><pre class="highlight"><code>#{formatter.format(lexer.lex(source.encode('utf-8')))}</code></pre></div>)
70
73
  original_format.gsub!(/<table class="rouge-table">/, '<table class="rouge-table" style="width:100%">')
71
74
  end
72
75
  end
73
76
 
74
77
  def process_message
75
- formatter = Rouge::Formatters::HTMLLegacy.new(css_class: 'highlight pl-3')
78
+ formatter = Rouge::Formatters::HTML.new
76
79
  lexer = Rouge::Lexers::Ruby.new
77
- formatter.format(lexer.lex(@message))
80
+ %(<div class="highlight"><pre class="highlight pl-3"><code>#{formatter.format(lexer.lex(@message))}</code></pre></div>)
78
81
  end
79
82
  end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'json'
5
+
6
+ ##
7
+ # Lets the workers of one parallel_tests run share a report directory.
8
+ #
9
+ # Every worker of a run gets the same PARALLEL_PID_FILE, so it identifies the run.
10
+ # The first worker of a new run empties the report directory. The other workers keep
11
+ # what it contains. Each worker saves its groups as JSON, and each worker writes the
12
+ # overview from the groups of all the workers that have finished. The last worker to
13
+ # finish writes the complete overview.
14
+ #
15
+ # Outside parallel_tests, or with a parallel_tests version that does not set
16
+ # PARALLEL_PID_FILE, the reporter works as one process.
17
+ ##
18
+ module RspecPrettyHtmlParallel
19
+ STATE_DIR = '.parallel'
20
+
21
+ def self.worker?
22
+ !ENV['PARALLEL_TEST_GROUPS'].to_s.empty? && !ENV['PARALLEL_PID_FILE'].to_s.empty?
23
+ end
24
+
25
+ ##
26
+ # Runs the block while it holds a lock that all the workers share.
27
+ # A single process does not lock.
28
+ # @param [String] report_path The report directory
29
+ ##
30
+ def self.synchronize(report_path)
31
+ return yield unless worker?
32
+
33
+ # A trailing separator would put the lock file inside the report directory,
34
+ # which the first worker of a run deletes.
35
+ report_path = File.expand_path(report_path)
36
+ FileUtils.mkpath(File.dirname(report_path))
37
+ File.open("#{report_path}.lock", File::RDWR | File::CREAT) do |lock|
38
+ lock.flock(File::LOCK_EX)
39
+ yield
40
+ end
41
+ end
42
+
43
+ ##
44
+ # @param [String] report_path The report directory
45
+ # @return [Boolean] True when another worker of this run has prepared the report directory
46
+ ##
47
+ def self.current_run?(report_path)
48
+ File.read(run_file(report_path)) == ENV['PARALLEL_PID_FILE']
49
+ rescue Errno::ENOENT
50
+ false
51
+ end
52
+
53
+ ##
54
+ # Records that the report directory belongs to this run.
55
+ # @param [String] report_path The report directory
56
+ ##
57
+ def self.mark_run(report_path)
58
+ FileUtils.mkpath(File.join(report_path, STATE_DIR))
59
+ File.write(run_file(report_path), ENV['PARALLEL_PID_FILE'])
60
+ end
61
+
62
+ ##
63
+ # Saves the groups of this worker, then returns the groups of all the workers that have finished.
64
+ # A worker that dies while it writes leaves only a temporary file, which the merge ignores.
65
+ # The merge also skips a groups file that does not parse, so one bad file costs only its own groups.
66
+ # @param [String] report_path The report directory
67
+ # @param [Hash] groups The groups of this worker, by the name of their report file
68
+ # @return [Hash] The groups of all the finished workers, in worker order
69
+ ##
70
+ def self.merge_groups(report_path, groups)
71
+ path = groups_file(report_path, worker_number)
72
+ File.write("#{path}.tmp", JSON.generate(groups))
73
+ File.rename("#{path}.tmp", path)
74
+
75
+ Dir[groups_file(report_path, '*')].sort_by { |file| file[/(\d+)\.json\z/, 1].to_i }.each_with_object({}) do |file, all|
76
+ JSON.parse(File.read(file), symbolize_names: true).each { |name, group| all[name.to_s] = group }
77
+ rescue JSON::ParserError
78
+ next
79
+ end
80
+ end
81
+
82
+ ##
83
+ # The first worker has an empty TEST_ENV_NUMBER, unless parallel_tests runs with --first-is-1.
84
+ ##
85
+ def self.worker_number
86
+ ENV['TEST_ENV_NUMBER'].to_s.empty? ? 1 : ENV['TEST_ENV_NUMBER'].to_i
87
+ end
88
+
89
+ def self.run_file(report_path)
90
+ File.join(report_path, STATE_DIR, 'run')
91
+ end
92
+
93
+ def self.groups_file(report_path, number)
94
+ File.join(report_path, STATE_DIR, "groups-#{number}.json")
95
+ end
96
+ end
@@ -7,6 +7,7 @@ require 'fileutils'
7
7
  require 'erb'
8
8
  require 'rspec_pretty_html_reporter/example'
9
9
  require 'rspec_pretty_html_reporter/helpers'
10
+ require 'rspec_pretty_html_reporter/parallel'
10
11
 
11
12
  I18n.enforce_available_locales = false
12
13
 
@@ -23,10 +24,9 @@ class RspecPrettyHtmlReporter < RSpec::Core::Formatters::BaseFormatter
23
24
  :example_group_finished
24
25
 
25
26
  def initialize(_io_standard_out)
26
- create_reports_dir
27
+ prepare_reports_dir
27
28
  create_screenshots_dir
28
29
  create_screenrecords_dir
29
- copy_resources
30
30
  @all_groups = {}
31
31
  @group_level = 0
32
32
  @theme = Helpers.theme(ENV['THEME'])
@@ -68,7 +68,7 @@ class RspecPrettyHtmlReporter < RSpec::Core::Formatters::BaseFormatter
68
68
  @group_level -= 1
69
69
 
70
70
  if @group_level.zero?
71
- @filename = Helpers.rename_duplicate_filename("#{REPORT_PATH}/#{notification.group.description.parameterize}.html")
71
+ @filename = reserve_filename("#{REPORT_PATH}/#{notification.group.description.parameterize}.html")
72
72
 
73
73
  File.open(@filename, 'w') do |f|
74
74
  @passed = @group_example_success_count
@@ -98,7 +98,8 @@ class RspecPrettyHtmlReporter < RSpec::Core::Formatters::BaseFormatter
98
98
  else
99
99
  (statuses.include?('passed') ? 'passed' : 'pending')
100
100
  end
101
- @spec_description = Helpers.rename_duplicate_description(@all_groups, notification.group.description.parameterize)
101
+ # The overview links to the report file, so the file name is the key. It stays unique across parallel workers.
102
+ @spec_description = File.basename(@filename, '.html')
102
103
  @all_groups[@spec_description] = {
103
104
  group: notification.group.description,
104
105
  examples: @examples.size,
@@ -118,9 +119,15 @@ class RspecPrettyHtmlReporter < RSpec::Core::Formatters::BaseFormatter
118
119
  end
119
120
  end
120
121
 
121
- def close(notification)
122
+ def close(_notification)
123
+ RspecPrettyHtmlParallel.synchronize(REPORT_PATH) { write_overview }
124
+ end
125
+
126
+ private
127
+
128
+ def write_overview
122
129
  File.open("#{REPORT_PATH}/overview.html", 'w') do |f|
123
- @overview = @all_groups
130
+ @overview = RspecPrettyHtmlParallel.worker? ? RspecPrettyHtmlParallel.merge_groups(REPORT_PATH, @all_groups) : @all_groups
124
131
 
125
132
  @passed = @overview.values.map { |g| g[:passed].size }.inject(0) { |sum, i| sum + i }
126
133
  @failed = @overview.values.map { |g| g[:failed].size }.inject(0) { |sum, i| sum + i }
@@ -144,11 +151,25 @@ class RspecPrettyHtmlReporter < RSpec::Core::Formatters::BaseFormatter
144
151
  end
145
152
  end
146
153
 
147
- private
154
+ # A parallel worker empties the report directory only when it is the first worker of a new run.
155
+ def prepare_reports_dir
156
+ RspecPrettyHtmlParallel.synchronize(REPORT_PATH) do
157
+ create_reports_dir unless RspecPrettyHtmlParallel.worker? && RspecPrettyHtmlParallel.current_run?(REPORT_PATH)
158
+ end
159
+ end
148
160
 
149
161
  def create_reports_dir
150
162
  FileUtils.rm_rf(REPORT_PATH) if File.exist?(REPORT_PATH)
151
163
  FileUtils.mkpath(REPORT_PATH)
164
+ copy_resources
165
+ RspecPrettyHtmlParallel.mark_run(REPORT_PATH) if RspecPrettyHtmlParallel.worker?
166
+ end
167
+
168
+ # Picks a free file name and creates the file, so a parallel worker cannot pick the same name.
169
+ def reserve_filename(filename)
170
+ RspecPrettyHtmlParallel.synchronize(REPORT_PATH) do
171
+ Helpers.rename_duplicate_filename(filename).tap { |name| FileUtils.touch(name) }
172
+ end
152
173
  end
153
174
 
154
175
  def create_screenshots_dir
@@ -11,8 +11,8 @@
11
11
  <link href="resources/bootstrap-4.0.0-dist/themes/bootstrap-theme-<%= @theme %>.min.css" rel="stylesheet">
12
12
 
13
13
  <script src="resources/js/jquery-1.11.1.min.js"></script>
14
+ <script src="resources/tether-1.3.3-dist/js/tether.min.js"></script>
14
15
  <script src="resources/bootstrap-4.0.0-dist/js/bootstrap.min.js"></script>
15
- <script src="resources/tether-1.3.3/js/tether.min.js"></script>
16
16
  <script src="resources/js/chart-3.7.1.js"></script>
17
17
  <style>
18
18
  * {
data/templates/report.erb CHANGED
@@ -11,8 +11,8 @@
11
11
  <link href="resources/bootstrap-4.0.0-dist/themes/bootstrap-theme-<%= @theme %>.min.css" rel="stylesheet">
12
12
 
13
13
  <script src="resources/js/jquery-1.11.1.min.js"></script>
14
+ <script src="resources/tether-1.3.3-dist/js/tether.min.js"></script>
14
15
  <script src="resources/bootstrap-4.0.0-dist/js/bootstrap.min.js"></script>
15
- <script src="resources/tether-1.3.3/js/tether.min.js"></script>
16
16
  <script src="resources/js/chart-3.7.1.js"></script>
17
17
  <style>
18
18
  * {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_pretty_html_reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Gutierrez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-15 00:00:00.000000000 Z
11
+ date: 2026-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 4.1.4
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 7.1.3
22
+ version: '9.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,35 +29,41 @@ dependencies:
29
29
  version: 4.1.4
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 7.1.3
32
+ version: '9.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '2.2'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5'
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
44
- - - "~>"
47
+ - - ">="
45
48
  - !ruby/object:Gem::Version
46
49
  version: '2.2'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '5'
47
53
  - !ruby/object:Gem::Dependency
48
54
  name: rouge
49
55
  requirement: !ruby/object:Gem::Requirement
50
56
  requirements:
51
57
  - - "~>"
52
58
  - !ruby/object:Gem::Version
53
- version: '3.28'
59
+ version: '5.0'
54
60
  type: :runtime
55
61
  prerelease: false
56
62
  version_requirements: !ruby/object:Gem::Requirement
57
63
  requirements:
58
64
  - - "~>"
59
65
  - !ruby/object:Gem::Version
60
- version: '3.28'
66
+ version: '5.0'
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: rspec-core
63
69
  requirement: !ruby/object:Gem::Requirement
@@ -84,42 +90,54 @@ dependencies:
84
90
  requirements:
85
91
  - - "~>"
86
92
  - !ruby/object:Gem::Version
87
- version: '11.1'
93
+ version: '13.0'
88
94
  type: :development
89
95
  prerelease: false
90
96
  version_requirements: !ruby/object:Gem::Requirement
91
97
  requirements:
92
98
  - - "~>"
93
99
  - !ruby/object:Gem::Version
94
- version: '11.1'
100
+ version: '13.0'
95
101
  - !ruby/object:Gem::Dependency
96
102
  name: capybara
97
103
  requirement: !ruby/object:Gem::Requirement
98
104
  requirements:
99
- - - "~>"
105
+ - - ">="
100
106
  - !ruby/object:Gem::Version
101
107
  version: '3.39'
108
+ - - "<"
109
+ - !ruby/object:Gem::Version
110
+ version: '4'
102
111
  type: :development
103
112
  prerelease: false
104
113
  version_requirements: !ruby/object:Gem::Requirement
105
114
  requirements:
106
- - - "~>"
115
+ - - ">="
107
116
  - !ruby/object:Gem::Version
108
117
  version: '3.39'
118
+ - - "<"
119
+ - !ruby/object:Gem::Version
120
+ version: '4'
109
121
  - !ruby/object:Gem::Dependency
110
122
  name: cucumber
111
123
  requirement: !ruby/object:Gem::Requirement
112
124
  requirements:
113
- - - "~>"
125
+ - - ">="
114
126
  - !ruby/object:Gem::Version
115
127
  version: '7.0'
128
+ - - "<"
129
+ - !ruby/object:Gem::Version
130
+ version: '12'
116
131
  type: :development
117
132
  prerelease: false
118
133
  version_requirements: !ruby/object:Gem::Requirement
119
134
  requirements:
120
- - - "~>"
135
+ - - ">="
121
136
  - !ruby/object:Gem::Version
122
137
  version: '7.0'
138
+ - - "<"
139
+ - !ruby/object:Gem::Version
140
+ version: '12'
123
141
  - !ruby/object:Gem::Dependency
124
142
  name: rake
125
143
  requirement: !ruby/object:Gem::Requirement
@@ -138,30 +156,42 @@ dependencies:
138
156
  name: rdoc
139
157
  requirement: !ruby/object:Gem::Requirement
140
158
  requirements:
141
- - - "~>"
159
+ - - ">="
142
160
  - !ruby/object:Gem::Version
143
161
  version: '6.4'
162
+ - - "<"
163
+ - !ruby/object:Gem::Version
164
+ version: '9'
144
165
  type: :development
145
166
  prerelease: false
146
167
  version_requirements: !ruby/object:Gem::Requirement
147
168
  requirements:
148
- - - "~>"
169
+ - - ">="
149
170
  - !ruby/object:Gem::Version
150
171
  version: '6.4'
172
+ - - "<"
173
+ - !ruby/object:Gem::Version
174
+ version: '9'
151
175
  - !ruby/object:Gem::Dependency
152
176
  name: rspec
153
177
  requirement: !ruby/object:Gem::Requirement
154
178
  requirements:
155
- - - "~>"
179
+ - - ">="
156
180
  - !ruby/object:Gem::Version
157
- version: 3.11.0
181
+ version: '3.11'
182
+ - - "<"
183
+ - !ruby/object:Gem::Version
184
+ version: '4.0'
158
185
  type: :development
159
186
  prerelease: false
160
187
  version_requirements: !ruby/object:Gem::Requirement
161
188
  requirements:
162
- - - "~>"
189
+ - - ">="
163
190
  - !ruby/object:Gem::Version
164
- version: 3.11.0
191
+ version: '3.11'
192
+ - - "<"
193
+ - !ruby/object:Gem::Version
194
+ version: '4.0'
165
195
  - !ruby/object:Gem::Dependency
166
196
  name: turnip
167
197
  requirement: !ruby/object:Gem::Requirement
@@ -203,6 +233,7 @@ files:
203
233
  - lib/rspec_pretty_html_reporter/example.rb
204
234
  - lib/rspec_pretty_html_reporter/helpers.rb
205
235
  - lib/rspec_pretty_html_reporter/oopsy.rb
236
+ - lib/rspec_pretty_html_reporter/parallel.rb
206
237
  - resources/bootstrap-4.0.0-dist/css/bootstrap.min.css
207
238
  - resources/bootstrap-4.0.0-dist/js/bootstrap.js
208
239
  - resources/bootstrap-4.0.0-dist/js/bootstrap.min.js
@@ -229,14 +260,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
229
260
  requirements:
230
261
  - - ">="
231
262
  - !ruby/object:Gem::Version
232
- version: 3.0.6
263
+ version: 3.3.0
233
264
  required_rubygems_version: !ruby/object:Gem::Requirement
234
265
  requirements:
235
266
  - - ">="
236
267
  - !ruby/object:Gem::Version
237
268
  version: '0'
238
269
  requirements: []
239
- rubygems_version: 3.2.33
270
+ rubygems_version: 3.5.3
240
271
  signing_key:
241
272
  specification_version: 4
242
273
  summary: RSpec Pretty HTML Reporter