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 11# frozen_string_literal: true
22
3+ class Thread
4+ attr_accessor :__rspec_local_data
5+ end
6+
37module RSpec
48 module Support
59 # @api private
@@ -91,14 +95,8 @@ def self.class_of(object)
9195 end
9296
9397 # 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 ||= { }
102100 end
103101
104102 # @api private
Original file line number Diff line number Diff line change @@ -204,6 +204,17 @@ def object.some_method
204204 end . resume
205205 end
206206 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
207218 end
208219
209220 describe "failure notification" do
You can’t perform that action at this time.
0 commit comments