rspec_html_reporter 1.0.1 → 1.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: 7240b9e71f70c91f66716bee22754445f16fbae8
4
- data.tar.gz: e37cbf82007f1b41a48b8a7bdb6f67f038dbb519
3
+ metadata.gz: 8ae94974550f41e82238d6bfba8d63f7a3ebef71
4
+ data.tar.gz: 0fa08481d76ff8a9d49d7d8165ae45261373a417
5
5
  SHA512:
6
- metadata.gz: aa51f6fc85ccfbe9b44c1c4cdf93ad03229432006c8f332203a32630e9d2f83e8dcfc262d6ac92d492306cb79645e6380740a64476cb02dfa519c9c56d3dddb6
7
- data.tar.gz: 81c6a409b05e79e70429182d96d6f4b4cf1d6b148fe63a72a9ae28c739a9119b12e33e58563fd8646ec5f5790bfdd0f328b8eee052e083afe028f7dd9b8d7fd1
6
+ metadata.gz: c1292b7db6d8e7663437b8959cef71e28e4f1c5bd69f8202732a0705859856f878ac842b1e29e55ab164ffbb719fe674ed6977a4af2188552d858ae253863066
7
+ data.tar.gz: 18d735071425e2d5d7b0eee7496b26b0463aac0aa0f877782b32d0ee76f9e4b86dc34dca9299a5300646b7fbf9814945a5f16c2165fff858894cefdfd296e74d
@@ -12,14 +12,15 @@ I18n.enforce_available_locales = false
12
12
  class Oopsy
13
13
  attr_reader :klass, :message, :backtrace, :highlighted_source, :explanation, :backtrace_message
14
14
 
15
- def initialize(exception, file_path)
16
- @exception = exception
15
+ def initialize(example, file_path)
16
+ @example = example
17
+ @exception = @example.exception
17
18
  @file_path = file_path
18
19
  unless @exception.nil?
19
20
  @klass = @exception.class
20
21
  @message = @exception.message.encode('utf-8')
21
22
  @backtrace = @exception.backtrace
22
- @backtrace_message = @backtrace.nil? ? '' : @backtrace.select { |r| r.match(@file_path) }.join('').encode('utf-8')
23
+ @backtrace_message = formatted_backtrace(@example, @exception)
23
24
  @highlighted_source = process_source
24
25
  @explanation = process_message
25
26
  end
@@ -45,8 +46,13 @@ class Oopsy
45
46
  )
46
47
  end
47
48
 
49
+ def formatted_backtrace(example, exception)
50
+ formatter = RSpec.configuration.backtrace_formatter
51
+ formatter.format_backtrace(exception.backtrace, example.metadata)
52
+ end
53
+
48
54
  def process_source
49
- data = @backtrace_message.split(':')
55
+ data = @backtrace_message.first.split(':')
50
56
  unless data.empty?
51
57
  if os == :windows
52
58
  file_path = data[0] + ':' + data[1]
@@ -76,6 +82,22 @@ end
76
82
 
77
83
  class Example
78
84
 
