This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 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)
9090 singleton_class . ancestors . find { |ancestor | !ancestor . equal? ( singleton_class ) }
9191 end
9292
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 .
9494 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 )
9897 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 , { } )
102105 end
103106
104107 # @api private
You can’t perform that action at this time.
0 commit comments