@@ -29,38 +29,20 @@ def with_block
29
29
end
30
30
31
31
subject do
32
- obj = async_class . create
32
+ obj = async_class . new
33
33
obj . executor = executor
34
34
obj
35
35
end
36
36
37
37
context 'object creation' do
38
38
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
46
40
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
48
42
async_class . new ( *args )
49
43
end
50
44
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
64
46
clazz = Class . new do
65
47
include Concurrent ::Async
66
48
attr_reader :args
@@ -69,11 +51,11 @@ def initialize(*args)
69
51
end
70
52
end
71
53
72
- object = clazz . create ( :foo , :bar )
54
+ object = clazz . new ( :foo , :bar )
73
55
expect ( object . args ) . to eq [ :foo , :bar ]
74
56
end
75
57
76
- specify '#create passes all args to the constructor' do
58
+ specify 'passes a given block to the original constructor' do
77
59
clazz = Class . new do
78
60
include Concurrent ::Async
79
61
attr_reader :block
@@ -82,9 +64,16 @@ def initialize(&block)
82
64
end
83
65
end
84
66
85
- object = clazz . create { 42 }
67
+ object = clazz . new { 42 }
86
68
expect ( object . block ) . to eq 42
87
69
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
88
77
end
89
78
90
79
context '#validate_argc' do
@@ -158,21 +147,21 @@ def many(*args, &block) nil; end
158
147
it 'returns the default executor when #executor= has never been called' do
159
148
expect ( Concurrent ) . to receive ( :global_io_executor ) .
160
149
and_return ( ImmediateExecutor . new )
161
- subject = async_class . create
150
+ subject = async_class . new
162
151
subject . async . echo ( :foo )
163
152
end
164
153
165
154
it 'returns the memo after #executor= has been called' do
166
155
executor = ImmediateExecutor . new
167
156
expect ( executor ) . to receive ( :post )
168
- subject = async_class . create
157
+ subject = async_class . new
169
158
subject . executor = executor
170
159
subject . async . echo ( :foo )
171
160
end
172
161
173
162
it 'raises an exception if #executor= is called after initialization complete' do
174
163
executor = ImmediateExecutor . new
175
- subject = async_class . create
164
+ subject = async_class . new
176
165
subject . async . echo ( :foo )
177
166
expect {
178
167
subject . executor = executor
@@ -209,7 +198,7 @@ def many(*args, &block) nil; end
209
198
it 'runs the future on the memoized executor' do
210
199
executor = ImmediateExecutor . new
211
200
expect ( executor ) . to receive ( :post ) . with ( any_args )
212
- subject = async_class . create
201
+ subject = async_class . new
213
202
subject . executor = executor
214
203
subject . async . echo ( :foo )
215
204
end
@@ -351,7 +340,7 @@ def gather(seconds, first, *rest)
351
340
( @bucket ||= [ ] ) . concat ( [ first ] )
352
341
@bucket . concat ( rest )
353
342
end
354
- } . create
343
+ } . new
355
344
356
345
object . async . gather ( 0.5 , :a , :b )
357
346
object . await . gather ( 0 , :c , :d )
0 commit comments