85
+ def self.load_spec_comments!(examples)
86
+ examples.group_by(&:file_path).each do |file_path, file_examples|
87
+ lines = File.readlines(file_path)
88
+
89
+ file_examples.zip(file_examples.rotate).each do |ex, next_ex|
90
+ lexically_next = next_ex &&
91
+ next_ex.file_path == ex.file_path &&
92
+ next_ex.metadata[:line_number] > ex.metadata[:line_number]
93
+ start_line_idx = ex.metadata[:line_number] - 1
94
+ next_start_idx = (lexically_next ? next_ex.metadata[:line_number] : lines.size) - 1
95
+ spec_lines = lines[start_line_idx...next_start_idx].select { |l| l.match(/#->/) }
96
+ ex.set_spec(spec_lines.join) unless spec_lines.empty?
97
+ end
98
+ end
99
+ end
100
+
79
101
  attr_reader :example_group, :description, :full_description, :run_time, :duration, :status, :exception, :file_path, :metadata, :spec, :screenshots, :screenrecord, :failed_screenshot
80
102
 
81
103
  def initialize(example)
@@ -88,7 +110,7 @@ class Example
88
110
  @status = @execution_result.status.to_s
89
111
  @metadata = example.metadata
90
112
  @file_path = @metadata[:file_path]
91
- @exception = Oopsy.new(example.exception, @file_path)
113
+ @exception = Oopsy.new(example, @file_path)
92
114
  @spec = nil
93
115
  @screenshots = @metadata[:screenshots]
94
116
  @screenrecord = @metadata[:screenrecord]
@@ -122,8 +144,10 @@ class Example
122
144
  !@failed_screenshot.nil?
123
145
  end
124
146
 
125
- def set_spec(spec)
126
- @spec = spec
147
+ def set_spec(spec_text)
148
+ formatter = Rouge::Formatters::HTML.new(css_class: 'highlight')
149
+ lexer = Rouge::Lexers::Gherkin.new
150
+ @spec = formatter.format(lexer.lex(spec_text.gsub('#->', '')))
127
151
  end
128
152
 
129
153
  def klass(prefix='label-')
@@ -133,30 +157,6 @@ class Example
133
157
 
134
158
  end
135
159
 
136
- class Specify
137
-
138
- def initialize(examples)
139
- @examples = examples
140
- end
141
-
142
- def process
143
- @examples.each_with_index do |e, i|
144
- lines = File.readlines(e.file_path)
145
- start_line = e.metadata[:line_number]
146
- end_line = @examples[i+1].nil? ? lines.size : @examples[i+1].metadata[:line_number] - 1
147
- code_block = lines[start_line..end_line]
148
- spec = code_block.select { |l| l.match(/#->/) }.join('')
149
- if !spec.split.empty?
150
- formatter = Rouge::Formatters::HTML.new(css_class: 'highlight')
151
- lexer = Rouge::Lexers::Gherkin.new
152
- formatted_spec = formatter.format(lexer.lex(spec.gsub('#->', '')))
153
- e.set_spec(formatted_spec)
154
- end
155
- end
156
- @examples
157
- end
158
- end
159
-
160
160
  class RspecHtmlReporter < RSpec::Core::Formatters::BaseFormatter
161
161
 
162
162
  DEFAULT_REPORT_PATH = File.join(Bundler.root, 'reports', Time.now.strftime('%Y%m%d-%H%M%S'))
@@ -181,7 +181,7 @@ class RspecHtmlReporter < RSpec::Core::Formatters::BaseFormatter
181
181
  def example_group_started(notification)
182
182
  if @group_level == 0
183
183
  @example_group = {}
184
- @group_examples = []
184
+ @examples = []
185
185
  @group_example_count = 0
186
186
  @group_example_success_count = 0
187
187
  @group_example_failure_count = 0
@@ -197,17 +197,17 @@ class RspecHtmlReporter < RSpec::Core::Formatters::BaseFormatter
197
197
 
198
198
  def example_passed(notification)
199
199
  @group_example_success_count += 1
200
- @group_examples << Example.new(notification.example)
200
+ @examples << Example.new(notification.example)
201
201
  end
202
202
 
203
203
  def example_failed(notification)
204
204
  @group_example_failure_count += 1
205
- @group_examples << Example.new(notification.example)
205
+ @examples << Example.new(notification.example)
206
206
  end
207
207
 
208
208
  def example_pending(notification)
209
209
  @group_example_pending_count += 1
210
- @group_examples << Example.new(notification.example)
210
+ @examples << Example.new(notification.example)
211
211
  end
212
212
 
213
213
  def example_group_finished(notification)
@@ -220,7 +220,7 @@ class RspecHtmlReporter < RSpec::Core::Formatters::BaseFormatter
220
220
  @failed = @group_example_failure_count
221
221
  @pending = @group_example_pending_count
222
222
 
223
- duration_values = @group_examples.map { |e| e.run_time }
223
+ duration_values = @examples.map { |e| e.run_time }
224
224
 
225
225
  duration_keys = duration_values.size.times.to_a
226
226
  if duration_values.size < 2 and duration_values.size > 0
@@ -232,7 +232,7 @@ class RspecHtmlReporter < RSpec::Core::Formatters::BaseFormatter
232
232
  @durations = duration_keys.zip(duration_values)
233
233
 
234
234
  @summary_duration = duration_values.inject(0) { |sum, i| sum + i }.to_s(:rounded, precision: 5)
235
- @examples = Specify.new(@group_examples).process
235
+ Example.load_spec_comments!(@examples)
236
236
 
237
237
  class_map = {passed: 'success', failed: 'danger', pending: 'warning'}
238
238
  statuses = @examples.map { |e| e.status }
data/templates/report.erb CHANGED
@@ -73,10 +73,7 @@
73
73
  </div>
74
74
  </div>
75
75
 
76
- <div class="row">
77
-
78
76
  <div class="col-lg-12">
79
-
80
77
  <table class="table table-striped table-hover ">
81
78
  <thead>
82
79
  <tr>
@@ -155,7 +152,16 @@
155
152
  </div>
156
153
  <div class="panel-body">
157
154
  <%= example.exception.explanation %>
158
- <h5><%= example.exception.backtrace_message %></h5>
155
+ <dl>
156
+ <dt>Backtrace:</dt>
157
+ <dd>
158
+ <ol>
159
+ <% example.exception.backtrace_message.each do |message| %>
160
+ <li><%= message %></li>
161
+ <% end %>
162
+ </ol>
163
+ </dd>
164
+ </dl>
159
165
  <%= example.exception.highlighted_source %>
160
166
  </div>
161
167
 
@@ -181,10 +187,8 @@
181
187
  <% end %>
182
188
  </tbody>
183
189
  </table>
184
-
185
190
  </div>
186
191
  </div>
187
-
188
192
  </div>
189
193
 
190
194
  <script type="text/javascript">
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_html_reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vishal Banthia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-31 00:00:00.000000000 Z
11
+ date: 2018-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec