lib/cucumber/formatter/legacy_api/adapter.rb in cucumber-2.0.0 vs lib/cucumber/formatter/legacy_api/adapter.rb in cucumber-2.0.1
- old
+ new
@@ -1,9 +1,10 @@
require 'forwardable'
require 'delegate'
require 'cucumber/errors'
require 'cucumber/multiline_argument'
+require 'cucumber/formatter/backtrace_filter'
require 'cucumber/formatter/legacy_api/ast'
module Cucumber
module Formatter
module LegacyApi
@@ -27,17 +28,17 @@
printer.before_test_step(test_step)
end
def after_test_step(test_step, result)
printer.after_test_step(test_step, result)
- formatter.after_test_step(test_step, result)
+ formatter.after_test_step(test_step, result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter))
end
def after_test_case(test_case, result)
record_test_case_result(test_case, result)
printer.after_test_case(test_case, result)
- formatter.after_test_case(test_case, result)
+ formatter.after_test_case(test_case, result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter))
end
def puts(*messages)
printer.puts(messages)
end
@@ -269,11 +270,11 @@
@delayed_embeddings = []
end
def after_step_hook(hook, result)
p current_test_step_source if current_test_step_source.step.nil?
- line = StepBacktraceLine.new(current_test_step_source.step)
+ line = current_test_step_source.step.backtrace_line
@child.after_step_hook Ast::HookResult.new(LegacyResultBuilder.new(result).
append_to_exception_backtrace(line), @delayed_messages, @delayed_embeddings)
@delayed_messages = []
@delayed_embeddings = []
end
@@ -319,11 +320,11 @@
def select_step_container(source)
if source.background
if same_background_as_previous_test_case?(source)
HiddenBackgroundPrinter.new(formatter, source.background)
else
- BackgroundPrinter.new(formatter, source.background, before_hook_results)
+ BackgroundPrinter.new(formatter, node, source.background, before_hook_results)
end
elsif source.scenario
ScenarioPrinter.new(formatter, source.scenario, before_hook_results)
elsif source.scenario_outline
if same_scenario_outline_as_previous_test_case?(source) and @previous_outline_child
@@ -446,20 +447,21 @@
def after
after_hook_results.accept(formatter)
end
end
- BackgroundPrinter = Struct.new(:formatter, :node, :before_hook_results) do
+ BackgroundPrinter = Struct.new(:formatter, :feature, :node, :before_hook_results) do
def after_test_case(*)
end
def after_hook(*)
end
def before
- formatter.before_background node
+ formatter.before_background Ast::Background.new(feature, node)
+ Ast::Comments.new(node.comments).accept(formatter)
formatter.background_name node.keyword, node.legacy_conflated_name_and_description, node.location.to_s, indent.of(node)
before_hook_results.accept(formatter)
self
end
@@ -475,11 +477,11 @@
end
end
def after
@child.after if @child
- formatter.after_background(node)
+ formatter.after_background(Ast::Background.new(feature, node))
self
end
def failed?
@failed
@@ -517,10 +519,11 @@
ScenarioPrinter = Struct.new(:formatter, :node, :before_hook_results) do
include PrintsAfterHooks
def before
formatter.before_feature_element(node)
+ Ast::Comments.new(node.comments).accept(formatter)
Ast::Tags.new(node.tags).accept(formatter)
formatter.scenario_name node.keyword, node.legacy_conflated_name_and_description, node.location.to_s, indent.of(node)
before_hook_results.accept(formatter)
self
end
@@ -591,10 +594,11 @@
extend Forwardable
def_delegators :@child, :after_hook, :after_step_hook
def before
formatter.before_feature_element(node)
+ Ast::Comments.new(node.comments).accept(formatter)
Ast::Tags.new(node.tags).accept(formatter)
formatter.scenario_name node.keyword, node.legacy_conflated_name_and_description, node.location.to_s, indent.of(node)
OutlineStepsPrinter.new(formatter, configuration, indent).print(node)
self
end
@@ -691,10 +695,12 @@
extend Forwardable
def_delegators :@child, :step_invocation, :after_hook, :after_step_hook, :after_test_case
def before
formatter.before_examples(node)
+ Ast::Comments.new(node.comments).accept(formatter)
+ Ast::Tags.new(node.tags).accept(formatter)
formatter.examples_name(node.keyword, node.legacy_conflated_name_and_description)
formatter.before_outline_table(legacy_table)
if !configuration.expand?
HeaderTableRowPrinter.new(formatter, ExampleTableRow.new(node.header), Ast::Node.new).before.after
end
@@ -801,10 +807,11 @@
def legacy_table_row
Ast::ExampleTableRow.new(exception, @status, node.values, node.location, Ast::NullLanguage.new)
end
def before
+ Ast::Comments.new(node.comments).accept(formatter)
formatter.before_table_row(node)
self
end
def after
@@ -820,10 +827,11 @@
class TableRowPrinter < TableRowPrinterBase
def before
before_hook_results.accept(formatter)
+ Ast::Comments.new(node.comments).accept(formatter)
formatter.before_table_row(node)
self
end
def step_invocation(step_invocation, source)
@@ -993,67 +1001,23 @@
def step_exception(step, configuration)
return filtered_step_exception(step) if @exception
return nil unless @status == :undefined && configuration.strict?
@exception = Cucumber::Undefined.from(@result, step.name)
+ @exception.backtrace << step.backtrace_line
filtered_step_exception(step)
end
def filtered_exception
- BacktraceFilter.new(@exception.dup).exception
+ Cucumber::Formatter::BacktraceFilter.new(@exception.dup).exception
end
def filtered_step_exception(step)
exception = filtered_exception
- exception.backtrace << StepBacktraceLine.new(step).to_s
- return BacktraceFilter.new(exception).exception
+ return Cucumber::Formatter::BacktraceFilter.new(exception).exception
end
end
- end
-
- class StepBacktraceLine < Struct.new(:step)
- def initialize(step)
- raise ArgumentError if step.nil?
- super
- end
-
- def to_s
- step.backtrace_line
- end
- end
-
- require 'cucumber/platform'
- class BacktraceFilter
- BACKTRACE_FILTER_PATTERNS = \
- [/vendor\/rails|lib\/cucumber|bin\/cucumber:|lib\/rspec|gems\/|minitest|test\/unit|.gem\/ruby|lib\/ruby/]
- if(::Cucumber::JRUBY)
- BACKTRACE_FILTER_PATTERNS << /org\/jruby/
- end
- PWD_PATTERN = /#{::Regexp.escape(::Dir.pwd)}\//m
-
- def initialize(exception)
- @exception = exception
- end
-
- def exception
- return @exception if ::Cucumber.use_full_backtrace
- @exception.backtrace.each{|line| line.gsub!(PWD_PATTERN, "./")}
-
- filtered = (@exception.backtrace || []).reject do |line|
- BACKTRACE_FILTER_PATTERNS.detect { |p| line =~ p }
- end
-
- if ::ENV['CUCUMBER_TRUNCATE_OUTPUT']
- # Strip off file locations
- filtered = filtered.map do |line|
- line =~ /(.*):in `/ ? $1 : line
- end
- end
-
- @exception.set_backtrace(filtered)
- @exception
- end
end
end
end
end