Sha256: 18ec07b7016220546ead3ad97e0a470c945a3dca22116689e1b5f27f1daf8d0d

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

require 'polytrix/rspec'
require 'hashie/mash'
require 'yaml'
require 'fileutils'

module Polytrix
  module RSpec
    class YAMLReport < ::RSpec::Core::Formatters::BaseFormatter
      def example_passed(example)
        add_implementation_result example, :passed
      end

      def example_failed(example)
        add_implementation_result example, :failed
      end

      def example_pending(example)
        add_implementation_result example, :pending
      end

      def dump_summary(duration, example_count, failure_count, pending_count)
        results = Hashie::Mash.new(Polytrix.manifest.dup.to_hash)
        all_challenges = examples.map { |e| e.metadata[:polytrix_challenge] }
        grouped_challenges = all_challenges.compact.group_by(&:name)
        results.suites.each do |suite_name, suite|
          suite.samples = suite.samples.each_with_object({}) do |sample_name, sample_results|
            sample_results[sample_name] ||= {}
            if grouped_challenges[sample_name]
              challenge_results = grouped_challenges[sample_name]
              challenge_results.each do |challenge|
                sample_results[sample_name][challenge.implementor.name] = challenge.result
              end
            end
          end
        end
        @output.puts YAML.dump(results.to_hash)
      end

      private

      def add_implementation_result(example, state)
        validation = Validation.new(
          validated_by: 'polytrix',
          result: state.to_s
        )
        challenge = example.metadata[:polytrix_challenge]
        challenge.result.validations << validation unless challenge.nil? || challenge.result.nil?
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
polytrix-0.1.2 lib/polytrix/rspec/yaml_report.rb
polytrix-0.1.1 lib/polytrix/rspec/yaml_report.rb
polytrix-0.1.0 lib/polytrix/rspec/yaml_report.rb
polytrix-0.1.0.pre lib/polytrix/rspec/yaml_report.rb