Skip to content

Commit 88166ef

Browse files
committed
Minor cleanups and simplifications in thread_local_var_spec
1 parent 9866df2 commit 88166ef

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

spec/concurrent/atomic/thread_local_var_spec.rb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@ module Concurrent
66

77
describe ThreadLocalVar do
88

9-
subject { ThreadLocalVar.new }
10-
119
context '#initialize' do
1210

1311
it 'can set an initial value' do
14-
v = ThreadLocalVar.new(14)
12+
v = described_class.new(14)
1513
expect(v.value).to eq 14
1614
end
1715

1816
it 'sets nil as a default initial value' do
19-
v = ThreadLocalVar.new
17+
v = described_class.new
2018
expect(v.value).to be_nil
2119
end
2220

2321
it 'sets the same initial value for all threads' do
24-
v = ThreadLocalVar.new(14)
22+
v = described_class.new(14)
2523
t1 = Thread.new { v.value }
2624
t2 = Thread.new { v.value }
2725
expect(t1.value).to eq 14
@@ -30,51 +28,47 @@ module Concurrent
3028

3129
if Concurrent.on_jruby?
3230
it 'extends JavaThreadLocalVar' do
33-
expect(subject.class.ancestors).to include(Concurrent::JavaThreadLocalVar)
31+
expect(described_class.ancestors).to include(Concurrent::JavaThreadLocalVar)
3432
end
3533
else
3634
it 'extends RubyThreadLocalVar' do
37-
expect(subject.class.ancestors).to include(Concurrent::RubyThreadLocalVar)
35+
expect(described_class.ancestors).to include(Concurrent::RubyThreadLocalVar)
3836
end
3937
end
4038
end
4139

4240
context '#value' do
41+
let(:v) { described_class.new(14) }
4342

4443
it 'returns the current value' do
45-
v = ThreadLocalVar.new(14)
4644
expect(v.value).to eq 14
4745
end
4846

4947
it 'returns the value after modification' do
50-
v = ThreadLocalVar.new(14)
5148
v.value = 2
5249
expect(v.value).to eq 2
5350
end
5451
end
5552

5653
context '#value=' do
54+
let(:v) { described_class.new(14) }
5755

5856
it 'sets a new value' do
59-
v = ThreadLocalVar.new(14)
6057
v.value = 2
6158
expect(v.value).to eq 2
6259
end
6360

6461
it 'returns the new value' do
65-
v = ThreadLocalVar.new(14)
6662
expect(v.value = 2).to eq 2
6763
end
6864

6965
it 'does not modify the initial value for other threads' do
70-
v = ThreadLocalVar.new(14)
7166
v.value = 2
7267
t = Thread.new { v.value }
7368
expect(t.value).to eq 14
7469
end
7570

7671
it 'does not modify the value for other threads' do
77-
v = ThreadLocalVar.new(14)
7872
v.value = 2
7973

8074
b1 = CountDownLatch.new(2)

0 commit comments

Comments
 (0)