From ae286fad211e53b8c7ab1e487c3cb5cea71a647a Mon Sep 17 00:00:00 2001 From: Matt Wynne Date: Mon, 21 Sep 2009 22:15:46 +0100 Subject: [PATCH] Fix for when step fails in scenario that already failed in background --- lib/cucumber/formatter/html.rb | 8 +++++--- spec/cucumber/formatter/html_spec.rb | 28 ++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/cucumber/formatter/html.rb b/lib/cucumber/formatter/html.rb index 1d60d5fb7f..43ca5a9e74 100644 --- a/lib/cucumber/formatter/html.rb +++ b/lib/cucumber/formatter/html.rb @@ -122,7 +122,6 @@ def visit_background_name(keyword, name, file_colon_line, source_indent) def before_visit_feature_element(feature_element) start_buffering :feature_element - @exceptions = [] end def after_visit_feature_element(feature_element) @@ -198,9 +197,11 @@ def before_visit_step_result(keyword, step_match, multiline_arg, status, excepti start_buffering :step_result @hide_this_step = false if exception - @hide_this_step = true if @exceptions.index(exception) + if @exceptions.include?(exception) + @hide_this_step = true + return + end @exceptions << exception - return end if status != :failed && @in_background ^ background @hide_this_step = true @@ -229,6 +230,7 @@ def visit_step_name(keyword, step_match, status, source_indent, background) end def visit_exception(exception, status) + return if @hide_this_step builder.pre(format_exception(exception), :class => status) end diff --git a/spec/cucumber/formatter/html_spec.rb b/spec/cucumber/formatter/html_spec.rb index d59a24145b..b65d6fc390 100644 --- a/spec/cucumber/formatter/html_spec.rb +++ b/spec/cucumber/formatter/html_spec.rb @@ -167,20 +167,36 @@ def define_steps it { @doc.should have_css_node('.feature .scenario table td', /foo/) } end - describe "with a step that fails" do + describe "with a step that fails in the scenario" do define_steps do - Given /boo/ do - raise 'eek' - end + Given(/boo/) { raise 'eek' } end define_feature(<<-FEATURE) - Scenario: Monkey get a fright + Scenario: Monkey gets a fright Given boo FEATURE - + it { @doc.should have_css_node('.feature .scenario .step.failed', /eek/) } end + + describe "with a step that fails in the backgound" do + define_steps do + Given(/boo/) { raise 'eek' } + end + + define_feature(<<-FEATURE) + Background: + Given boo + Scenario: + Given yay + FEATURE + + it { @doc.should have_css_node('.feature .background .step.failed', /eek/) } + it { @doc.should_not have_css_node('.feature .scenario .step.failed', //) } + it { @doc.should have_css_node('.feature .scenario .step.undefined', /yay/) } + end + end end end