require 'rspec/core/formatters/base_text_formatter'

module RSpec
  module Core
    module Formatters
      class AugmentedTextFormatter < BaseTextFormatter
        def initialize(output)
          super(output)
        end

        def self.configure buffet_server, slave_name
          @@buffet_server = buffet_server
          @@slave_name = slave_name
        end

        def example_passed example
          super
          @@buffet_server.example_passed(@@slave_name, {
            :description => example.description,
            :location    => example.location,
            :slave_name  => @@slave_name,
          })
        end

        def example_failed example
          super
          exception = example.metadata[:execution_result][:exception]
          backtrace = format_backtrace(exception.backtrace, example).join("\n")

          @@buffet_server.example_failed(@@slave_name, {
            :description => example.description,
            :backtrace   => backtrace,
            :message     => exception.message,
            :location    => example.location,
            :slave_name  => @@slave_name,
          })
        end

        def example_pending example
          super
          @@buffet_server.example_pending(@@slave_name, {
            :description => example.description,
            :location    => example.location,
            :slave_name  => @@slave_name,
          })
        end
      end
    end
  end
end

require 'rspec/core/formatters/base_text_formatter'

module RSpec
  module Core
    module Formatters
      class AugmentedTextFormatter < BaseTextFormatter
        def initialize(output)
          super(output)
        end

        def self.configure buffet_server, slave_name
          @@buffet_server = buffet_server
          @@slave_name = slave_name
        end

        def example_passed example
          super
          @@buffet_server.example_passed(@@slave_name, {
            :description => example.description,
            :location    => example.location,
            :slave_name  => @@slave_name,
          })
        end

        def example_failed example
          super
          exception = example.metadata[:execution_result][:exception]
          backtrace = format_backtrace(exception.backtrace, example).join("\n")

          message = exception.message
          if shared_group = find_shared_group(example)
            message += "\nShared example group called from " +
              backtrace_line(shared_group.metadata[:example_group][:location])
          end

          @@buffet_server.example_failed(@@slave_name, {
            :description => example.description,
            :backtrace   => backtrace,
            :message     => message,
            :location    => example.location,
            :slave_name  => @@slave_name,
          })
        end

        def example_pending example
          super
          @@buffet_server.example_pending(@@slave_name, {
            :description => example.description,
            :location    => example.location,
            :slave_name  => @@slave_name,
          })
        end
      end
    end
  end
end

Return information about example groups on failure
Return information about example groups on failure

Example#execution_result[:exception] only has information about the
example that failed, which does not include the example group for
shared examples. This appends the calling location to the failure
message for shared examples.

Reference code: https://github.com/rspec/rspec-core/blob/v2.8.0/
                  lib/rspec/core/formatters/base_text_formatter.rb#L178

Change-Id: I8d3ae6583c1b66ffa3a5e1021e47ce371d69d431
Reviewed-on: https://gerrit.causes.com/9699
Reviewed-by: Elliot Block <de602badf61da69092c03807d41b60ec8901ad87@causes.com>
Tested-by: Lann Martin <564fa7a717c51b612962ea128f146981a0e99d90@causes.com>
