Class: ReportFactory::Rspec::Formatter
- Inherits:
-
RSpec::Core::Formatters::BaseFormatter
- Object
- RSpec::Core::Formatters::BaseFormatter
- ReportFactory::Rspec::Formatter
- Defined in:
- lib/report_factory/rspec/formatter.rb
Overview
An RSpec formatter that formats json from the test run
Constant Summary collapse
- SUMMARY =
%i[duration example_count failure_count pending_count].freeze
Instance Attribute Summary collapse
-
#output_hash ⇒ Object
readonly
Returns the value of attribute output_hash.
Instance Method Summary collapse
- #close(_notification) ⇒ Object
- #dump_profile(profile) ⇒ Object
- #dump_profile_slowest_example_groups(profile) ⇒ Object private
- #dump_profile_slowest_examples(profile) ⇒ Object private
- #dump_summary(summary) ⇒ Object
-
#initialize(output) ⇒ Formatter
constructor
A new instance of Formatter.
- #message(notification) ⇒ Object
- #seed(notification) ⇒ Object
- #stop(notification) ⇒ Object
Constructor Details
#initialize(output) ⇒ Formatter
Returns a new instance of Formatter.
18 19 20 21 22 23 |
# File 'lib/report_factory/rspec/formatter.rb', line 18 def initialize(output) super @output_hash = { version: RSpec::Core::Version::STRING } end |
Instance Attribute Details
#output_hash ⇒ Object (readonly)
Returns the value of attribute output_hash.
16 17 18 |
# File 'lib/report_factory/rspec/formatter.rb', line 16 def output_hash @output_hash end |
Instance Method Details
#close(_notification) ⇒ Object
55 56 57 58 59 |
# 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) ⇒ Object
61 62 63 64 65 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 79 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 73 |
# 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) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# 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) ⇒ Object
25 26 27 |
# File 'lib/report_factory/rspec/formatter.rb', line 25 def (notification) (@output_hash[:messages] ||= []) << notification. end |
#seed(notification) ⇒ Object
49 50 51 52 53 |
# 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) ⇒ Object
41 42 43 44 45 46 47 |
# 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 |