@@ -29,38 +29,20 @@ def with_block
2929 end
3030
3131 subject do
32- obj = async_class . create
32+ obj = async_class . new
3333 obj . executor = executor
3434 obj
3535 end
3636
3737 context 'object creation' do
3838
39- # Will be added in 1.0 once deprecated methods are removed
40- #it 'makes #new private' do
41- # expect{ async_class.new }.to raise_error(NoMethodError)
42- #end
43-
44- # Will be removed in 1.0 once deprecated methods are removed
45- it '#new delegates to #create' do
39+ it 'delegates to the original constructor' do
4640 args = [ :foo , 'bar' , 42 ]
47- expect ( async_class ) . to receive ( :create ) . once . with ( *args )
41+ expect ( async_class ) . to receive ( :original_new ) . once . with ( *args ) . and_call_original
4842 async_class . new ( *args )
4943 end
5044
51- it 'uses #create to instanciate new objects' do
52- object = async_class . create
53- expect ( object ) . to be_a async_class
54- end
55-
56- specify '#create initializes synchronization' do
57- mock = async_class . create
58- allow ( async_class ) . to receive ( :original_new ) . and_return ( mock )
59- expect ( mock ) . to receive ( :init_synchronization ) . once . with ( no_args )
60- async_class . create
61- end
62-
63- specify '#create passes all args to the constructor' do
45+ specify 'passes all args to the original constructor' do
6446 clazz = Class . new do
6547 include Concurrent ::Async
6648 attr_reader :args
@@ -69,11 +51,11 @@ def initialize(*args)
6951 end
7052 end
7153
72- object = clazz . create ( :foo , :bar )
54+ object = clazz . new ( :foo , :bar )
7355 expect ( object . args ) . to eq [ :foo , :bar ]
7456 end
7557
76- specify '#create passes all args to the constructor' do
58+ specify 'passes a given block to the original constructor' do
7759 clazz = Class . new do
7860 include Concurrent ::Async
7961 attr_reader :block
@@ -82,9 +64,16 @@ def initialize(&block)
8264 end
8365 end
8466
85- object = clazz . create { 42 }
67+ object = clazz . new { 42 }
8668 expect ( object . block ) . to eq 42
8769 end
70+
71+ specify 'initializes synchronization' do
72+ mock = async_class . new
73+ allow ( async_class ) . to receive ( :original_new ) . and_return ( mock )
74+ expect ( mock ) . to receive ( :init_synchronization ) . once . with ( no_args )
75+ async_class . new
76+ end
8877 end
8978
9079 context '#validate_argc' do
@@ -158,21 +147,21 @@ def many(*args, &block) nil; end
158147 it 'returns the default executor when #executor= has never been called' do
159148 expect ( Concurrent ) . to receive ( :global_io_executor ) .
160149 and_return ( ImmediateExecutor . new )
161- subject = async_class . create
150+ subject = async_class . new
162151 subject . async . echo ( :foo )
163152 end
164153
165154 it 'returns the memo after #executor= has been called' do
166155 executor = ImmediateExecutor . new
167156 expect ( executor ) . to receive ( :post )
168- subject = async_class . create
157+ subject = async_class . new
169158 subject . executor = executor
170159 subject . async . echo ( :foo )
171160 end
172161
173162 it 'raises an exception if #executor= is called after initialization complete' do
174163 executor = ImmediateExecutor . new
175- subject = async_class . create
164+ subject = async_class . new
176165 subject . async . echo ( :foo )
177166 expect {
178167 subject . executor = executor
@@ -209,7 +198,7 @@ def many(*args, &block) nil; end
209198 it 'runs the future on the memoized executor' do
210199 executor = ImmediateExecutor . new
211200 expect ( executor ) . to receive ( :post ) . with ( any_args )
212- subject = async_class . create
201+ subject = async_class . new
213202 subject . executor = executor
214203 subject . async . echo ( :foo )
215204 end
@@ -351,7 +340,7 @@ def gather(seconds, first, *rest)
351340 ( @bucket ||= [ ] ) . concat ( [ first ] )
352341 @bucket . concat ( rest )
353342 end
354- } . create
343+ } . new
355344
356345 object . async . gather ( 0.5 , :a , :b )
357346 object . await . gather ( 0 , :c , :d )
0 commit comments