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
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.
17 18 19 20 21 22 |
# File 'lib/report_factory/rspec/formatter.rb', line 17 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.
15 16 17 |
# File 'lib/report_factory/rspec/formatter.rb', line 15 def output_hash @output_hash end |
Instance Method Details
#close(_notification) ⇒ Object
53 54 55 56 |
# File 'lib/report_factory/rspec/formatter.rb', line 53 def close(_notification) return if @output_hash[:examples].empty? print_result(ReportFactory::Rspec::API.send_report(@output_hash)) end |
#dump_profile(profile) ⇒ Object
58 59 60 61 62 |
# File 'lib/report_factory/rspec/formatter.rb', line 58 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.
73 74 75 76 |
# File 'lib/report_factory/rspec/formatter.rb', line 73 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.
65 66 67 68 69 70 |
# File 'lib/report_factory/rspec/formatter.rb', line 65 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
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/report_factory/rspec/formatter.rb', line 28 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
24 25 26 |
# File 'lib/report_factory/rspec/formatter.rb', line 24 def (notification) (@output_hash[:messages] ||= []) << notification. end |
#seed(notification) ⇒ Object
48 49 50 51 |
# File 'lib/report_factory/rspec/formatter.rb', line 48 def seed(notification) return unless notification.seed_used? @output_hash[:seed] = notification.seed end |
#stop(notification) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/report_factory/rspec/formatter.rb', line 40 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 |