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 +17
-8
lines changed Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
+ class Thread
4
+ attr_accessor :__rspec_local_data
5
+ end
6
+
3
7
module RSpec
4
8
module Support
5
9
# @api private
@@ -91,14 +95,8 @@ def self.class_of(object)
91
95
end
92
96
93
97
# A single thread local variable so we don't excessively pollute that namespace.
94
- if RUBY_VERSION . to_f >= 2
95
- def self . thread_local_data
96
- Thread . current . thread_variable_get ( :__rspec ) || Thread . current . thread_variable_set ( :__rspec , { } )
97
- end
98
- else
99
- def self . thread_local_data
100
- Thread . current [ :__rspec ] ||= { }
101
- end
98
+ def self . thread_local_data
99
+ Thread . current . __rspec_local_data ||= { }
102
100
end
103
101
104
102
# @api private
Original file line number Diff line number Diff line change @@ -204,6 +204,17 @@ def object.some_method
204
204
end . resume
205
205
end
206
206
end
207
+
208
+ it "works when Thread#thread_variable_get and Thread#thread_variable_set are mocked" do
209
+ expect ( Thread . current ) . to receive ( :thread_variable_set ) . with ( :test , true ) . once . and_return ( true )
210
+ expect ( Thread . current ) . to receive ( :thread_variable_get ) . with ( :test ) . once . and_return ( true )
211
+
212
+ Thread . current . thread_variable_set ( :test , true )
213
+ expect ( Thread . current . thread_variable_get ( :test ) ) . to eq true
214
+
215
+ RSpec ::Support . thread_local_data [ :__for_test ] = :oh_hai
216
+ expect ( RSpec ::Support . thread_local_data [ :__for_test ] ) . to eq :oh_hai
217
+ end
207
218
end
208
219
209
220
describe "failure notification" do
You can’t perform that action at this time.
0 commit comments