Class: LauncherJsonFormatter
- Inherits:
-
RSpec::Core::Formatters::BaseFormatter
- Object
- RSpec::Core::Formatters::BaseFormatter
- LauncherJsonFormatter
- Defined in:
- lib/launcher_json_formatter.rb
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
- #example_group_finished(example_group) ⇒ Object
- #example_group_started(example_group) ⇒ Object
-
#initialize(output) ⇒ LauncherJsonFormatter
constructor
A new instance of LauncherJsonFormatter.
- #message(notification) ⇒ Object
- #seed(notification) ⇒ Object
- #stop(notification) ⇒ Object
Constructor Details
#initialize(output) ⇒ LauncherJsonFormatter
Returns a new instance of LauncherJsonFormatter.
9 10 11 12 13 14 15 16 |
# File 'lib/launcher_json_formatter.rb', line 9 def initialize(output) super @output_hash = { :version => RSpec::Core::Version::STRING } @context = [] @resource = '' end |
Instance Attribute Details
#output_hash ⇒ Object (readonly)
Returns the value of attribute output_hash.
7 8 9 |
# File 'lib/launcher_json_formatter.rb', line 7 def output_hash @output_hash end |
Instance Method Details
#close(_notification) ⇒ Object
53 54 55 |
# File 'lib/launcher_json_formatter.rb', line 53 def close(_notification) output.write @output_hash.to_json end |
#dump_profile(profile) ⇒ Object
57 58 59 60 61 |
# File 'lib/launcher_json_formatter.rb', line 57 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.
85 86 87 88 89 90 |
# File 'lib/launcher_json_formatter.rb', line 85 def dump_profile_slowest_example_groups(profile) @output_hash[:profile] ||= {} @output_hash[:profile][:groups] = profile.slowest_groups.map do |loc, hash| hash.update(:location => loc) end 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.
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/launcher_json_formatter.rb', line 73 def dump_profile_slowest_examples(profile) @output_hash[:profile] = {} @output_hash[:profile][:examples] = profile.slowest_examples.map do |example| format_example(example).tap do |hash| hash[:run_time] = example.execution_result.run_time end end @output_hash[:profile][:slowest] = profile.slow_duration @output_hash[:profile][:total] = profile.duration end |
#dump_summary(summary) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/launcher_json_formatter.rb', line 22 def dump_summary(summary) @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 => summary.errors_outside_of_examples_count } @output_hash[:summary_line] = summary.totals_line end |
#example_group_finished(example_group) ⇒ Object
68 69 70 |
# File 'lib/launcher_json_formatter.rb', line 68 def example_group_finished(example_group) @group.pop end |
#example_group_started(example_group) ⇒ Object
63 64 65 66 |
# File 'lib/launcher_json_formatter.rb', line 63 def example_group_started(example_group) @context.push "#{example_group.group.description}" @resource = "#{example_group.group.description}" end |
#message(notification) ⇒ Object
18 19 20 |
# File 'lib/launcher_json_formatter.rb', line 18 def (notification) (@output_hash[:messages] ||= []) << notification. end |
#seed(notification) ⇒ Object
48 49 50 51 |
# File 'lib/launcher_json_formatter.rb', line 48 def seed(notification) return unless notification.seed_used? @output_hash[:seed] = notification.seed end |
#stop(notification) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/launcher_json_formatter.rb', line 33 def stop(notification) @output_hash[:examples] = notification.examples.map do |example| format_example(example).tap do |hash| e = example.exception if e hash[:exception] = { :class => e.class.name, :message => e., :backtrace => e.backtrace, } end end end end |