Skip to content

Commit

Permalink
Expand specs for Thread#thread_variable?
Browse files Browse the repository at this point in the history
* Test with frozen Thread
* Test different key types

The key type behaviour is similar to Thread#thread_variable_get?
  • Loading branch information
herwinw committed Jan 9, 2024
1 parent 2f8508e commit 7ab86dc
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions core/thread/thread_variable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,31 @@
@t.thread_variable_set(:a, 2)
@t.thread_variable?(:a).should be_true
end

it "converts a String key into a Symbol" do
@t.thread_variable_set(:a, 49)
@t.thread_variable?('a').should be_true
end

it "converts a key that is neither String nor Symbol with #to_str" do
key = mock('key')
key.should_receive(:to_str).and_return('a')
@t.thread_variable_set(:a, 49)
@t.thread_variable?(key).should be_true
end

it "does not raise FrozenError if the thread is frozen" do
@t.freeze
@t.thread_variable?(:a).should be_false
end

it "does not raise a TypeError if the key is neither Symbol nor String, nor responds to #to_str" do
@t.thread_variable?(123).should be_false
end

it "does not try to convert the key with #to_sym" do
key = mock('key')
key.should_not_receive(:to_sym)
@t.thread_variable?(key).should be_false
end
end

0 comments on commit 7ab86dc

Please sign in to comment.