This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree 1 file changed +10
-7
lines changed
1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -90,15 +90,18 @@ def self.class_of(object)
90
90
singleton_class . ancestors . find { |ancestor | !ancestor . equal? ( singleton_class ) }
91
91
end
92
92
93
- # A single thread local variable so we don't excessively pollute that namespace .
93
+ # Stash original methods to allow the user to mock them .
94
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
95
+ @thread_variable_get = Thread . instance_method ( :thread_variable_get )
96
+ @thread_variable_set = Thread . instance_method ( :thread_variable_set )
98
97
else
99
- def self . thread_local_data
100
- Thread . current [ :__rspec ] ||= { }
101
- end
98
+ @thread_variable_get = Thread . instance_method ( :[] )
99
+ @thread_variable_set = Thread . instance_method ( :[]= )
100
+ end
101
+
102
+ # A single thread local variable so we don't excessively pollute that namespace.
103
+ def self . thread_local_data
104
+ @thread_variable_get . bind ( Thread . current ) . call ( :__rspec ) || @thread_variable_set . bind ( Thread . current ) . call ( :__rspec , { } )
102
105
end
103
106
104
107
# @api private
You can’t perform that action at this time.
0 commit comments