Sha256: 5d360b48947191df253549908c89afb6013b9f846f978526e4c805bac2a14f64

Contents?: true

Size: 1.54 KB

Versions: 73

Compression:

Stored size: 1.54 KB

Contents

require 'thread'

# Our implementation of Thread only supports faux thread-local variables.
# Since we can't actually create a thread, nothing in rubyspec will run.
describe Thread do
  it "returns a value for current" do
    Thread.current.should_not be_nil
  end

  it "only has current in list" do
    Thread.list.should == [Thread.current]
  end

  it "does not allow creation of new threads" do
    lambda do
      Thread.new {}
    end.should raise_error(NotImplementedError)
  end

  describe "local storage" do
    before do
      @current = Thread.current
      @current.send(:core_initialize!)
    end

    it "stores fiber-local variables" do
      @current[:a] = 'hello'
      @current[:a].should == 'hello'
    end

    it "returns fiber-local keys that are assigned" do
      @current[:a] = 'hello'
      @current.key?(:a).should be_true
      @current.keys.should === ['a']
    end

    it "considers fiber-local keys, as symbols or strings equal" do
      @current[:a]  = 1
      @current['a'] = 2
      @current.keys.size.should == 1
      @current[:a].should == 2
    end

    it "implements thread-local variables" do
      @current.thread_variable_set('a', 1)
      @current.thread_variable_get('a').should == 1
      @current.thread_variables.should == ['a']
    end

    it "distinguishes between fiber-local and thread-local variables" do
      @current[:a] = 1
      @current.thread_variables.should == []

      @current.thread_variable_set(:a, 2)

      @current[:a].should == 1
      @current.thread_variable_get(:a).should == 2
    end
  end
end

Version data entries

73 entries across 73 versions & 3 rubygems

Version Path
opal-1.8.3.rc1 spec/opal/stdlib/thread/thread_spec.rb
opal-1.8.2 spec/opal/stdlib/thread/thread_spec.rb
opal-1.8.1 spec/opal/stdlib/thread/thread_spec.rb
opal-1.8.0 spec/opal/stdlib/thread/thread_spec.rb
opal-1.8.0.beta1 spec/opal/stdlib/thread/thread_spec.rb
opal-1.7.4 spec/opal/stdlib/thread/thread_spec.rb
opal-1.8.0.alpha1 spec/opal/stdlib/thread/thread_spec.rb
opal-1.7.3 spec/opal/stdlib/thread/thread_spec.rb
opal-1.7.2 spec/opal/stdlib/thread/thread_spec.rb
opal-1.7.1 spec/opal/stdlib/thread/thread_spec.rb
opal-1.7.0 spec/opal/stdlib/thread/thread_spec.rb
opal-1.7.0.rc1 spec/opal/stdlib/thread/thread_spec.rb
opal-1.6.1 spec/opal/stdlib/thread/thread_spec.rb
opal-1.6.0 spec/opal/stdlib/thread/thread_spec.rb
opal-1.6.0.rc1 spec/opal/stdlib/thread/thread_spec.rb
opal-1.6.0.alpha1 spec/opal/stdlib/thread/thread_spec.rb
opal-1.5.1 spec/opal/stdlib/thread/thread_spec.rb
opal-1.5.0 spec/opal/stdlib/thread/thread_spec.rb
opal-1.5.0.rc1 spec/opal/stdlib/thread/thread_spec.rb
opal-1.4.1 spec/opal/stdlib/thread/thread_spec.rb