This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ def self.class_of(object)
9090
9191 # A single thread local variable so we don't excessively pollute that namespace.
9292 def self . thread_local_data
93- Thread . current [ :__rspec ] ||= { }
93+ Thread . current . thread_variable_get ( :__rspec ) || Thread . current . thread_variable_set ( :__rspec , { } )
9494 end
9595
9696 # @api private
Original file line number Diff line number Diff line change @@ -186,6 +186,26 @@ def object.some_method
186186 end
187187 end
188188
189+ describe ".thread_local_data" do
190+ it "contains data local to the current thread" do
191+ RSpec ::Support . thread_local_data [ :__for_test ] = :oh_hai
192+
193+ Thread . new do
194+ expect ( RSpec ::Support . thread_local_data ) . to eq ( { } )
195+ end . join
196+ end
197+
198+ if defined? ( Fiber )
199+ it "shares data across fibres" do
200+ RSpec ::Support . thread_local_data [ :__for_test ] = :oh_hai
201+
202+ Fiber . new do
203+ expect ( RSpec ::Support . thread_local_data [ :__for_test ] ) . to eq ( :oh_hai )
204+ end . resume
205+ end
206+ end
207+ end
208+
189209 describe "failure notification" do
190210 before { @failure_notifier = RSpec ::Support . failure_notifier }
191211 after { RSpec ::Support . failure_notifier = @failure_notifier }
You can’t perform that action at this time.
0 commit comments