forked from cjbottaro/strand
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrand_spec.rb
51 lines (40 loc) · 1.45 KB
/
strand_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'spec_helper'
require 'strand/shared'
include EM::SpecHelper
describe Strand::EM::Thread do
let(:strand_type) { Strand::EM::Thread }
let(:strand_exception) { FiberError }
around(:each) do |example|
ScratchPad.clear
em do
example.run
done
end
end
it "should run examples within EventMachine" do
EM.reactor_running?.should be_true
Strand.event_machine?.should be_true
end
include_examples Strand
it "should pass resume and yield arguments like fiber" do
em do
s = Strand.new() do
# These yield args get swalled by the resume that
# automatically starts the Strand
Strand.yield(:y1).should == [ :r2,"r2" ]
#These yeild args should be visible by our resume call below
Strand.yield(:y2,"y2").should == [ "r3",:r3]
:the_end
end
s.resume(:r2,"r2").should == [ :y2, "y2" ]
# This is the end of the strand because there are no more yields
# should be the value of the block.
# Most apps should be calling value() here, rather than resume
s.resume("r3",:r3).should == :the_end
# the Strand is dead now, but should still have captured the value
s.value.should == :the_end
done
end
end
it "needs some tests to describe how raw fibers can be treated as strands"
end