-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfuture-resource_spec.rb
More file actions
85 lines (67 loc) · 2.02 KB
/
Copy pathfuture-resource_spec.rb
File metadata and controls
85 lines (67 loc) · 2.02 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require 'future-resource'
describe FutureResource do
it { should be_instance_of FutureResource }
it { should_not be_set_yet }
it { should_not be_terminated }
it "should set resource" do
subject.resource = :foo
end
it "should be terminateable" do
subject.terminate
end
describe "with a resource set" do
before { subject.resource = :foo }
it { should be_set_yet }
it { should_not be_terminated }
it "should have resource set" do
expect(subject.resource).to be :foo
end
it "should raise ResourceAlreadySetException when setting value that is already set" do
expect {
subject.resource = :bar
}.to raise_error FutureResource::ResourceAlreadySetException
end
it "should raise ResourceAlreadySetException when terminating" do
expect {
subject.terminate
}.to raise_error FutureResource::ResourceAlreadySetException
end
end
describe "that is terminated" do
before { subject.terminate }
it { should_not be_set_yet }
it { should be_terminated }
it "should raise a Terminated exception when getting the resource" do
expect {
subject.resource
}.to raise_error FutureResource::Terminated
end
it "should ignore any attempt to set the resource" do
subject.resource = :bar
expect {
subject.resource
}.to raise_error FutureResource::Terminated
end
it "should ignore any attempt to terminate again" do
subject.terminate
end
end
it "should receive the resource value from another thread" do
Thread.new do
sleep 1
subject.resource = :foo
end
expect(subject.resource).to be :foo
end
it "should raise on timeout" do
expect { subject.resource(0.5) }.to raise_error FutureResource::Timeout
end
it "should allow an alternative condition to be provided" do
resource = described_class.new(ConditionVariable.new)
Thread.new do
sleep 1
subject.resource = :foo
end
expect(subject.resource).to be :foo
end
end