class LauncherJsonFormatter

Attributes

output_hash[R]

Public Class Methods

new(output) click to toggle source
Calls superclass method
# File lib/launcher_json_formatter.rb, line 10
def initialize(output)
  super
  @output_hash = {
      :version => RSpec::Core::Version::STRING
  }
  @context = []
  @resource = ''
end

Public Instance Methods

close(_notification) click to toggle source
# File lib/launcher_json_formatter.rb, line 54
def close(_notification)
  output.write @output_hash.to_json
end
dump_profile(profile) click to toggle source
# 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) click to toggle source

@api private

# 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) click to toggle source

@api private

# 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) click to toggle source
# 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) click to toggle source
# File lib/launcher_json_formatter.rb, line 69
def example_group_finished(example_group)

end
example_group_started(example_group) click to toggle source
# 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) click to toggle source
# File lib/launcher_json_formatter.rb, line 19
def message(notification)
  (@output_hash[:messages] ||= []) << notification.message
end
seed(notification) click to toggle source
# File lib/launcher_json_formatter.rb, line 49
def seed(notification)
  return unless notification.seed_used?
  @output_hash[:seed] = notification.seed
end
stop(notification) click to toggle source
# 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.message,
            :backtrace => e.backtrace,
        }
      end
    end
  end
end

Private Instance Methods

format_example(example) click to toggle source
# File lib/launcher_json_formatter.rb, line 95
def format_example(example)
  {
      :id => example.id,
      :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,
      :pending_message => example.execution_result.pending_message,
      :resource => example.example_group.description,
      :context => get_tree(example),
      :metadata => example.metadata,
      :tags => example.metadata[:tags],
      :report_tags => example.metadata[:report_tags],
      :type => example.metadata[:type]
  }
end
get_tree(example) click to toggle source
# File lib/launcher_json_formatter.rb, line 114
def get_tree(example)
  example.example_group.ancestors.select do |o|
    /RSpec::ExampleGroups/.match?(o.to_s) && o.respond_to?(:description)
  end.map do |object|
    object.description
  end.reverse
end