Sha256: 138363b3037d6d69f007ff5f8bb80bb385a5ceec75eddda2308a20d3e085ff3a

Contents?: true

Size: 1.36 KB

Versions: 55

Compression:

Stored size: 1.36 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

describe "Thread#[]" do
  it "gives access to thread local values" do
    th = Thread.new do
      Thread.current[:value] = 5
    end
    th.join
    th[:value].should == 5
    Thread.current[:value].should == nil
  end

  it "is not shared across threads" do
    t1 = Thread.new do
      Thread.current[:value] = 1
    end
    t2 = Thread.new do
      Thread.current[:value] = 2
    end
    [t1,t2].each {|x| x.join}
    t1[:value].should == 1
    t2[:value].should == 2
  end

  it "is accessable using strings or symbols" do
    t1 = Thread.new do
      Thread.current[:value] = 1
    end
    t2 = Thread.new do
      Thread.current["value"] = 2
    end
    [t1,t2].each {|x| x.join}
    t1[:value].should == 1
    t1["value"].should == 1
    t2[:value].should == 2
    t2["value"].should == 2
  end

  ruby_version_is ""..."1.9" do
    it "raises exceptions on the wrong type of keys" do
      lambda { Thread.current[nil] }.should raise_error(TypeError)
      lambda { Thread.current[5] }.should raise_error(ArgumentError)
    end
  end

  ruby_version_is "1.9" do
    it "raises exceptions on the wrong type of keys" do
      lambda { Thread.current[nil] }.should raise_error(TypeError)
      lambda { Thread.current[5] }.should raise_error(TypeError)
    end
  end
end

Version data entries

55 entries across 55 versions & 3 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/thread/element_reference_spec.rb
empathy-0.1.0 rubyspec/core/thread/element_reference_spec.rb
empathy-0.0.1.RC2 rubyspec/core/thread/element_reference_spec.rb
empathy-0.0.1.RC0 rubyspec/core/thread/element_reference_spec.rb