From 1d74f3c457d3c20d7a201fac70fb6c121e534fd0 Mon Sep 17 00:00:00 2001 From: Robin Goos Date: Thu, 25 May 2023 10:59:57 -0700 Subject: [PATCH] fix: copy over rspec context to reactor thread --- lib/async/rspec/reactor.rb | 2 ++ spec/async/rspec/reactor_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/async/rspec/reactor.rb b/lib/async/rspec/reactor.rb index d78ff4a..0c5cba3 100644 --- a/lib/async/rspec/reactor.rb +++ b/lib/async/rspec/reactor.rb @@ -78,6 +78,7 @@ def run_in_reactor(reactor, duration = nil) include Reactor let(:reactor) {@reactor} + rspec_context = Thread.current[:__rspec] include_context Async::RSpec::Leaks around(:each) do |example| @@ -90,6 +91,7 @@ def run_in_reactor(reactor, duration = nil) task.annotate(self.class) run_in_reactor(@reactor, duration) do + Thread.current[:__rspec] = rspec_context example.run end ensure diff --git a/spec/async/rspec/reactor_spec.rb b/spec/async/rspec/reactor_spec.rb index 7529218..1a6558a 100644 --- a/spec/async/rspec/reactor_spec.rb +++ b/spec/async/rspec/reactor_spec.rb @@ -82,4 +82,13 @@ # end.to raise_error("Boom!") # end end + + context "rspec metadata", timeout: 1 do + include_context Async::RSpec::Reactor + + it "should have access to example metadata" do + expect(RSpec.current_example).not_to be_nil + expect(RSpec.current_example.metadata[:described_class]).to eq(Async::RSpec::Reactor) + end + end end