Class: RspecHtmlReporter
- Inherits:
-
RSpec::Core::Formatters::BaseFormatter
- Object
- RSpec::Core::Formatters::BaseFormatter
- RspecHtmlReporter
- Defined in:
- lib/rspec_html_reporter.rb
Constant Summary collapse
- DEFAULT_REPORT_PATH =
File.join(Bundler.root, 'reports', Time.now.strftime('%Y%m%d-%H%M%S'))
- REPORT_PATH =
ENV['REPORT_PATH'] || DEFAULT_REPORT_PATH
- SCREENRECORD_DIR =
File.join(REPORT_PATH, 'screenrecords')
- SCREENSHOT_DIR =
File.join(REPORT_PATH, 'screenshots')
- RESOURCE_DIR =
File.join(REPORT_PATH, 'resources')
Instance Method Summary collapse
- #close(notification) ⇒ Object
- #example_failed(notification) ⇒ Object
- #example_group_finished(notification) ⇒ Object
- #example_group_started(notification) ⇒ Object
- #example_passed(notification) ⇒ Object
- #example_pending(notification) ⇒ Object
- #example_started(notification) ⇒ Object
-
#initialize(io_standard_out) ⇒ RspecHtmlReporter
constructor
A new instance of RspecHtmlReporter.
Constructor Details
#initialize(io_standard_out) ⇒ RspecHtmlReporter
Returns a new instance of RspecHtmlReporter.
174 175 176 177 178 179 180 181 182 |
# File 'lib/rspec_html_reporter.rb', line 174 def initialize(io_standard_out) create_reports_dir create_screenshots_dir create_screenrecords_dir copy_resources @all_groups = {} @group_level = 0 end |
Instance Method Details
#close(notification) ⇒ Object
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/rspec_html_reporter.rb', line 261 def close(notification) File.open("#{REPORT_PATH}/overview.html", 'w') do |f| @overview = @all_groups @passed = @overview.values.map { |g| g[:passed].size }.inject(0) { |sum, i| sum + i } @failed = @overview.values.map { |g| g[:failed].size }.inject(0) { |sum, i| sum + i } @pending = @overview.values.map { |g| g[:pending].size }.inject(0) { |sum, i| sum + i } duration_values = @overview.values.map { |e| e[:duration] } duration_keys = duration_values.size.times.to_a if duration_values.size < 2 duration_values.unshift(duration_values.first) duration_keys = duration_keys << 1 end @durations = duration_keys.zip(duration_values.map{|d| d.to_f.round(5)}) @summary_duration = duration_values.map{|d| d.to_f.round(5)}.inject(0) { |sum, i| sum + i }.to_s(:rounded, precision: 5) @total_examples = @passed + @failed + @pending template_file = File.read(File.dirname(__FILE__) + '/../templates/overview.erb') f.puts ERB.new(template_file).result(binding) end end |
#example_failed(notification) ⇒ Object
206 207 208 209 |
# File 'lib/rspec_html_reporter.rb', line 206 def example_failed(notification) @group_example_failure_count += 1 @examples << Example.new(notification.example) end |
#example_group_finished(notification) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/rspec_html_reporter.rb', line 216 def example_group_finished(notification) @group_level -= 1 if @group_level == 0 File.open("#{REPORT_PATH}/#{notification.group.description.parameterize}.html", 'w') do |f| @passed = @group_example_success_count @failed = @group_example_failure_count @pending = @group_example_pending_count duration_values = @examples.map { |e| e.run_time } duration_keys = duration_values.size.times.to_a if duration_values.size < 2 and duration_values.size > 0 duration_values.unshift(duration_values.first) duration_keys = duration_keys << 1 end @title = notification.group.description @durations = duration_keys.zip(duration_values) @summary_duration = duration_values.inject(0) { |sum, i| sum + i }.to_s(:rounded, precision: 5) Example.load_spec_comments!(@examples) class_map = {passed: 'success', failed: 'danger', pending: 'warning'} statuses = @examples.map { |e| e.status } status = statuses.include?('failed') ? 'failed' : (statuses.include?('passed') ? 'passed' : 'pending') @all_groups[notification.group.description.parameterize] = { group: notification.group.description, examples: @examples.size, status: status, klass: class_map[status.to_sym], passed: statuses.select { |s| s == 'passed' }, failed: statuses.select { |s| s == 'failed' }, pending: statuses.select { |s| s == 'pending' }, duration: @summary_duration } template_file = File.read(File.dirname(__FILE__) + '/../templates/report.erb') f.puts ERB.new(template_file).result(binding) end end end |
#example_group_started(notification) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/rspec_html_reporter.rb', line 184 def example_group_started(notification) if @group_level == 0 @example_group = {} @examples = [] @group_example_count = 0 @group_example_success_count = 0 @group_example_failure_count = 0 @group_example_pending_count = 0 end @group_level += 1 end |
#example_passed(notification) ⇒ Object
201 202 203 204 |
# File 'lib/rspec_html_reporter.rb', line 201 def example_passed(notification) @group_example_success_count += 1 @examples << Example.new(notification.example) end |
#example_pending(notification) ⇒ Object
211 212 213 214 |
# File 'lib/rspec_html_reporter.rb', line 211 def example_pending(notification) @group_example_pending_count += 1 @examples << Example.new(notification.example) end |
#example_started(notification) ⇒ Object
197 198 199 |
# File 'lib/rspec_html_reporter.rb', line 197 def example_started(notification) @group_example_count += 1 end |