class ReportFactory::Rspec::Formatter
An RSpec formatter that formats json from the test run
Constants
- SUMMARY
Attributes
output_hash[R]
Public Class Methods
new(output)
click to toggle source
Calls superclass method
# File lib/report_factory/rspec/formatter.rb, line 18 def initialize(output) super @output_hash = { version: RSpec::Core::Version::STRING } end
Public Instance Methods
close(_notification)
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 55 def close(_notification) return if @output_hash[:examples].empty? || !summary_is_valid? print_result(ReportFactory::Rspec::API.send_report(@output_hash)) end
dump_profile(profile)
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 61 def dump_profile(profile) @output_hash[:profile] = {} dump_profile_slowest_examples(profile) dump_profile_slowest_example_groups(profile) end
dump_profile_slowest_example_groups(profile)
click to toggle source
@api private
# File lib/report_factory/rspec/formatter.rb, line 76 def dump_profile_slowest_example_groups(profile) @output_hash[:profile] ||= {} @output_hash[:profile][:groups] = format_profile_groups(profile) end
dump_profile_slowest_examples(profile)
click to toggle source
@api private
# File lib/report_factory/rspec/formatter.rb, line 68 def dump_profile_slowest_examples(profile) @output_hash[:profile] = {} @output_hash[:profile][:examples] = format_profile_examples(profile) @output_hash[:profile][:slowest] = profile.slow_duration @output_hash[:profile][:total] = profile.duration end
dump_summary(summary)
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 29 def dump_summary(summary) errors_outside_count = summary.errors_outside_of_examples_count @output_hash[:summary] = { duration: summary.duration, example_count: summary.example_count, failure_count: summary.failure_count, pending_count: summary.pending_count, errors_outside_of_examples_count: errors_outside_count } @output_hash[:summary_line] = summary.totals_line end
message(notification)
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 25 def message(notification) (@output_hash[:messages] ||= []) << notification.message end
seed(notification)
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 49 def seed(notification) return unless notification.seed_used? @output_hash[:seed] = notification.seed end
stop(notification)
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 41 def stop(notification) @output_hash[:examples] = notification.examples.map do |example| format_example(example).tap do |hash| hash[:exception] = format_exception(example) end end end
Private Instance Methods
format_example(example)
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 102 def format_example(example) { id: example.id, description: example.description, full_description: example.full_description, status: example.execution_result.status.to_s, file_path: example.metadata[:file_path], line_number: example.metadata[:line_number], run_time: example.execution_result.run_time, pending_message: example.execution_result.pending_message } end
format_exception(example)
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 115 def format_exception(example) exception = example.exception return unless exception { class: exception.class.name, message: exception.message, backtrace: exception.backtrace } end
format_profile_examples(profile)
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 126 def format_profile_examples(profile) profile.slowest_examples.map do |example| format_example(example).tap do |hash| hash[:run_time] = example.execution_result.run_time end end end
format_profile_groups(profile)
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 134 def format_profile_groups(profile) profile.slowest_groups.map { |loc, hash| hash.update(location: loc) } end
print_error(response)
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 93 def print_error(response) output.write 'Unfortunately the test report could not be submitted'\ " to ReportFactory. #{response.code}: #{response.msg}\n" end
print_result(response)
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 83 def print_result(response) return print_success if response.code == '201' print_error(response) end
print_success()
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 89 def print_success output.write "Report has been successfully submitted to ReportFactory\n" end
summary_is_valid?()
click to toggle source
# File lib/report_factory/rspec/formatter.rb, line 98 def summary_is_valid? SUMMARY.all? { |param| @output_hash.dig(:summary, param) } end