@@ -15,8 +15,72 @@ module Concurrent
15
15
16
16
describe OptionsParser do
17
17
18
- context 'get_executor_from' do
19
- pending
18
+ subject do
19
+ Class . new { include OptionsParser } . new
20
+ end
21
+
22
+ let ( :executor ) { ImmediateExecutor . new }
23
+
24
+ let ( :task_pool ) { ImmediateExecutor . new }
25
+ let ( :operation_pool ) { ImmediateExecutor . new }
26
+
27
+ context '#get_executor_from' do
28
+
29
+ it 'returns the given :executor' do
30
+ subject . get_executor_from ( executor : executor ) . should eq executor
31
+ end
32
+
33
+ it 'returns the global operation pool when :operation is true' do
34
+ Concurrent . configuration . should_receive ( :global_operation_pool ) .
35
+ and_return ( :operation_pool )
36
+ subject . get_executor_from ( operation : true )
37
+ end
38
+
39
+ it 'returns the global task pool when :operation is false' do
40
+ Concurrent . configuration . should_receive ( :global_task_pool ) .
41
+ and_return ( :task_pool )
42
+ subject . get_executor_from ( operation : false )
43
+ end
44
+
45
+ it 'returns the global operation pool when :task is false' do
46
+ Concurrent . configuration . should_receive ( :global_operation_pool ) .
47
+ and_return ( :operation_pool )
48
+ subject . get_executor_from ( task : false )
49
+ end
50
+
51
+ it 'returns the global task pool when :task is true' do
52
+ Concurrent . configuration . should_receive ( :global_task_pool ) .
53
+ and_return ( :task_pool )
54
+ subject . get_executor_from ( task : true )
55
+ end
56
+
57
+ it 'returns the global task pool when :executor is nil' do
58
+ Concurrent . configuration . should_receive ( :global_task_pool ) .
59
+ and_return ( :task_pool )
60
+ subject . get_executor_from ( executor : nil )
61
+ end
62
+
63
+ it 'returns the global task pool when no option is given' do
64
+ Concurrent . configuration . should_receive ( :global_task_pool ) .
65
+ and_return ( :task_pool )
66
+ subject . get_executor_from
67
+ end
68
+
69
+ specify ':executor overrides :operation' do
70
+ subject . get_executor_from ( executor : executor , operation : true ) .
71
+ should eq executor
72
+ end
73
+
74
+ specify ':executor overrides :task' do
75
+ subject . get_executor_from ( executor : executor , task : true ) .
76
+ should eq executor
77
+ end
78
+
79
+ specify ':operation overrides :task' do
80
+ Concurrent . configuration . should_receive ( :global_operation_pool ) .
81
+ and_return ( :operation_pool )
82
+ subject . get_executor_from ( operation : true , task : true )
83
+ end
20
84
end
21
85
end
22
86
0 commit comments