Class: RSpec::Core::Formatters::JsonFormatter

### Home Classes Methods

### In Files

- lib/rspec/core/formatters/json_formatter.rb

### Parent

RSpec::Core::Formatters::BaseFormatter

### Methods

- ::new
- #close
- #dump_summary
- #message
- #stop
- #summary_line

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Core
- RSpec::Core::BacktraceCleaner
- RSpec::Core::BacktraceFormatter
- RSpec::Core::CommandLine
- RSpec::Core::Configuration
- RSpec::Core::Configuration::MustBeConfiguredBeforeExampleGroupsError
- RSpec::Core::ConfigurationOptions
- RSpec::Core::ConstMissing
- RSpec::Core::DRbCommandLine
- RSpec::Core::DSL
- RSpec::Core::Deprecation
- RSpec::Core::DrbOptions
- RSpec::Core::Example
- RSpec::Core::Example::NotPendingExampleFixed
- RSpec::Core::Example::Procsy
- RSpec::Core::ExampleGroup
- RSpec::Core::Extensions
- RSpec::Core::Extensions::InstanceEvalWithArgs
- RSpec::Core::Extensions::ModuleEvalWithArgs
- RSpec::Core::Extensions::Ordered
- RSpec::Core::Extensions::Ordered::ExampleGroups
- RSpec::Core::Extensions::Ordered::Examples
- RSpec::Core::FilterManager
- RSpec::Core::FilterManager::BackwardCompatibility
- RSpec::Core::FilterManager::Describable
- RSpec::Core::Formatters
- RSpec::Core::Formatters::BaseFormatter
- RSpec::Core::Formatters::BaseTextFormatter
- RSpec::Core::Formatters::DeprecationFormatter
- RSpec::Core::Formatters::DocumentationFormatter
- RSpec::Core::Formatters::Helpers
- RSpec::Core::Formatters::HtmlFormatter
- RSpec::Core::Formatters::HtmlPrinter
- RSpec::Core::Formatters::JsonFormatter
- RSpec::Core::Formatters::ProgressFormatter
- RSpec::Core::Formatters::SnippetExtractor
- RSpec::Core::Formatters::SnippetExtractor::NullConverter
- RSpec::Core::Formatters::TextMateFormatter
- RSpec::Core::Hooks
- RSpec::Core::Hooks::AfterAllHook
- RSpec::Core::Hooks::AfterHook
- RSpec::Core::Hooks::AroundHook
- RSpec::Core::Hooks::AroundHookCollection
- RSpec::Core::Hooks::BeforeHook
- RSpec::Core::Hooks::GroupHookCollection
- RSpec::Core::Hooks::Hook
- RSpec::Core::Hooks::HookCollection
- RSpec::Core::Hooks::HookCollectionAliases
- RSpec::Core::Hooks::RegistersGlobals
- RSpec::Core::MemoizedHelpers
- RSpec::Core::MemoizedHelpers::BeforeAllMemoizedHash
- RSpec::Core::MemoizedHelpers::ClassMethods
- RSpec::Core::Metadata
- RSpec::Core::Metadata::ExampleMetadataHash
- RSpec::Core::Metadata::GroupMetadataHash
- RSpec::Core::Metadata::MetadataHash
- RSpec::Core::MetadataHashBuilder
- RSpec::Core::MetadataHashBuilder::Common
- RSpec::Core::MetadataHashBuilder::WithConfigWarning
- RSpec::Core::MetadataHashBuilder::WithDeprecationWarning
- RSpec::Core::MockFrameworkAdapter
- RSpec::Core::Parser
- RSpec::Core::Pending
- RSpec::Core::Pending::PendingDeclaredInExample
- RSpec::Core::Pending::PendingExampleFixedError
- RSpec::Core::ProjectInitializer
- RSpec::Core::RakeTask
- RSpec::Core::Reporter
- RSpec::Core::RubyProject
- RSpec::Core::Runner
- RSpec::Core::SharedContext
- RSpec::Core::SharedExampleGroup
- RSpec::Core::SharedExampleGroup::Collection
- RSpec::Core::SharedExampleGroup::Registry
- RSpec::Core::SharedExampleGroup::TopLevelDSL
- RSpec::Core::Time
- RSpec::Core::Version
- RSpec::Core::World
- RSpec::Rake
- RSpec::Runner
- Autotest
- Autotest::Rspec2
- Kernel

No matching classes.

# RSpec::Core::Formatters::JsonFormatter

### Attributes

output_hash[R]

### Public Class Methods

new(output) click to toggle source

    # File lib/rspec/core/formatters/json_formatter.rb, line 12
    def initialize(output)
      super
      @output_hash = {}
    end

### Public Instance Methods

close() click to toggle source

    # File lib/rspec/core/formatters/json_formatter.rb, line 62
    def close
      output.write @output_hash.to_json
      output.close if IO === output && output != $stdout
    end

dump_summary(duration, example_count, failure_count, pending_count) click to toggle source

    # File lib/rspec/core/formatters/json_formatter.rb, line 21
    def dump_summary(duration, example_count, failure_count, pending_count)
      super(duration, example_count, failure_count, pending_count)
      @output_hash[:summary] = {
        :duration => duration,
        :example_count => example_count,
        :failure_count => failure_count,
        :pending_count => pending_count
      }
      @output_hash[:summary_line] = summary_line(example_count, failure_count, pending_count)
    end

message(message) click to toggle source

    # File lib/rspec/core/formatters/json_formatter.rb, line 17
    def message(message)
      (@output_hash[:messages] ||= []) << message
    end

stop() click to toggle source

    # File lib/rspec/core/formatters/json_formatter.rb, line 39
    def stop
      super
      @output_hash[:examples] = examples.map do |example|
        {
          :description => example.description,
          :full_description => example.full_description,
          :status => example.execution_result[:status],
          # :example_group,
          # :execution_result,
          :file_path => example.metadata[:file_path],
          :line_number  => example.metadata[:line_number],
        }.tap do |hash|
          if e=example.exception
            hash[:exception] =  {
              :class => e.class.name,
              :message => e.message,
              :backtrace => e.backtrace,
            }
          end
        end
      end
    end

summary_line(example_count, failure_count, pending_count) click to toggle source

    # File lib/rspec/core/formatters/json_formatter.rb, line 32
    def summary_line(example_count, failure_count, pending_count)
      summary = pluralize(example_count, "example")
      summary << ", " << pluralize(failure_count, "failure")
      summary << ", #{pending_count} pending" if pending_count > 0
      summary
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.