Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve cucumber latest error message with exit code to fix problem … #10

Merged
merged 2 commits into from
May 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lib/knapsack_pro/adapters/cucumber_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions spec/knapsack_pro/adapters/cucumber_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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