summaryrefslogtreecommitdiff
path: root/spec/ruby/core/threadgroup/enclose_spec.rb
blob: dd9a7a362da54c80b8b60e19b3ae91b6961d70c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require_relative '../../spec_helper'

describe "ThreadGroup#enclose" do
  before :each do
    @q1, @q2 = Queue.new, Queue.new
    @thread = Thread.new { @q1 << :go; @q2.pop }
    @q1.pop
  end

  after :each do
    @q2 << :done
    @thread.join
  end

  it "raises a ThreadError if attempting to move a Thread from an enclosed ThreadGroup" do
    thread_group = ThreadGroup.new
    default_group = @thread.group
    thread_group.add(@thread)
    thread_group.enclose
    -> do
      default_group.add(@thread)
    end.should raise_error(ThreadError)
  end
end