class RSpec::Core::Formatters::JsonFormatter
@private
Attributes
output_hash[R]
Public Class Methods
new(output)
click to toggle source
Calls superclass method
RSpec::Core::Formatters::BaseFormatter.new
# File lib/rspec/core/formatters/json_formatter.rb, line 13 def initialize(output) super @output_hash = {} end
Public Instance Methods
close(_notification)
click to toggle source
# File lib/rspec/core/formatters/json_formatter.rb, line 47 def close(_notification) output.write @output_hash.to_json output.close if IO === output && output != $stdout end
dump_profile(profile)
click to toggle source
# File lib/rspec/core/formatters/json_formatter.rb, line 52 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/rspec/core/formatters/json_formatter.rb, line 72 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)
click to toggle source
@api private
# File lib/rspec/core/formatters/json_formatter.rb, line 59 def dump_profile_slowest_examples(profile) @output_hash[:profile] = {} sorted_examples = profile.slowest_examples @output_hash[:profile][:examples] = sorted_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)
click to toggle source
# File lib/rspec/core/formatters/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 } @output_hash[:summary_line] = summary.totals_line end
message(notification)
click to toggle source
# File lib/rspec/core/formatters/json_formatter.rb, line 18 def message(notification) (@output_hash[:messages] ||= []) << notification.message end
stop(notification)
click to toggle source
# File lib/rspec/core/formatters/json_formatter.rb, line 32 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.message, :backtrace => e.backtrace, } end end end end
Private Instance Methods
format_example(example)
click to toggle source
# File lib/rspec/core/formatters/json_formatter.rb, line 81 def format_example(example) { :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 } end