-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from gongo/turnip_base_formatter
Preparing to increase format of output other than html.
- Loading branch information
Showing
53 changed files
with
662 additions
and
616 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
require 'rspec/core/formatters/base_formatter' | ||
require 'turnip_formatter/scenario/pass' | ||
require 'turnip_formatter/scenario/failure' | ||
require 'turnip_formatter/scenario/pending' | ||
require_relative './turnip_formatter/for_rspec2' | ||
require_relative './turnip_formatter/for_rspec3' | ||
|
||
module RSpec | ||
module Core | ||
module Formatters | ||
class TurnipBaseFormatter < BaseFormatter | ||
attr_reader :scenarios | ||
|
||
def self.inherited(child) | ||
if Formatters.respond_to?(:register) | ||
# not called `child.include` for 1.9.3 | ||
child.send(:include, TurnipFormatter::ForRSpec3) | ||
else | ||
child.send(:include, TurnipFormatter::ForRSpec2) | ||
end | ||
end | ||
|
||
def initialize(output) | ||
super(output) | ||
@scenarios = [] | ||
end | ||
|
||
def output_summary(params) | ||
end | ||
|
||
def output_scenario(scenario) | ||
@scenarios << scenario | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
require 'rspec/core/formatters/turnip_base_formatter' | ||
require 'turnip_formatter/html/printer/index' | ||
require 'turnip_formatter/html/printer/scenario' | ||
|
||
module RSpec | ||
module Core | ||
module Formatters | ||
class TurnipHtmlFormatter < TurnipBaseFormatter | ||
attr_reader :scenario_output_files | ||
|
||
SCENARIO_TEMPORARY_OUTPUT_DIR = File.expand_path('./turnip_tmp') | ||
|
||
def initialize(output) | ||
super(output) | ||
@scenario_output_files = [] | ||
FileUtils.mkdir_p(SCENARIO_TEMPORARY_OUTPUT_DIR) | ||
end | ||
|
||
def output_summary(params) | ||
output.puts ::TurnipFormatter::Html::Printer::Index.print_out(params) | ||
FileUtils.rm_rf(SCENARIO_TEMPORARY_OUTPUT_DIR) | ||
end | ||
|
||
def output_scenario(scenario) | ||
super(scenario) | ||
|
||
filepath = SCENARIO_TEMPORARY_OUTPUT_DIR + "/#{scenario.id}.html" | ||
|
||
File.open(filepath, 'w') do |io| | ||
io.puts ::TurnipFormatter::Html::Printer::Scenario.print_out(scenario) | ||
end | ||
|
||
@scenario_output_files << filepath | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'tilt' | ||
|
||
module TurnipFormatter | ||
module Html | ||
module Printer | ||
# | ||
# @example | ||
# render_template(:main, { name: 'user' }) | ||
# # => Tilt.new('/path/to/main.erb') render { name: 'user' } | ||
# | ||
def render_template(name, params = {}) | ||
render_template_list(name).render(self, params) | ||
end | ||
|
||
private | ||
|
||
def render_template_list(name) | ||
if templates[name].nil? | ||
path = File.dirname(__FILE__) + "/template/#{name}.haml" | ||
templates[name] = Tilt.new(path) | ||
end | ||
|
||
templates[name] | ||
end | ||
|
||
def templates | ||
@templates ||= {} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'turnip_formatter/html/printer' | ||
require 'turnip_formatter/html/printer/scenario' | ||
require 'turnip_formatter/html/printer/tab_feature_statistics' | ||
require 'turnip_formatter/html/printer/tab_tag_statistics' | ||
require 'turnip_formatter/html/printer/tab_speed_statistics' | ||
|
||
module TurnipFormatter | ||
module Html | ||
module Printer | ||
class Index | ||
class << self | ||
include TurnipFormatter::Html::Printer | ||
|
||
def print_out(params) | ||
render_template(:index, { | ||
scenarios: params[:scenarios], | ||
failed_count: params[:failed_count], | ||
pending_count: params[:pending_count], | ||
total_time: params[:total_time], | ||
scenario_files: params[:scenario_files] | ||
} | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'turnip_formatter/html/printer' | ||
require 'turnip_formatter/html/printer/step_extra_args' | ||
|
||
module TurnipFormatter | ||
module Html | ||
module Printer | ||
class RuntimeError | ||
class << self | ||
include TurnipFormatter::Html::Printer | ||
|
||
def print_out(example, exception) | ||
render_template(:runtime_exception, { | ||
example: example, | ||
runtime_exception: runtime_exception(exception), | ||
example_exception: example_exception(example), | ||
} | ||
) | ||
end | ||
|
||
private | ||
|
||
def runtime_exception(exception) | ||
render_template(:exception, { title: 'Runtime', exception: exception }) | ||
end | ||
|
||
def example_exception(example) | ||
unless example.exception | ||
'' | ||
else | ||
render_template(:exception, { | ||
title: 'Example', | ||
exception: example.exception | ||
} | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'turnip_formatter/html/printer' | ||
require 'turnip_formatter/html/printer/step' | ||
require 'turnip_formatter/html/printer/runtime_error' | ||
|
||
module TurnipFormatter | ||
module Html | ||
module Printer | ||
class Scenario | ||
class << self | ||
include TurnipFormatter::Html::Printer | ||
|
||
def print_out(scenario) | ||
# | ||
# TODO output for scenario.valid? == false | ||
# | ||
render_template(:scenario, scenario: scenario) if scenario.valid? | ||
rescue => e | ||
TurnipFormatter::Html::Printer::RuntimeError.print_out(scenario.example, e) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'turnip_formatter/html/printer' | ||
require 'turnip_formatter/html/printer/step_extra_args' | ||
|
||
module TurnipFormatter | ||
module Html | ||
module Printer | ||
class Step | ||
class << self | ||
include TurnipFormatter::Html::Printer | ||
|
||
def print_out(step) | ||
step_templates = TurnipFormatter.step_templates_for(step.status) | ||
|
||
render_template(:step, | ||
{ | ||
step: step, | ||
has_args_or_documents: has_args_or_documents?(step, step_templates), | ||
step_docs: documents(step, step_templates) | ||
} | ||
) | ||
end | ||
|
||
private | ||
|
||
def has_args_or_documents?(step, templates) | ||
(step.extra_args.length + templates.length) > 0 | ||
end | ||
|
||
def documents(step, templates) | ||
templates.map do |template, method| | ||
template.send(method, step.example) | ||
end.join("\n") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'turnip_formatter/html/printer' | ||
|
||
module TurnipFormatter | ||
module Html | ||
module Printer | ||
class StepExtraArgs | ||
class << self | ||
include TurnipFormatter::Html::Printer | ||
|
||
def print_out(args) | ||
return '' if args.nil? | ||
|
||
args.map do |arg| | ||
if arg.instance_of?(Turnip::Table) | ||
render_template(:step_outline, { table: arg.to_a }) | ||
else | ||
render_template(:step_multiline, { lines: arg }) | ||
end | ||
end.join | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.