Sha256: a943048d00ca4fa00b8dc44de4161a59b2a9ccc3eeed9d5f714d77d7f8ced852

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

require "json"
require "petitest/subscribers/base_subscriber"
require "petitest/subscriber_concerns/output_concern"
require "petitest/subscriber_concerns/time_concern"

module Petitest
  module Subscribers
    class JsonReportSubscriber < ::Petitest::Subscribers::BaseSubscriber
      include ::Petitest::SubscriberConcerns::OutputConcern
      include ::Petitest::SubscriberConcerns::TimeConcern

      # @note Override
      def after_running_test_cases(test_cases)
        super
        data = {
          test_cases: test_cases.map do |test_case|
            {
              backtrace: test_case.backtrace,
              class_name: test_case.test_group_class.to_s,
              error_class_name: test_case.error_class_name,
              error_message: test_case.error_message,
              failed: test_case.failed?,
              finished_at: test_case.finished_at.iso8601(6),
              method_line_number: test_case.test_method.line_number,
              method_name: test_case.test_method.method_name,
              path: test_case.test_method.path,
              skipped: test_case.skipped?,
              started_at: test_case.started_at.iso8601(6),
            }
          end,
          times: {
            finished_at: finished_at.iso8601(6),
            started_at: started_at.iso8601(6),
          },
        }
        string = ::JSON.pretty_generate(data)
        output.puts(string)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
petitest-0.2.1 lib/petitest/subscribers/json_report_subscriber.rb
petitest-0.2.0 lib/petitest/subscribers/json_report_subscriber.rb