File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 37
37
t2 [ "value" ] . should == 2
38
38
end
39
39
40
+ it "converts a key that is neither String nor Symbol with #to_str" do
41
+ key = mock ( 'value' )
42
+ key . should_receive ( :to_str ) . and_return ( 'value' )
43
+
44
+ th = Thread . new do
45
+ Thread . current [ :value ] = 1
46
+ end . join
47
+
48
+ th [ key ] . should == 1
49
+ end
50
+
40
51
it "raises exceptions on the wrong type of keys" do
41
52
-> { Thread . current [ nil ] } . should raise_error ( TypeError )
42
53
-> { Thread . current [ 5 ] } . should raise_error ( TypeError )
Original file line number Diff line number Diff line change 12
12
th . freeze
13
13
-> {
14
14
th [ :foo ] = "bar"
15
- } . should raise_error ( FrozenError , / frozen/ )
15
+ } . should raise_error ( FrozenError , "can't modify frozen thread locals" )
16
16
end . join
17
17
end
18
18
19
+ it "accepts Strings and Symbols" do
20
+ t1 = Thread . new do
21
+ Thread . current [ :value ] = 1
22
+ end . join
23
+ t2 = Thread . new do
24
+ Thread . current [ "value" ] = 2
25
+ end . join
26
+
27
+ t1 [ :value ] . should == 1
28
+ t2 [ :value ] . should == 2
29
+ end
30
+
31
+ it "converts a key that is neither String nor Symbol with #to_str" do
32
+ key = mock ( 'value' )
33
+ key . should_receive ( :to_str ) . and_return ( 'value' )
34
+
35
+ th = Thread . new do
36
+ Thread . current [ key ] = 1
37
+ end . join
38
+
39
+ th [ :value ] . should == 1
40
+ end
41
+
19
42
it "raises exceptions on the wrong type of keys" do
20
43
-> { Thread . current [ nil ] = true } . should raise_error ( TypeError )
21
44
-> { Thread . current [ 5 ] = true } . should raise_error ( TypeError )
Original file line number Diff line number Diff line change 16
16
@th . key? ( :stanley . to_s ) . should == false
17
17
end
18
18
19
+ it "converts a key that is neither String nor Symbol with #to_str" do
20
+ key = mock ( 'key' )
21
+ key . should_receive ( :to_str ) . and_return ( 'oliver' )
22
+
23
+ @th . key? ( key ) . should == true
24
+ end
25
+
19
26
it "raises exceptions on the wrong type of keys" do
20
27
-> { Thread . current . key? nil } . should raise_error ( TypeError )
21
28
-> { Thread . current . key? 5 } . should raise_error ( TypeError )
You can’t perform that action at this time.
0 commit comments