Skip to content

Commit b4a59b3

Browse files
committed
Added specs for OptionsParser#get_executor_from
1 parent be329e8 commit b4a59b3

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

lib/concurrent/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def finalize_executor(executor)
6868
module OptionsParser
6969

7070
def get_executor_from(opts = {})
71-
if opts.has_key?(:executor)
71+
if opts[:executor]
7272
opts[:executor]
7373
elsif opts[:operation] == true || opts[:task] == false
7474
Concurrent.configuration.global_operation_pool

spec/concurrent/configuration_spec.rb

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,72 @@ module Concurrent
1515

1616
describe OptionsParser do
1717

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
2084
end
2185
end
2286

0 commit comments

Comments
 (0)