transpec 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +36 -16
- data/README.md.erb +36 -16
- data/lib/transpec/option_parser.rb +1 -1
- data/lib/transpec/syntax/have.rb +126 -39
- data/lib/transpec/syntax/its.rb +15 -2
- data/lib/transpec/syntax/method_stub.rb +4 -4
- data/lib/transpec/syntax/mixin/any_instance.rb +43 -4
- data/lib/transpec/syntax/mixin/send.rb +4 -0
- data/lib/transpec/syntax/should_receive.rb +9 -9
- data/lib/transpec/version.rb +2 -2
- data/spec/transpec/cli_spec.rb +2 -2
- data/spec/transpec/converter_spec.rb +2 -2
- data/spec/transpec/static_context_inspector_spec.rb +5 -5
- data/spec/transpec/syntax/have_spec.rb +355 -0
- data/spec/transpec/syntax/its_spec.rb +49 -24
- data/spec/transpec/syntax/method_stub_spec.rb +467 -323
- data/spec/transpec/syntax/should_receive_spec.rb +212 -24
- data/transpec.gemspec +1 -0
- metadata +15 -1
@@ -106,137 +106,234 @@ module Transpec
|
|
106
106
|
end
|
107
107
|
|
108
108
|
describe '#allowize!' do
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
subject.#{method}(:foo)
|
116
|
-
end
|
109
|
+
context 'when it is `subject.stub(:method)` form' do
|
110
|
+
let(:source) do
|
111
|
+
<<-END
|
112
|
+
describe 'example' do
|
113
|
+
it 'responds to #foo' do
|
114
|
+
subject.stub(:foo)
|
117
115
|
end
|
118
|
-
|
119
|
-
|
116
|
+
end
|
117
|
+
END
|
118
|
+
end
|
120
119
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
120
|
+
let(:expected_source) do
|
121
|
+
<<-END
|
122
|
+
describe 'example' do
|
123
|
+
it 'responds to #foo' do
|
124
|
+
allow(subject).to receive(:foo)
|
127
125
|
end
|
128
|
-
|
129
|
-
|
126
|
+
end
|
127
|
+
END
|
128
|
+
end
|
130
129
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
130
|
+
it 'converts into `allow(subject).to receive(:method)` form' do
|
131
|
+
method_stub_object.allowize!
|
132
|
+
rewritten_source.should == expected_source
|
133
|
+
end
|
135
134
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
135
|
+
it "adds record \"`obj.stub(:message)` -> `allow(obj).to receive(:message)`\"" do
|
136
|
+
method_stub_object.allowize!
|
137
|
+
record.original_syntax.should == 'obj.stub(:message)'
|
138
|
+
record.converted_syntax.should == 'allow(obj).to receive(:message)'
|
139
|
+
end
|
141
140
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
end
|
141
|
+
context 'and #allow and #receive are not available in the context' do
|
142
|
+
context 'and the context is determinable statically' do
|
143
|
+
let(:source) do
|
144
|
+
<<-END
|
145
|
+
describe 'example' do
|
146
|
+
class TestRunner
|
147
|
+
def run
|
148
|
+
'something'.stub(:foo)
|
151
149
|
end
|
150
|
+
end
|
152
151
|
|
153
|
-
|
154
|
-
|
155
|
-
end
|
152
|
+
it 'responds to #foo' do
|
153
|
+
TestRunner.new.run
|
156
154
|
end
|
157
|
-
|
155
|
+
end
|
156
|
+
END
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'with runtime information' do
|
160
|
+
include_context 'dynamic analysis objects'
|
161
|
+
|
162
|
+
it 'raises InvalidContextError' do
|
163
|
+
-> { method_stub_object.allowize! }.should raise_error(InvalidContextError)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context 'without runtime information' do
|
168
|
+
it 'raises InvalidContextError' do
|
169
|
+
-> { method_stub_object.allowize! }.should raise_error(InvalidContextError)
|
158
170
|
end
|
171
|
+
end
|
172
|
+
end
|
159
173
|
|
160
|
-
|
161
|
-
|
174
|
+
context 'and the context is not determinable statically' do
|
175
|
+
let(:source) do
|
176
|
+
<<-END
|
177
|
+
def my_eval(&block)
|
178
|
+
Object.new.instance_eval(&block)
|
179
|
+
end
|
162
180
|
|
163
|
-
|
164
|
-
|
181
|
+
describe 'example' do
|
182
|
+
it 'responds to #foo' do
|
183
|
+
my_eval { 'something'.stub(:foo) }
|
184
|
+
end
|
165
185
|
end
|
186
|
+
END
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'with runtime information' do
|
190
|
+
include_context 'dynamic analysis objects'
|
191
|
+
|
192
|
+
it 'raises InvalidContextError' do
|
193
|
+
-> { method_stub_object.allowize! }.should raise_error(InvalidContextError)
|
166
194
|
end
|
195
|
+
end
|
167
196
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
end
|
197
|
+
context 'without runtime information' do
|
198
|
+
it 'does not raise InvalidContextError' do
|
199
|
+
-> { method_stub_object.allowize! }.should_not raise_error
|
172
200
|
end
|
173
201
|
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
174
205
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
206
|
+
context 'when it is `subject.stub!(:method)` form' do
|
207
|
+
let(:source) do
|
208
|
+
<<-END
|
209
|
+
describe 'example' do
|
210
|
+
it 'responds to #foo' do
|
211
|
+
subject.stub!(:foo)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
END
|
215
|
+
end
|
181
216
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
END
|
217
|
+
let(:expected_source) do
|
218
|
+
<<-END
|
219
|
+
describe 'example' do
|
220
|
+
it 'responds to #foo' do
|
221
|
+
allow(subject).to receive(:foo)
|
188
222
|
end
|
223
|
+
end
|
224
|
+
END
|
225
|
+
end
|
189
226
|
|
190
|
-
|
191
|
-
|
227
|
+
it 'converts into `allow(subject).to receive(:method)` form' do
|
228
|
+
method_stub_object.allowize!
|
229
|
+
rewritten_source.should == expected_source
|
230
|
+
end
|
192
231
|
|
193
|
-
|
194
|
-
|
195
|
-
|
232
|
+
it "adds record \"`obj.stub!(:message)` -> `allow(obj).to receive(:message)`\"" do
|
233
|
+
method_stub_object.allowize!
|
234
|
+
record.original_syntax.should == 'obj.stub!(:message)'
|
235
|
+
record.converted_syntax.should == 'allow(obj).to receive(:message)'
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context 'when it is `subject.stub(:method).and_return(value)` form' do
|
240
|
+
let(:source) do
|
241
|
+
<<-END
|
242
|
+
describe 'example' do
|
243
|
+
it 'responds to #foo and returns 1' do
|
244
|
+
subject.stub(:foo).and_return(1)
|
196
245
|
end
|
246
|
+
end
|
247
|
+
END
|
248
|
+
end
|
197
249
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
250
|
+
let(:expected_source) do
|
251
|
+
<<-END
|
252
|
+
describe 'example' do
|
253
|
+
it 'responds to #foo and returns 1' do
|
254
|
+
allow(subject).to receive(:foo).and_return(1)
|
202
255
|
end
|
203
256
|
end
|
204
|
-
|
257
|
+
END
|
205
258
|
end
|
206
259
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
260
|
+
it 'converts into `allow(subject).to receive(:method).and_return(value)` form' do
|
261
|
+
method_stub_object.allowize!
|
262
|
+
rewritten_source.should == expected_source
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
context 'when it is `subject.stub(:method).and_raise(RuntimeError)` form' do
|
267
|
+
let(:source) do
|
268
|
+
<<-END
|
269
|
+
describe 'example' do
|
270
|
+
it 'responds to #foo and raises RuntimeError' do
|
271
|
+
subject.stub(:foo).and_raise(RuntimeError)
|
214
272
|
end
|
215
|
-
|
216
|
-
|
273
|
+
end
|
274
|
+
END
|
275
|
+
end
|
217
276
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
end
|
277
|
+
let(:expected_source) do
|
278
|
+
<<-END
|
279
|
+
describe 'example' do
|
280
|
+
it 'responds to #foo and raises RuntimeError' do
|
281
|
+
allow(subject).to receive(:foo).and_raise(RuntimeError)
|
224
282
|
end
|
225
|
-
|
226
|
-
|
283
|
+
end
|
284
|
+
END
|
285
|
+
end
|
227
286
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
287
|
+
it 'converts into `allow(subject).to receive(:method).and_raise(RuntimeError)` form' do
|
288
|
+
method_stub_object.allowize!
|
289
|
+
rewritten_source.should == expected_source
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
context 'when the statement continues over multi lines' do
|
294
|
+
let(:source) do
|
295
|
+
<<-END
|
296
|
+
describe 'example' do
|
297
|
+
it 'responds to #foo and returns 1' do
|
298
|
+
subject.stub(
|
299
|
+
:foo
|
300
|
+
).
|
301
|
+
and_return(
|
302
|
+
1
|
303
|
+
)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
END
|
232
307
|
end
|
233
308
|
|
234
|
-
|
309
|
+
let(:expected_source) do
|
310
|
+
<<-END
|
311
|
+
describe 'example' do
|
312
|
+
it 'responds to #foo and returns 1' do
|
313
|
+
allow(subject).to receive(
|
314
|
+
:foo
|
315
|
+
).
|
316
|
+
and_return(
|
317
|
+
1
|
318
|
+
)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
END
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'keeps the style as far as possible' do
|
325
|
+
method_stub_object.allowize!
|
326
|
+
rewritten_source.should == expected_source
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
context 'when it is `subject.stub(:method => value)` form' do
|
331
|
+
context 'and #receive_messages is available' do
|
235
332
|
let(:source) do
|
236
333
|
<<-END
|
237
334
|
describe 'example' do
|
238
|
-
it 'responds to #foo and
|
239
|
-
subject
|
335
|
+
it 'responds to #foo and returns 1' do
|
336
|
+
subject.stub(:foo => 1)
|
240
337
|
end
|
241
338
|
end
|
242
339
|
END
|
@@ -245,30 +342,32 @@ module Transpec
|
|
245
342
|
let(:expected_source) do
|
246
343
|
<<-END
|
247
344
|
describe 'example' do
|
248
|
-
it 'responds to #foo and
|
249
|
-
allow(subject).to
|
345
|
+
it 'responds to #foo and returns 1' do
|
346
|
+
allow(subject).to receive_messages(:foo => 1)
|
250
347
|
end
|
251
348
|
end
|
252
349
|
END
|
253
350
|
end
|
254
351
|
|
255
|
-
it 'converts into `allow(subject).to
|
256
|
-
method_stub_object.allowize!
|
352
|
+
it 'converts into `allow(subject).to receive_messages(:method => value)` form' do
|
353
|
+
method_stub_object.allowize!(true)
|
257
354
|
rewritten_source.should == expected_source
|
258
355
|
end
|
356
|
+
|
357
|
+
it 'adds record ' +
|
358
|
+
"\"`obj.stub(:message => value)` -> `allow(obj).to receive_messages(:message => value)`\"" do
|
359
|
+
method_stub_object.allowize!(true)
|
360
|
+
record.original_syntax.should == 'obj.stub(:message => value)'
|
361
|
+
record.converted_syntax.should == 'allow(obj).to receive_messages(:message => value)'
|
362
|
+
end
|
259
363
|
end
|
260
364
|
|
261
|
-
context '
|
365
|
+
context 'and #receive_messages is not available' do
|
262
366
|
let(:source) do
|
263
367
|
<<-END
|
264
368
|
describe 'example' do
|
265
369
|
it 'responds to #foo and returns 1' do
|
266
|
-
subject
|
267
|
-
:foo
|
268
|
-
).
|
269
|
-
and_return(
|
270
|
-
1
|
271
|
-
)
|
370
|
+
subject.stub(:foo => 1)
|
272
371
|
end
|
273
372
|
end
|
274
373
|
END
|
@@ -278,30 +377,106 @@ module Transpec
|
|
278
377
|
<<-END
|
279
378
|
describe 'example' do
|
280
379
|
it 'responds to #foo and returns 1' do
|
281
|
-
allow(subject).to receive(
|
282
|
-
:foo
|
283
|
-
).
|
284
|
-
and_return(
|
285
|
-
1
|
286
|
-
)
|
380
|
+
allow(subject).to receive(:foo).and_return(1)
|
287
381
|
end
|
288
382
|
end
|
289
383
|
END
|
290
384
|
end
|
291
385
|
|
292
|
-
it '
|
386
|
+
it 'converts into `allow(subject).to receive(:method).and_return(value)` form' do
|
293
387
|
method_stub_object.allowize!
|
294
388
|
rewritten_source.should == expected_source
|
295
389
|
end
|
390
|
+
|
391
|
+
it 'adds record ' +
|
392
|
+
"\"`obj.stub(:message => value)` -> `allow(obj).to receive(:message).and_return(value)`\"" do
|
393
|
+
method_stub_object.allowize!
|
394
|
+
record.original_syntax.should == 'obj.stub(:message => value)'
|
395
|
+
record.converted_syntax.should == 'allow(obj).to receive(:message).and_return(value)'
|
396
|
+
end
|
296
397
|
end
|
398
|
+
end
|
297
399
|
|
298
|
-
|
400
|
+
context 'when it is `subject.stub(method: value)` form' do
|
401
|
+
let(:source) do
|
402
|
+
<<-END
|
403
|
+
describe 'example' do
|
404
|
+
it 'responds to #foo and returns 1' do
|
405
|
+
subject.stub(foo: 1)
|
406
|
+
end
|
407
|
+
end
|
408
|
+
END
|
409
|
+
end
|
410
|
+
|
411
|
+
let(:expected_source) do
|
412
|
+
<<-END
|
413
|
+
describe 'example' do
|
414
|
+
it 'responds to #foo and returns 1' do
|
415
|
+
allow(subject).to receive(:foo).and_return(1)
|
416
|
+
end
|
417
|
+
end
|
418
|
+
END
|
419
|
+
end
|
420
|
+
|
421
|
+
it 'converts into `allow(subject).to receive(:method).and_return(value)` form' do
|
422
|
+
method_stub_object.allowize!
|
423
|
+
rewritten_source.should == expected_source
|
424
|
+
end
|
425
|
+
|
426
|
+
it 'adds record ' +
|
427
|
+
"\"`obj.stub(:message => value)` -> `allow(obj).to receive(:message).and_return(value)`\"" do
|
428
|
+
method_stub_object.allowize!
|
429
|
+
record.original_syntax.should == 'obj.stub(:message => value)'
|
430
|
+
record.converted_syntax.should == 'allow(obj).to receive(:message).and_return(value)'
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
context 'when it is `subject.stub(:a_method => a_value, b_method => b_value)` form' do
|
435
|
+
let(:source) do
|
436
|
+
<<-END
|
437
|
+
describe 'example' do
|
438
|
+
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
439
|
+
subject.stub(:foo => 1, :bar => 2)
|
440
|
+
end
|
441
|
+
end
|
442
|
+
END
|
443
|
+
end
|
444
|
+
|
445
|
+
let(:expected_source) do
|
446
|
+
<<-END
|
447
|
+
describe 'example' do
|
448
|
+
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
449
|
+
allow(subject).to receive(:foo).and_return(1)
|
450
|
+
allow(subject).to receive(:bar).and_return(2)
|
451
|
+
end
|
452
|
+
end
|
453
|
+
END
|
454
|
+
end
|
455
|
+
|
456
|
+
it 'converts into `allow(subject).to receive(:a_method).and_return(a_value)` ' +
|
457
|
+
'and `allow(subject).to receive(:b_method).and_return(b_value)` form' do
|
458
|
+
method_stub_object.allowize!
|
459
|
+
rewritten_source.should == expected_source
|
460
|
+
end
|
461
|
+
|
462
|
+
it 'adds record ' +
|
463
|
+
"\"`obj.stub(:message => value)` -> `allow(obj).to receive(:message).and_return(value)`\"" do
|
464
|
+
method_stub_object.allowize!
|
465
|
+
record.original_syntax.should == 'obj.stub(:message => value)'
|
466
|
+
record.converted_syntax.should == 'allow(obj).to receive(:message).and_return(value)'
|
467
|
+
end
|
468
|
+
|
469
|
+
context 'when the statement continues over multi lines' do
|
299
470
|
context 'and #receive_messages is available' do
|
300
471
|
let(:source) do
|
301
472
|
<<-END
|
302
473
|
describe 'example' do
|
303
|
-
it 'responds to #foo and returns 1' do
|
304
|
-
subject
|
474
|
+
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
475
|
+
subject
|
476
|
+
.stub(
|
477
|
+
:foo => 1,
|
478
|
+
:bar => 2
|
479
|
+
)
|
305
480
|
end
|
306
481
|
end
|
307
482
|
END
|
@@ -310,32 +485,33 @@ module Transpec
|
|
310
485
|
let(:expected_source) do
|
311
486
|
<<-END
|
312
487
|
describe 'example' do
|
313
|
-
it 'responds to #foo and returns 1' do
|
314
|
-
allow(subject)
|
488
|
+
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
489
|
+
allow(subject)
|
490
|
+
.to receive_messages(
|
491
|
+
:foo => 1,
|
492
|
+
:bar => 2
|
493
|
+
)
|
315
494
|
end
|
316
495
|
end
|
317
496
|
END
|
318
497
|
end
|
319
498
|
|
320
|
-
it '
|
499
|
+
it 'keeps the style' do
|
321
500
|
method_stub_object.allowize!(true)
|
322
501
|
rewritten_source.should == expected_source
|
323
502
|
end
|
324
|
-
|
325
|
-
it 'adds record ' +
|
326
|
-
"\"`obj.#{method}(:message => value)` -> `allow(obj).to receive_messages(:message => value)`\"" do
|
327
|
-
method_stub_object.allowize!(true)
|
328
|
-
record.original_syntax.should == "obj.#{method}(:message => value)"
|
329
|
-
record.converted_syntax.should == 'allow(obj).to receive_messages(:message => value)'
|
330
|
-
end
|
331
503
|
end
|
332
504
|
|
333
505
|
context 'and #receive_messages is not available' do
|
334
506
|
let(:source) do
|
335
507
|
<<-END
|
336
508
|
describe 'example' do
|
337
|
-
it 'responds to #foo and returns 1' do
|
338
|
-
subject
|
509
|
+
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
510
|
+
subject
|
511
|
+
.stub(
|
512
|
+
:foo => 1,
|
513
|
+
:bar => 2
|
514
|
+
)
|
339
515
|
end
|
340
516
|
end
|
341
517
|
END
|
@@ -344,250 +520,218 @@ module Transpec
|
|
344
520
|
let(:expected_source) do
|
345
521
|
<<-END
|
346
522
|
describe 'example' do
|
347
|
-
it 'responds to #foo and returns 1' do
|
348
|
-
allow(subject)
|
523
|
+
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
524
|
+
allow(subject)
|
525
|
+
.to receive(:foo).and_return(1)
|
526
|
+
allow(subject)
|
527
|
+
.to receive(:bar).and_return(2)
|
349
528
|
end
|
350
529
|
end
|
351
530
|
END
|
352
531
|
end
|
353
532
|
|
354
|
-
it '
|
533
|
+
it 'keeps the style except around the hash' do
|
355
534
|
method_stub_object.allowize!
|
356
535
|
rewritten_source.should == expected_source
|
357
536
|
end
|
358
|
-
|
359
|
-
it 'adds record ' +
|
360
|
-
"\"`obj.#{method}(:message => value)` -> `allow(obj).to receive(:message).and_return(value)`\"" do
|
361
|
-
method_stub_object.allowize!
|
362
|
-
record.original_syntax.should == "obj.#{method}(:message => value)"
|
363
|
-
record.converted_syntax.should == 'allow(obj).to receive(:message).and_return(value)'
|
364
|
-
end
|
365
537
|
end
|
366
538
|
end
|
539
|
+
end
|
540
|
+
end
|
367
541
|
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
end
|
376
|
-
END
|
377
|
-
end
|
378
|
-
|
379
|
-
let(:expected_source) do
|
380
|
-
<<-END
|
381
|
-
describe 'example' do
|
382
|
-
it 'responds to #foo and returns 1' do
|
383
|
-
allow(subject).to receive(:foo).and_return(1)
|
384
|
-
end
|
542
|
+
[:unstub, :unstub!].each do |method|
|
543
|
+
context "when it is `subject.#{method}(:method)` form" do
|
544
|
+
let(:source) do
|
545
|
+
<<-END
|
546
|
+
describe 'example' do
|
547
|
+
it 'does not respond to #foo' do
|
548
|
+
subject.#{method}(:foo)
|
385
549
|
end
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
it 'converts into `allow(subject).to receive(:method).and_return(value)` form' do
|
390
|
-
method_stub_object.allowize!
|
391
|
-
rewritten_source.should == expected_source
|
392
|
-
end
|
550
|
+
end
|
551
|
+
END
|
552
|
+
end
|
393
553
|
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
record.original_syntax.should == "obj.#{method}(:message => value)"
|
398
|
-
record.converted_syntax.should == 'allow(obj).to receive(:message).and_return(value)'
|
399
|
-
end
|
554
|
+
it 'does nothing' do
|
555
|
+
method_stub_object.allowize!
|
556
|
+
rewritten_source.should == source
|
400
557
|
end
|
401
558
|
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
end
|
409
|
-
end
|
410
|
-
END
|
411
|
-
end
|
559
|
+
it 'reports nothing' do
|
560
|
+
method_stub_object.allowize!
|
561
|
+
method_stub_object.report.records.should be_empty
|
562
|
+
end
|
563
|
+
end
|
564
|
+
end
|
412
565
|
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
end
|
421
|
-
END
|
566
|
+
context 'when it is `Klass.any_instance.stub(:method)` form' do
|
567
|
+
let(:source) do
|
568
|
+
<<-END
|
569
|
+
describe 'example' do
|
570
|
+
it 'responds to #foo' do
|
571
|
+
Klass.any_instance.stub(:foo)
|
572
|
+
end
|
422
573
|
end
|
574
|
+
END
|
575
|
+
end
|
423
576
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
577
|
+
let(:expected_source) do
|
578
|
+
<<-END
|
579
|
+
describe 'example' do
|
580
|
+
it 'responds to #foo' do
|
581
|
+
allow_any_instance_of(Klass).to receive(:foo)
|
582
|
+
end
|
428
583
|
end
|
584
|
+
END
|
585
|
+
end
|
429
586
|
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
record.converted_syntax.should == 'allow(obj).to receive(:message).and_return(value)'
|
435
|
-
end
|
587
|
+
it 'converts into `allow_any_instance_of(Klass).to receive(:method)` form' do
|
588
|
+
method_stub_object.allowize!
|
589
|
+
rewritten_source.should == expected_source
|
590
|
+
end
|
436
591
|
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
subject
|
444
|
-
.#{method}(
|
445
|
-
:foo => 1,
|
446
|
-
:bar => 2
|
447
|
-
)
|
448
|
-
end
|
449
|
-
end
|
450
|
-
END
|
451
|
-
end
|
452
|
-
|
453
|
-
let(:expected_source) do
|
454
|
-
<<-END
|
455
|
-
describe 'example' do
|
456
|
-
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
457
|
-
allow(subject)
|
458
|
-
.to receive_messages(
|
459
|
-
:foo => 1,
|
460
|
-
:bar => 2
|
461
|
-
)
|
462
|
-
end
|
463
|
-
end
|
464
|
-
END
|
465
|
-
end
|
592
|
+
it "adds record \"`Klass.any_instance.stub(:message)` " +
|
593
|
+
'-> `allow_any_instance_of(obj).to receive(:message)`"' do
|
594
|
+
method_stub_object.allowize!
|
595
|
+
record.original_syntax.should == 'Klass.any_instance.stub(:message)'
|
596
|
+
record.converted_syntax.should == 'allow_any_instance_of(Klass).to receive(:message)'
|
597
|
+
end
|
466
598
|
|
467
|
-
|
468
|
-
|
469
|
-
|
599
|
+
context 'when the statement continues over multi lines' do
|
600
|
+
let(:source) do
|
601
|
+
<<-END
|
602
|
+
describe 'example' do
|
603
|
+
it 'responds to #foo and returns 1' do
|
604
|
+
Klass
|
605
|
+
.any_instance
|
606
|
+
.stub(
|
607
|
+
:foo
|
608
|
+
).
|
609
|
+
and_return(
|
610
|
+
1
|
611
|
+
)
|
470
612
|
end
|
471
613
|
end
|
614
|
+
END
|
615
|
+
end
|
472
616
|
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
end
|
485
|
-
END
|
617
|
+
let(:expected_source) do
|
618
|
+
<<-END
|
619
|
+
describe 'example' do
|
620
|
+
it 'responds to #foo and returns 1' do
|
621
|
+
allow_any_instance_of(Klass)
|
622
|
+
.to receive(
|
623
|
+
:foo
|
624
|
+
).
|
625
|
+
and_return(
|
626
|
+
1
|
627
|
+
)
|
486
628
|
end
|
629
|
+
end
|
630
|
+
END
|
631
|
+
end
|
487
632
|
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
allow(subject)
|
495
|
-
.to receive(:bar).and_return(2)
|
496
|
-
end
|
497
|
-
end
|
498
|
-
END
|
499
|
-
end
|
633
|
+
it 'keeps the style as far as possible' do
|
634
|
+
method_stub_object.allowize!
|
635
|
+
rewritten_source.should == expected_source
|
636
|
+
end
|
637
|
+
end
|
638
|
+
end
|
500
639
|
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
640
|
+
context 'when it is `described_class.any_instance.stub(:method)` form' do
|
641
|
+
let(:source) do
|
642
|
+
<<-END
|
643
|
+
describe 'example' do
|
644
|
+
it 'responds to #foo' do
|
645
|
+
described_class.any_instance.stub(:foo)
|
505
646
|
end
|
506
647
|
end
|
507
|
-
|
648
|
+
END
|
508
649
|
end
|
509
650
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
subject.#{method}(:foo)
|
517
|
-
end
|
518
|
-
end
|
519
|
-
END
|
651
|
+
let(:expected_source) do
|
652
|
+
<<-END
|
653
|
+
describe 'example' do
|
654
|
+
it 'responds to #foo' do
|
655
|
+
allow_any_instance_of(described_class).to receive(:foo)
|
656
|
+
end
|
520
657
|
end
|
658
|
+
END
|
659
|
+
end
|
521
660
|
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
661
|
+
it 'converts into `allow_any_instance_of(described_class).to receive(:method)` form' do
|
662
|
+
method_stub_object.allowize!
|
663
|
+
rewritten_source.should == expected_source
|
664
|
+
end
|
526
665
|
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
666
|
+
it "adds record \"`Klass.any_instance.stub(:message)` " +
|
667
|
+
'-> `allow_any_instance_of(obj).to receive(:message)`"' do
|
668
|
+
method_stub_object.allowize!
|
669
|
+
record.original_syntax.should == 'Klass.any_instance.stub(:message)'
|
670
|
+
record.converted_syntax.should == 'allow_any_instance_of(Klass).to receive(:message)'
|
532
671
|
end
|
672
|
+
end
|
533
673
|
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
674
|
+
context 'when it is `variable.any_instance.stub(:method)` form ' +
|
675
|
+
'and the variable is an AnyInstance::Recorder' do
|
676
|
+
context 'with runtime information' do
|
677
|
+
include_context 'dynamic analysis objects'
|
678
|
+
|
679
|
+
let(:source) do
|
680
|
+
<<-END
|
681
|
+
describe 'example' do
|
682
|
+
it 'responds to #foo' do
|
683
|
+
variable = String.any_instance
|
684
|
+
variable.stub(:foo)
|
542
685
|
end
|
543
|
-
|
544
|
-
|
686
|
+
end
|
687
|
+
END
|
688
|
+
end
|
545
689
|
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
690
|
+
let(:expected_source) do
|
691
|
+
<<-END
|
692
|
+
describe 'example' do
|
693
|
+
it 'responds to #foo' do
|
694
|
+
variable = String.any_instance
|
695
|
+
allow_any_instance_of(String).to receive(:foo)
|
552
696
|
end
|
553
|
-
|
554
|
-
|
697
|
+
end
|
698
|
+
END
|
699
|
+
end
|
555
700
|
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
701
|
+
it 'converts into `allow_any_instance_of(Klass).to receive(:method)` form' do
|
702
|
+
method_stub_object.allowize!
|
703
|
+
rewritten_source.should == expected_source
|
704
|
+
end
|
560
705
|
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
end
|
706
|
+
it "adds record \"`Klass.any_instance.stub(:message)` " +
|
707
|
+
'-> `allow_any_instance_of(obj).to receive(:message)`"' do
|
708
|
+
method_stub_object.allowize!
|
709
|
+
record.original_syntax.should == 'Klass.any_instance.stub(:message)'
|
710
|
+
record.converted_syntax.should == 'allow_any_instance_of(Klass).to receive(:message)'
|
567
711
|
end
|
568
712
|
end
|
713
|
+
end
|
569
714
|
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
end
|
715
|
+
[:unstub, :unstub!].each do |method|
|
716
|
+
context "when it is `Klass.any_instance.#{method}(:method)` form" do
|
717
|
+
let(:source) do
|
718
|
+
<<-END
|
719
|
+
describe 'example' do
|
720
|
+
it 'does not respond to #foo' do
|
721
|
+
Klass.any_instance.#{method}(:foo)
|
578
722
|
end
|
579
|
-
|
580
|
-
|
723
|
+
end
|
724
|
+
END
|
725
|
+
end
|
581
726
|
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
727
|
+
it 'does nothing' do
|
728
|
+
method_stub_object.allowize!
|
729
|
+
rewritten_source.should == source
|
730
|
+
end
|
586
731
|
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
end
|
732
|
+
it 'reports nothing' do
|
733
|
+
method_stub_object.allowize!
|
734
|
+
method_stub_object.report.records.should be_empty
|
591
735
|
end
|
592
736
|
end
|
593
737
|
end
|