This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree 3 files changed +33
-2
lines changed
3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 1
1
### Development
2
2
[ Full Changelog] ( http://github.com/rspec/rspec-support/compare/v3.12.0...main )
3
3
4
+ Bug Fixes:
5
+
6
+ * Fix ` RSpec::Support.thread_local_data ` to be Thread local but not Fiber local.
7
+ (Jon Rowe, #581 )
8
+
4
9
### 3.12.0 / 2022-10-26
5
10
[ Full Changelog] ( http://github.com/rspec/rspec-support/compare/v3.11.1...v3.12.0 )
6
11
Enhancements:
Original file line number Diff line number Diff line change @@ -89,8 +89,14 @@ def self.class_of(object)
89
89
end
90
90
91
91
# A single thread local variable so we don't excessively pollute that namespace.
92
- def self . thread_local_data
93
- Thread . current [ :__rspec ] ||= { }
92
+ if RUBY_VERSION . to_f >= 2
93
+ def self . thread_local_data
94
+ Thread . current . thread_variable_get ( :__rspec ) || Thread . current . thread_variable_set ( :__rspec , { } )
95
+ end
96
+ else
97
+ def self . thread_local_data
98
+ Thread . current [ :__rspec ] ||= { }
99
+ end
94
100
end
95
101
96
102
# @api private
Original file line number Diff line number Diff line change @@ -186,6 +186,26 @@ def object.some_method
186
186
end
187
187
end
188
188
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 ) && RUBY_VERSION . to_f >= 2.0
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
+
189
209
describe "failure notification" do
190
210
before { @failure_notifier = RSpec ::Support . failure_notifier }
191
211
after { RSpec ::Support . failure_notifier = @failure_notifier }
You can’t perform that action at this time.
0 commit comments