Skip to content

Commit

Permalink
Fix the handling of failing around hooks in the JUnit Formatter.
Browse files Browse the repository at this point in the history
Supersedes and closes #1233.
  • Loading branch information
brasmusson committed Nov 19, 2017
1 parent 3ce5aee commit 9605e88
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo

### Fixed

* N/A
* Fix the handling of failed hooks in the JUnit Formatter ([@brasmusson](https://github.com/brasmusson))

### Improved

Expand Down
8 changes: 6 additions & 2 deletions lib/cucumber/formatter/junit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ def create_output_string(test_case, scenario, result, row_name)
output = "#{test_case.keyword}: #{scenario}\n\n"
return output if result.ok?(@config.strict)
if test_case.keyword == 'Scenario'
output += @failing_step_source.keyword.to_s unless hook?(@failing_step_source)
output += "#{@failing_step_source}\n"
if @failing_step_source
output += @failing_step_source.keyword.to_s unless hook?(@failing_step_source)
output += "#{@failing_step_source}\n"
else # An Around hook has failed
output += "Around hook\n"
end
else
output += "Example row: #{row_name}\n"
end
Expand Down
19 changes: 19 additions & 0 deletions spec/cucumber/formatter/junit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,25 @@ def after_step(step)

it { expect(@doc.to_s).to match(%r{AfterStep hook at spec/cucumber/formatter/junit_spec.rb:(\d+)}) }
end

describe 'with a failing around hook' do
define_steps do
Around do |_scenario, block|
block.call
raise 'Around hook failed'
end
Given(/a passing step/) do
end
end
define_feature <<-FEATURE
Feature: One passing scenario
Scenario: Passing
Given a passing step
FEATURE

it { expect(@doc.to_s).to match(/Around hook\n\nMessage:/) }
end
end
end
end
Expand Down

0 comments on commit 9605e88

Please sign in to comment.