Sha256: 03d4ec23d15ed5adf78bf946fed657673af1a59a60fa11a5fb716ae4cb805727

Contents?: true

Size: 1.86 KB

Versions: 8

Compression:

Stored size: 1.86 KB

Contents

# -*- coding: utf-8 -*-

require 'rspec'
require 'rspec/core/formatters/base_formatter'
require 'turnip_formatter/renderer/html/index'
require 'turnip_formatter/resource/scenario/pass'
require 'turnip_formatter/resource/scenario/failure'
require 'turnip_formatter/resource/scenario/pending'

module RSpec
  module Core
    module Formatters
      class TurnipFormatter < BaseFormatter
        attr_accessor :scenarios

        Formatters.register self, :example_passed, :example_pending, :example_failed, :dump_summary

        def self.formatted_backtrace(example, exception = nil)
          exception = example.exception if exception.nil?
          formatter = RSpec.configuration.backtrace_formatter
          formatter.format_backtrace(exception.backtrace, example.metadata)
        end

        def initialize(output)
          super(output)
          @scenarios = []
        end

        def dump_summary(summary)
          print_params = {
            scenarios:      scenarios,
            failed_count:   summary.failure_count,
            pending_count:  summary.pending_count,
            total_time:     summary.duration
          }
          output_html(print_params)
        end

        def example_passed(notification)
          scenario = ::TurnipFormatter::Resource::Scenario::Pass.new(notification.example)
          scenarios << scenario
        end

        def example_pending(notification)
          scenario = ::TurnipFormatter::Resource::Scenario::Pending.new(notification.example)
          scenarios << scenario
        end

        def example_failed(notification)
          scenario = ::TurnipFormatter::Resource::Scenario::Failure.new(notification.example)
          scenarios << scenario
        end

        private

        def output_html(params)
          output.puts ::TurnipFormatter::Renderer::Html::Index.new(params).render
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
turnip_formatter-0.7.2 lib/rspec/core/formatters/turnip_formatter.rb
turnip_formatter-0.7.1 lib/rspec/core/formatters/turnip_formatter.rb
turnip_formatter-0.7.0 lib/rspec/core/formatters/turnip_formatter.rb
turnip_formatter-0.6.1 lib/rspec/core/formatters/turnip_formatter.rb
turnip_formatter-0.6.0 lib/rspec/core/formatters/turnip_formatter.rb
turnip_formatter-0.6.0.pre.beta.7 lib/rspec/core/formatters/turnip_formatter.rb
turnip_formatter-0.6.0.pre.beta.6 lib/rspec/core/formatters/turnip_formatter.rb
turnip_formatter-0.6.0.pre.beta.5 lib/rspec/core/formatters/turnip_formatter.rb