forked from ruby-concurrency/concurrent-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
constant_thread_local_var_spec.rb
56 lines (44 loc) · 1.22 KB
/
constant_thread_local_var_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'rbconfig'
module Concurrent
require 'concurrent/atomic/constant_thread_local_var'
RSpec.describe ConstantThreadLocalVar do
context "#value" do
it 'can return default value' do
v = described_class.new("apple")
expect(v.value).to eq("apple")
v = described_class.new do
"orange"
end
expect(v.value).to eq("orange")
end
end
context "#value=" do
it 'can set value to same value' do
v = described_class.new("apple")
v.value = "apple"
end
it 'will raise an ArgumentError when attempting to change immutable value' do
v = described_class.new do
"apple"
end
expect do
v.value = "orange"
end.to raise_error(ArgumentError)
end
end
context '#bind' do
it 'will raise when attempting to bind to a different value' do
v = described_class.new("apple")
expect do
v.bind("orange") {}
end.to raise_error(ArgumentError)
end
it 'works when bind value is the same' do
v = described_class.new("apple")
v.bind("apple") do
expect(v.value).to eq("apple")
end
end
end
end
end