Skip to content

Commit

Permalink
Merge pull request #221 from buildkite/ming/tai-427
Browse files Browse the repository at this point in the history
Fix missing failed examples if rspec hooks fail
  • Loading branch information
zhming0 authored Sep 9, 2024
2 parents e18ce13 + 77c2210 commit 7eacf8a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/buildkite/test_collector/library_hooks/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@
# The _buildkite prefix here is added as a safeguard against name collisions
# as we are in the main thread
Thread.current[:_buildkite_tracer] = tracer
example.run
Thread.current[:_buildkite_tracer] = nil

tracer.finalize

trace = Buildkite::TestCollector::RSpecPlugin::Trace.new(example, history: tracer.history)
Buildkite::TestCollector.uploader.traces[example.id] = trace
# It's important to use begin/ensure here, because otherwise if other hooks fail,
# the cleanup code won't run, meaning we will miss some data.
#
# Having said that, this behavior isn't documented by RSpec.
begin
example.run
ensure
Thread.current[:_buildkite_tracer] = nil

tracer.finalize

trace = Buildkite::TestCollector::RSpecPlugin::Trace.new(example, history: tracer.history)
Buildkite::TestCollector.uploader.traces[example.id] = trace
end
end

config.after(:suite) do
Expand Down

0 comments on commit 7eacf8a

Please sign in to comment.