This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree 2 files changed +11
-1
lines changed
2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
class Thread
4
4
attr_accessor :__rspec_local_data
5
+ class << self
6
+ alias __current_for_rspec current
7
+ end
5
8
end
6
9
7
10
module RSpec
@@ -96,7 +99,7 @@ def self.class_of(object)
96
99
97
100
# A single thread local variable so we don't excessively pollute that namespace.
98
101
def self . thread_local_data
99
- Thread . current . __rspec_local_data ||= { }
102
+ Thread . __current_for_rspec . __rspec_local_data ||= { }
100
103
end
101
104
102
105
# @api private
Original file line number Diff line number Diff line change @@ -205,6 +205,13 @@ def object.some_method
205
205
end
206
206
end
207
207
208
+ it "works when Thread.current is mocked" do
209
+ expect ( Thread ) . to_not receive ( :current )
210
+
211
+ RSpec ::Support . thread_local_data [ :__for_test ] = :oh_hai
212
+ expect ( RSpec ::Support . thread_local_data [ :__for_test ] ) . to eq :oh_hai
213
+ end
214
+
208
215
it "works when Thread#thread_variable_get and Thread#thread_variable_set are mocked" do
209
216
expect ( Thread . current ) . to receive ( :thread_variable_set ) . with ( :test , true ) . once . and_return ( true )
210
217
expect ( Thread . current ) . to receive ( :thread_variable_get ) . with ( :test ) . once . and_return ( true )
You can’t perform that action at this time.
0 commit comments