File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 29
29
end
30
30
end
31
31
32
+ describe 'with a block' do
33
+ it 'returns the value of the fiber-local variable if value has been assigned' do
34
+ th = Thread . new { Thread . current [ :cat ] = 'meow' }
35
+ th . join
36
+ th . fetch ( :cat ) { true } . should == 'meow'
37
+ end
38
+
39
+ it "returns the block value if fiber-local variable hasn't been assigned" do
40
+ th = Thread . new { }
41
+ th . join
42
+ th . fetch ( :cat ) { true } . should == true
43
+ end
44
+
45
+ it "does not call the block if value has been assigned" do
46
+ th = Thread . new { Thread . current [ :cat ] = 'meow' }
47
+ th . join
48
+ var = :not_updated
49
+ th . fetch ( :cat ) { var = :updated } . should == 'meow'
50
+ var . should == :not_updated
51
+ end
52
+
53
+ it "uses the block if a default is given and warns about it" do
54
+ th = Thread . new { }
55
+ th . join
56
+ -> {
57
+ th . fetch ( :cat , false ) { true } . should == true
58
+ } . should complain ( /warning: block supersedes default value argument/ )
59
+ end
60
+ end
61
+
32
62
it 'raises an ArgumentError when not passed one or two arguments' do
33
63
-> { Thread . current . fetch ( ) } . should raise_error ( ArgumentError )
34
64
-> { Thread . current . fetch ( 1 , 2 , 3 ) } . should raise_error ( ArgumentError )
You can’t perform that action at this time.
0 commit comments