diff options
author | Benoit Daloze <eregontp@gmail.com> | 2024-02-05 16:29:57 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2024-02-05 16:29:57 +0100 |
commit | 40642cd3bc581d3bb402ea5e8e61cdfb868b4f68 (patch) | |
tree | 077cc3ac94f880ce3c8c98322331c01cb1cc9cb8 /spec/ruby/core/thread | |
parent | abe07d4bf5f2f848b22e511a647a85c878066adb (diff) |
Update to ruby/spec@3fc4444
Diffstat (limited to 'spec/ruby/core/thread')
-rw-r--r-- | spec/ruby/core/thread/backtrace/location/lineno_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/thread/fetch_spec.rb | 30 | ||||
-rw-r--r-- | spec/ruby/core/thread/thread_variable_get_spec.rb | 2 |
3 files changed, 32 insertions, 2 deletions
diff --git a/spec/ruby/core/thread/backtrace/location/lineno_spec.rb b/spec/ruby/core/thread/backtrace/location/lineno_spec.rb index d14cf17514..10457f80f0 100644 --- a/spec/ruby/core/thread/backtrace/location/lineno_spec.rb +++ b/spec/ruby/core/thread/backtrace/location/lineno_spec.rb @@ -7,7 +7,7 @@ describe 'Thread::Backtrace::Location#lineno' do @line = __LINE__ - 1 end - it 'returns the absolute path of the call frame' do + it 'returns the line number of the call frame' do @frame.lineno.should == @line end diff --git a/spec/ruby/core/thread/fetch_spec.rb b/spec/ruby/core/thread/fetch_spec.rb index 6b37d4cfc5..85ffb71874 100644 --- a/spec/ruby/core/thread/fetch_spec.rb +++ b/spec/ruby/core/thread/fetch_spec.rb @@ -29,6 +29,36 @@ describe 'Thread#fetch' do end end + describe 'with a block' do + it 'returns the value of the fiber-local variable if value has been assigned' do + th = Thread.new { Thread.current[:cat] = 'meow' } + th.join + th.fetch(:cat) { true }.should == 'meow' + end + + it "returns the block value if fiber-local variable hasn't been assigned" do + th = Thread.new {} + th.join + th.fetch(:cat) { true }.should == true + end + + it "does not call the block if value has been assigned" do + th = Thread.new { Thread.current[:cat] = 'meow' } + th.join + var = :not_updated + th.fetch(:cat) { var = :updated }.should == 'meow' + var.should == :not_updated + end + + it "uses the block if a default is given and warns about it" do + th = Thread.new {} + th.join + -> { + th.fetch(:cat, false) { true }.should == true + }.should complain(/warning: block supersedes default value argument/) + end + end + it 'raises an ArgumentError when not passed one or two arguments' do -> { Thread.current.fetch() }.should raise_error(ArgumentError) -> { Thread.current.fetch(1, 2, 3) }.should raise_error(ArgumentError) diff --git a/spec/ruby/core/thread/thread_variable_get_spec.rb b/spec/ruby/core/thread/thread_variable_get_spec.rb index 38f90d5830..0ad19bfd88 100644 --- a/spec/ruby/core/thread/thread_variable_get_spec.rb +++ b/spec/ruby/core/thread/thread_variable_get_spec.rb @@ -13,7 +13,7 @@ describe "Thread#thread_variable_get" do @t.thread_variable_get(:a).should be_nil end - it "returns the value previously set by #[]=" do + it "returns the value previously set by #thread_variable_set" do @t.thread_variable_set :a, 49 @t.thread_variable_get(:a).should == 49 end |