diff options
Diffstat (limited to 'spec/ruby/core/thread/key_spec.rb')
| -rw-r--r-- | spec/ruby/core/thread/key_spec.rb | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/spec/ruby/core/thread/key_spec.rb b/spec/ruby/core/thread/key_spec.rb index d82a21ab39..a14aeb8d31 100644 --- a/spec/ruby/core/thread/key_spec.rb +++ b/spec/ruby/core/thread/key_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) +require_relative '../../spec_helper' +require_relative 'fixtures/classes' describe "Thread#key?" do before :each do @@ -16,31 +16,38 @@ describe "Thread#key?" do @th.key?(:stanley.to_s).should == false 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('oliver') + + @th.key?(key).should == true + end + it "raises exceptions on the wrong type of keys" do - lambda { Thread.current.key? nil }.should raise_error(TypeError) - lambda { Thread.current.key? 5 }.should raise_error(TypeError) + -> { Thread.current.key? nil }.should.raise(TypeError) + -> { Thread.current.key? 5 }.should.raise(TypeError) end it "is not shared across fibers" do fib = Fiber.new do Thread.current[:val1] = 1 Fiber.yield - Thread.current.key?(:val1).should be_true - Thread.current.key?(:val2).should be_false + Thread.current.key?(:val1).should == true + Thread.current.key?(:val2).should == false end - Thread.current.key?(:val1).should_not be_true + Thread.current.key?(:val1).should_not == true fib.resume Thread.current[:val2] = 2 fib.resume - Thread.current.key?(:val1).should be_false - Thread.current.key?(:val2).should be_true + Thread.current.key?(:val1).should == false + Thread.current.key?(:val2).should == true end it "stores a local in another thread when in a fiber" do fib = Fiber.new do t = Thread.new do sleep - Thread.current.key?(:value).should be_true + Thread.current.key?(:value).should == true end Thread.pass while t.status and t.status != "sleep" |
