Skip to content

fix: copy over rspec context to reactor thread #22

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

Merged
merged 1 commit into from
Jun 5, 2023
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
2 changes: 2 additions & 0 deletions lib/async/rspec/reactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/async/rspec/reactor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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