Skip to content

Commit

Permalink
Support custom formatter on RSpec3
Browse files Browse the repository at this point in the history
  • Loading branch information
gongo committed Jul 29, 2014
1 parent fca9155 commit f42c421
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rspec/core/formatters/turnip_formatter.rb
Expand Up @@ -7,6 +7,7 @@
require 'turnip_formatter/printer/index'
require 'turnip_formatter/printer/scenario'
require_relative './turnip_formatter/for_rspec2'
require_relative './turnip_formatter/for_rspec3'

module RSpec
module Core
Expand All @@ -16,7 +17,12 @@ class TurnipFormatter < BaseFormatter

SCENARIO_TEMPORARY_OUTPUT_DIR = File.expand_path('./turnip_tmp')

include TurnipFormatter::ForRSpec2
if Formatters.respond_to?(:register)
include TurnipFormatter::ForRSpec3
Formatters.register self, :example_passed, :example_pending, :example_failed, :dump_summary
else
include TurnipFormatter::ForRSpec2
end

def initialize(output)
super(output)
Expand Down
48 changes: 48 additions & 0 deletions lib/rspec/core/formatters/turnip_formatter/for_rspec3.rb
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-

module RSpec
module Core
module Formatters
class TurnipFormatter < BaseFormatter
module ForRSpec3
def dump_summary(summary)
print_params = {
scenarios: scenarios,
failed_count: summary.failure_count,
pending_count: summary.pending_count,
total_time: summary.duration,
scenario_files: scenario_output_files
}
output_html(print_params)
end

def example_passed(notification)
scenario = ::TurnipFormatter::Scenario::Pass.new(notification.example)
output_scenario(scenario)
end

def example_pending(notification)
clean_backtrace(notification)
scenario = ::TurnipFormatter::Scenario::Pending.new(notification.example)
output_scenario(scenario)
end

def example_failed(notification)
clean_backtrace(notification)
scenario = ::TurnipFormatter::Scenario::Failure.new(notification.example)
output_scenario(scenario)
end

private

def clean_backtrace(notification)
if notification.respond_to?(:formatted_backtrace)
formatted = notification.formatted_backtrace
notification.example.exception.set_backtrace(formatted)
end
end
end
end
end
end
end

0 comments on commit f42c421

Please sign in to comment.