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.
10 11 12 13 14 15 16 17 |
# File 'lib/launcher_json_formatter.rb', line 10 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.
8 9 10 |
# File 'lib/launcher_json_formatter.rb', line 8 def output_hash @output_hash end |
Instance Method Details
#close(_notification) ⇒ Object
54 55 56 |
# File 'lib/launcher_json_formatter.rb', line 54 def close(_notification) output.write @output_hash.to_json end |
#dump_profile(profile) ⇒ Object
58 59 60 61 62 |
# File 'lib/launcher_json_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.
86 87 88 89 90 91 |
# File 'lib/launcher_json_formatter.rb', line 86 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.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/launcher_json_formatter.rb', line 74 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
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/launcher_json_formatter.rb', line 23 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
69 70 71 |
# File 'lib/launcher_json_formatter.rb', line 69 def example_group_finished(example_group) end |
#example_group_started(example_group) ⇒ Object
64 65 66 67 |
# File 'lib/launcher_json_formatter.rb', line 64 def example_group_started(example_group) @context.push "#{example_group.group.description}" @resource = "#{example_group.group.description}" end |
#message(notification) ⇒ Object
19 20 21 |
# File 'lib/launcher_json_formatter.rb', line 19 def (notification) (@output_hash[:messages] ||= []) << notification. end |
#seed(notification) ⇒ Object
49 50 51 52 |
# File 'lib/launcher_json_formatter.rb', line 49 def seed(notification) return unless notification.seed_used? @output_hash[:seed] = notification.seed end |
#stop(notification) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/launcher_json_formatter.rb', line 34 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 |