From 9536465d1a28ed54eb98c4e3e4ac2d655182d862 Mon Sep 17 00:00:00 2001 From: ArturT Date: Fri, 20 May 2016 13:57:30 +0200 Subject: [PATCH 1/2] Preserve cucumber latest error message with exit code to fix problem with false positive cucumber failed tests --- lib/knapsack_pro/adapters/cucumber_adapter.rb | 9 ++++++++- .../adapters/cucumber_adapter_spec.rb | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/knapsack_pro/adapters/cucumber_adapter.rb b/lib/knapsack_pro/adapters/cucumber_adapter.rb index ed690f44..c7703307 100644 --- a/lib/knapsack_pro/adapters/cucumber_adapter.rb +++ b/lib/knapsack_pro/adapters/cucumber_adapter.rb @@ -41,9 +41,16 @@ def bind_time_tracker end end - def bind_save_report + def bind_save_report(latest_error = nil) ::Kernel.at_exit do + # $! is latest error message + latest_error = (latest_error || $!) + exit_status = latest_error.status if latest_error.is_a?(SystemExit) + #require 'pry'; binding.pry + # saving report makes API call which changes exit status + # from cucumber so we need to preserve cucumber exit status KnapsackPro::Report.save + ::Kernel.exit exit_status if exit_status end end diff --git a/spec/knapsack_pro/adapters/cucumber_adapter_spec.rb b/spec/knapsack_pro/adapters/cucumber_adapter_spec.rb index 05f770b6..02ac6f6c 100644 --- a/spec/knapsack_pro/adapters/cucumber_adapter_spec.rb +++ b/spec/knapsack_pro/adapters/cucumber_adapter_spec.rb @@ -129,6 +129,21 @@ subject.bind_save_report end + + context 'when cucumber tests failed' do + let(:exit_status) { double } + let(:latest_error) { instance_double(SystemExit, status: exit_status) } + + it 'preserves cucumber latest error message exit status' do + expect(::Kernel).to receive(:at_exit).and_yield + + expect(latest_error).to receive(:is_a?).with(SystemExit).and_return(true) + expect(KnapsackPro::Report).to receive(:save) + expect(::Kernel).to receive(:exit).with(exit_status) + + subject.bind_save_report(latest_error) + end + end end end end From 73186cb689afd147e799cfe1a7dd6be37e141d7f Mon Sep 17 00:00:00 2001 From: ArturT Date: Fri, 20 May 2016 14:02:34 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 178f5ed6..39baf2b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ * TODO +### 0.7.2 + +* Preserve cucumber latest error message with exit code to fix problem with false positive cucumber failed tests + + https://github.com/KnapsackPro/knapsack_pro-ruby/pull/10 + +https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v0.7.1...v0.7.2 + ### 0.7.1 * Don't fail when there are no tests to run on a node