transpec 0.2.6 → 1.0.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/.gitignore +1 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +10 -0
- data/README.md +111 -56
- data/README.md.erb +117 -62
- data/lib/transpec/ast/node.rb +41 -0
- data/lib/transpec/base_rewriter.rb +55 -0
- data/lib/transpec/cli.rb +43 -153
- data/lib/transpec/configuration.rb +13 -9
- data/lib/transpec/{rewriter.rb → converter.rb} +44 -71
- data/lib/transpec/dynamic_analyzer/rewriter.rb +94 -0
- data/lib/transpec/dynamic_analyzer/runtime_data.rb +27 -0
- data/lib/transpec/dynamic_analyzer.rb +166 -0
- data/lib/transpec/file_finder.rb +53 -0
- data/lib/transpec/option_parser.rb +166 -0
- data/lib/transpec/{context.rb → static_context_inspector.rb} +2 -2
- data/lib/transpec/syntax/be_close.rb +7 -9
- data/lib/transpec/syntax/double.rb +6 -10
- data/lib/transpec/syntax/expect.rb +35 -0
- data/lib/transpec/syntax/have.rb +195 -0
- data/lib/transpec/syntax/method_stub.rb +22 -27
- data/lib/transpec/syntax/mixin/allow_no_message.rb +73 -0
- data/lib/transpec/syntax/mixin/any_instance.rb +22 -0
- data/lib/transpec/syntax/mixin/expectizable.rb +26 -0
- data/lib/transpec/syntax/mixin/have_matcher.rb +23 -0
- data/lib/transpec/syntax/mixin/monkey_patch.rb +37 -0
- data/lib/transpec/syntax/mixin/send.rb +109 -0
- data/lib/transpec/syntax/{matcher.rb → operator_matcher.rb} +27 -14
- data/lib/transpec/syntax/raise_error.rb +6 -10
- data/lib/transpec/syntax/rspec_configure.rb +29 -28
- data/lib/transpec/syntax/should.rb +45 -15
- data/lib/transpec/syntax/should_receive.rb +44 -16
- data/lib/transpec/syntax.rb +29 -21
- data/lib/transpec/util.rb +12 -2
- data/lib/transpec/version.rb +3 -3
- data/spec/spec_helper.rb +8 -6
- data/spec/support/cache_helper.rb +50 -0
- data/spec/support/shared_context.rb +49 -1
- data/spec/transpec/ast/node_spec.rb +65 -0
- data/spec/transpec/cli_spec.rb +33 -242
- data/spec/transpec/commit_message_spec.rb +2 -2
- data/spec/transpec/configuration_spec.rb +12 -8
- data/spec/transpec/{rewriter_spec.rb → converter_spec.rb} +198 -148
- data/spec/transpec/dynamic_analyzer/rewriter_spec.rb +183 -0
- data/spec/transpec/dynamic_analyzer_spec.rb +164 -0
- data/spec/transpec/file_finder_spec.rb +118 -0
- data/spec/transpec/option_parser_spec.rb +185 -0
- data/spec/transpec/{context_spec.rb → static_context_inspector_spec.rb} +27 -12
- data/spec/transpec/syntax/be_close_spec.rb +8 -4
- data/spec/transpec/syntax/double_spec.rb +105 -12
- data/spec/transpec/syntax/expect_spec.rb +83 -0
- data/spec/transpec/syntax/have_spec.rb +599 -0
- data/spec/transpec/syntax/method_stub_spec.rb +276 -115
- data/spec/transpec/syntax/{matcher_spec.rb → operator_matcher_spec.rb} +277 -98
- data/spec/transpec/syntax/raise_error_spec.rb +92 -46
- data/spec/transpec/syntax/should_receive_spec.rb +298 -92
- data/spec/transpec/syntax/should_spec.rb +230 -44
- data/spec/transpec/util_spec.rb +2 -9
- data/tasks/lib/transpec_demo.rb +1 -1
- data/tasks/lib/transpec_test.rb +5 -7
- data/tasks/test.rake +5 -1
- data/transpec.gemspec +1 -1
- metadata +46 -22
- data/lib/transpec/syntax/able_to_allow_no_message.rb +0 -73
- data/lib/transpec/syntax/able_to_target_any_instance.rb +0 -24
- data/lib/transpec/syntax/expectizable.rb +0 -27
- data/lib/transpec/syntax/send_node_syntax.rb +0 -57
@@ -14,32 +14,35 @@ module Transpec
|
|
14
14
|
return ShouldReceive.new(
|
15
15
|
node,
|
16
16
|
ancestor_nodes,
|
17
|
-
source_rewriter
|
17
|
+
source_rewriter,
|
18
|
+
runtime_data
|
18
19
|
)
|
19
20
|
end
|
20
21
|
fail 'No should_receive node is found!'
|
21
22
|
end
|
22
23
|
|
23
|
-
let(:
|
24
|
+
let(:runtime_data) { nil }
|
24
25
|
|
25
|
-
|
26
|
-
should_receive_object.context.stub(:non_monkey_patch_mock_available?).and_return(true)
|
27
|
-
end
|
26
|
+
let(:record) { should_receive_object.report.records.first }
|
28
27
|
|
29
28
|
describe '#expectize!' do
|
30
29
|
context 'when it is `subject.should_receive(:method)` form' do
|
31
30
|
let(:source) do
|
32
31
|
<<-END
|
33
|
-
|
34
|
-
|
32
|
+
describe 'example' do
|
33
|
+
it 'receives #foo' do
|
34
|
+
subject.should_receive(:foo)
|
35
|
+
end
|
35
36
|
end
|
36
37
|
END
|
37
38
|
end
|
38
39
|
|
39
40
|
let(:expected_source) do
|
40
41
|
<<-END
|
41
|
-
|
42
|
-
|
42
|
+
describe 'example' do
|
43
|
+
it 'receives #foo' do
|
44
|
+
expect(subject).to receive(:foo)
|
45
|
+
end
|
43
46
|
end
|
44
47
|
END
|
45
48
|
end
|
@@ -54,21 +57,95 @@ module Transpec
|
|
54
57
|
record.original_syntax.should == 'obj.should_receive(:message)'
|
55
58
|
record.converted_syntax.should == 'expect(obj).to receive(:message)'
|
56
59
|
end
|
60
|
+
|
61
|
+
context 'and #expect and #receive are not available in the context' do
|
62
|
+
context 'and the context is determinable statically' do
|
63
|
+
let(:source) do
|
64
|
+
<<-END
|
65
|
+
describe 'example' do
|
66
|
+
class TestRunner
|
67
|
+
def run
|
68
|
+
something = 'something'
|
69
|
+
something.should_receive(:foo)
|
70
|
+
something.foo
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'receives #foo' do
|
75
|
+
TestRunner.new.run
|
76
|
+
end
|
77
|
+
end
|
78
|
+
END
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'with runtime information' do
|
82
|
+
include_context 'dynamic analysis objects'
|
83
|
+
|
84
|
+
it 'raises InvalidContextError' do
|
85
|
+
-> { should_receive_object.expectize! }.should raise_error(InvalidContextError)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'without runtime information' do
|
90
|
+
it 'raises InvalidContextError' do
|
91
|
+
-> { should_receive_object.expectize! }.should raise_error(InvalidContextError)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'and the context is not determinable statically' do
|
97
|
+
let(:source) do
|
98
|
+
<<-END
|
99
|
+
def my_eval(&block)
|
100
|
+
Object.new.instance_eval(&block)
|
101
|
+
end
|
102
|
+
|
103
|
+
describe 'example' do
|
104
|
+
it 'receives #foo' do
|
105
|
+
my_eval do
|
106
|
+
something = 'something'
|
107
|
+
something.should_receive(:foo)
|
108
|
+
something.foo
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
END
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'with runtime information' do
|
116
|
+
include_context 'dynamic analysis objects'
|
117
|
+
|
118
|
+
it 'raises InvalidContextError' do
|
119
|
+
-> { should_receive_object.expectize! }.should raise_error(InvalidContextError)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'without runtime information' do
|
124
|
+
it 'does not raise InvalidContextError' do
|
125
|
+
-> { should_receive_object.expectize! }.should_not raise_error
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
57
130
|
end
|
58
131
|
|
59
132
|
context 'when it is `subject.should_not_receive(:method)` form' do
|
60
133
|
let(:source) do
|
61
134
|
<<-END
|
62
|
-
|
63
|
-
|
135
|
+
describe 'example' do
|
136
|
+
it 'does not receive #foo' do
|
137
|
+
subject.should_not_receive(:foo)
|
138
|
+
end
|
64
139
|
end
|
65
140
|
END
|
66
141
|
end
|
67
142
|
|
68
143
|
let(:expected_source) do
|
69
144
|
<<-END
|
70
|
-
|
71
|
-
|
145
|
+
describe 'example' do
|
146
|
+
it 'does not receive #foo' do
|
147
|
+
expect(subject).not_to receive(:foo)
|
148
|
+
end
|
72
149
|
end
|
73
150
|
END
|
74
151
|
end
|
@@ -88,8 +165,10 @@ module Transpec
|
|
88
165
|
context 'and "to_not" is passed as negative form' do
|
89
166
|
let(:expected_source) do
|
90
167
|
<<-END
|
91
|
-
|
92
|
-
|
168
|
+
describe 'example' do
|
169
|
+
it 'does not receive #foo' do
|
170
|
+
expect(subject).to_not receive(:foo)
|
171
|
+
end
|
93
172
|
end
|
94
173
|
END
|
95
174
|
end
|
@@ -139,22 +218,26 @@ module Transpec
|
|
139
218
|
context 'when it is `subject.should_receive(:method).with do .. end` form' do
|
140
219
|
let(:source) do
|
141
220
|
<<-END
|
142
|
-
|
143
|
-
|
144
|
-
|
221
|
+
describe 'example' do
|
222
|
+
it 'receives #foo with 1' do
|
223
|
+
subject.should_receive(:foo).with do |arg|
|
224
|
+
arg == 1
|
225
|
+
end
|
226
|
+
subject.foo(1)
|
145
227
|
end
|
146
|
-
subject.foo(1)
|
147
228
|
end
|
148
229
|
END
|
149
230
|
end
|
150
231
|
|
151
232
|
let(:expected_source) do
|
152
233
|
<<-END
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
234
|
+
describe 'example' do
|
235
|
+
it 'receives #foo with 1' do
|
236
|
+
expect(subject).to receive(:foo).with { |arg|
|
237
|
+
arg == 1
|
238
|
+
}
|
239
|
+
subject.foo(1)
|
240
|
+
end
|
158
241
|
end
|
159
242
|
END
|
160
243
|
end
|
@@ -169,22 +252,26 @@ module Transpec
|
|
169
252
|
context 'when it is `subject.should_receive(:method).with(arg) do .. end` form' do
|
170
253
|
let(:source) do
|
171
254
|
<<-END
|
172
|
-
|
173
|
-
|
174
|
-
|
255
|
+
describe 'example' do
|
256
|
+
it 'receives #foo with 1' do
|
257
|
+
subject.should_receive(:foo).with(1) do |arg|
|
258
|
+
do_some_substitute_implementation
|
259
|
+
end
|
260
|
+
subject.foo(1)
|
175
261
|
end
|
176
|
-
subject.foo(1)
|
177
262
|
end
|
178
263
|
END
|
179
264
|
end
|
180
265
|
|
181
266
|
let(:expected_source) do
|
182
267
|
<<-END
|
183
|
-
|
184
|
-
|
185
|
-
|
268
|
+
describe 'example' do
|
269
|
+
it 'receives #foo with 1' do
|
270
|
+
expect(subject).to receive(:foo).with(1) do |arg|
|
271
|
+
do_some_substitute_implementation
|
272
|
+
end
|
273
|
+
subject.foo(1)
|
186
274
|
end
|
187
|
-
subject.foo(1)
|
188
275
|
end
|
189
276
|
END
|
190
277
|
end
|
@@ -226,22 +313,26 @@ module Transpec
|
|
226
313
|
context 'when it is `subject.should_receive(:method) do .. end.once` form' do
|
227
314
|
let(:source) do
|
228
315
|
<<-END
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
316
|
+
describe 'example' do
|
317
|
+
it 'receives #foo with 1' do
|
318
|
+
subject.should_receive(:foo) do |arg|
|
319
|
+
arg == 1
|
320
|
+
end.once
|
321
|
+
subject.foo(1)
|
322
|
+
end
|
234
323
|
end
|
235
324
|
END
|
236
325
|
end
|
237
326
|
|
238
327
|
let(:expected_source) do
|
239
328
|
<<-END
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
329
|
+
describe 'example' do
|
330
|
+
it 'receives #foo with 1' do
|
331
|
+
expect(subject).to receive(:foo) { |arg|
|
332
|
+
arg == 1
|
333
|
+
}.once
|
334
|
+
subject.foo(1)
|
335
|
+
end
|
245
336
|
end
|
246
337
|
END
|
247
338
|
end
|
@@ -256,22 +347,26 @@ module Transpec
|
|
256
347
|
context 'when it is `subject.should_receive(:method) do .. end` form' do
|
257
348
|
let(:source) do
|
258
349
|
<<-END
|
259
|
-
|
260
|
-
|
261
|
-
|
350
|
+
describe 'example' do
|
351
|
+
it 'receives #foo with 1' do
|
352
|
+
subject.should_receive(:foo) do |arg|
|
353
|
+
expect(arg).to eq(1)
|
354
|
+
end
|
355
|
+
subject.foo(1)
|
262
356
|
end
|
263
|
-
subject.foo(1)
|
264
357
|
end
|
265
358
|
END
|
266
359
|
end
|
267
360
|
|
268
361
|
let(:expected_source) do
|
269
362
|
<<-END
|
270
|
-
|
271
|
-
|
272
|
-
expect(
|
363
|
+
describe 'example' do
|
364
|
+
it 'receives #foo with 1' do
|
365
|
+
expect(subject).to receive(:foo) do |arg|
|
366
|
+
expect(arg).to eq(1)
|
367
|
+
end
|
368
|
+
subject.foo(1)
|
273
369
|
end
|
274
|
-
subject.foo(1)
|
275
370
|
end
|
276
371
|
END
|
277
372
|
end
|
@@ -285,16 +380,20 @@ module Transpec
|
|
285
380
|
context 'when it is `SomeClass.any_instance.should_receive(:method)` form' do
|
286
381
|
let(:source) do
|
287
382
|
<<-END
|
288
|
-
|
289
|
-
|
383
|
+
describe 'example' do
|
384
|
+
it 'receives #foo' do
|
385
|
+
SomeClass.any_instance.should_receive(:foo)
|
386
|
+
end
|
290
387
|
end
|
291
388
|
END
|
292
389
|
end
|
293
390
|
|
294
391
|
let(:expected_source) do
|
295
392
|
<<-END
|
296
|
-
|
297
|
-
|
393
|
+
describe 'example' do
|
394
|
+
it 'receives #foo' do
|
395
|
+
expect_any_instance_of(SomeClass).to receive(:foo)
|
396
|
+
end
|
298
397
|
end
|
299
398
|
END
|
300
399
|
end
|
@@ -319,8 +418,10 @@ module Transpec
|
|
319
418
|
context 'when it is `subject.should_receive(:method).any_number_of_times` form' do
|
320
419
|
let(:source) do
|
321
420
|
<<-END
|
322
|
-
|
323
|
-
|
421
|
+
describe 'example' do
|
422
|
+
it 'responds to #foo' do
|
423
|
+
subject.should_receive(:foo).any_number_of_times
|
424
|
+
end
|
324
425
|
end
|
325
426
|
END
|
326
427
|
end
|
@@ -331,8 +432,10 @@ module Transpec
|
|
331
432
|
context 'when it is `subject.should_receive(:method).with(arg).any_number_of_times` form' do
|
332
433
|
let(:source) do
|
333
434
|
<<-END
|
334
|
-
|
335
|
-
|
435
|
+
describe 'example' do
|
436
|
+
it 'responds to #foo with 1' do
|
437
|
+
subject.should_receive(:foo).with(1).any_number_of_times
|
438
|
+
end
|
336
439
|
end
|
337
440
|
END
|
338
441
|
end
|
@@ -343,8 +446,10 @@ module Transpec
|
|
343
446
|
context 'when it is `subject.should_receive(:method).at_least(0)` form' do
|
344
447
|
let(:source) do
|
345
448
|
<<-END
|
346
|
-
|
347
|
-
|
449
|
+
describe 'example' do
|
450
|
+
it 'responds to #foo' do
|
451
|
+
subject.should_receive(:foo).at_least(0)
|
452
|
+
end
|
348
453
|
end
|
349
454
|
END
|
350
455
|
end
|
@@ -355,8 +460,10 @@ module Transpec
|
|
355
460
|
context 'when it is `subject.should_receive(:method).at_least(1)` form' do
|
356
461
|
let(:source) do
|
357
462
|
<<-END
|
358
|
-
|
359
|
-
|
463
|
+
describe 'example' do
|
464
|
+
it 'receives #foo at least once' do
|
465
|
+
subject.should_receive(:foo).with(1).at_least(1)
|
466
|
+
end
|
360
467
|
end
|
361
468
|
END
|
362
469
|
end
|
@@ -367,8 +474,10 @@ module Transpec
|
|
367
474
|
context 'when it is `subject.should_receive(:method)` form' do
|
368
475
|
let(:source) do
|
369
476
|
<<-END
|
370
|
-
|
371
|
-
|
477
|
+
describe 'example' do
|
478
|
+
it 'receives to #foo' do
|
479
|
+
subject.should_receive(:foo)
|
480
|
+
end
|
372
481
|
end
|
373
482
|
END
|
374
483
|
end
|
@@ -378,61 +487,137 @@ module Transpec
|
|
378
487
|
end
|
379
488
|
|
380
489
|
describe '#allowize_useless_expectation!' do
|
381
|
-
before do
|
382
|
-
should_receive_object.allowize_useless_expectation!
|
383
|
-
end
|
384
|
-
|
385
490
|
context 'when it is `subject.should_receive(:method).any_number_of_times` form' do
|
386
491
|
let(:source) do
|
387
492
|
<<-END
|
388
|
-
|
389
|
-
|
493
|
+
describe 'example' do
|
494
|
+
it 'responds to #foo' do
|
495
|
+
subject.should_receive(:foo).any_number_of_times
|
496
|
+
end
|
390
497
|
end
|
391
498
|
END
|
392
499
|
end
|
393
500
|
|
394
501
|
let(:expected_source) do
|
395
502
|
<<-END
|
396
|
-
|
397
|
-
|
503
|
+
describe 'example' do
|
504
|
+
it 'responds to #foo' do
|
505
|
+
allow(subject).to receive(:foo)
|
506
|
+
end
|
398
507
|
end
|
399
508
|
END
|
400
509
|
end
|
401
510
|
|
402
511
|
it 'converts into `allow(subject).to receive(:method)` form' do
|
512
|
+
should_receive_object.allowize_useless_expectation!
|
403
513
|
rewritten_source.should == expected_source
|
404
514
|
end
|
405
515
|
|
406
516
|
it 'adds record ' +
|
407
517
|
'"`obj.should_receive(:message).any_number_of_times` -> `allow(obj).to receive(:message)`"' do
|
518
|
+
should_receive_object.allowize_useless_expectation!
|
408
519
|
record.original_syntax.should == 'obj.should_receive(:message).any_number_of_times'
|
409
520
|
record.converted_syntax.should == 'allow(obj).to receive(:message)'
|
410
521
|
end
|
522
|
+
|
523
|
+
context 'and #allow and #receive are not available in the context' do
|
524
|
+
context 'and the context is determinable statically' do
|
525
|
+
let(:source) do
|
526
|
+
<<-END
|
527
|
+
describe 'example' do
|
528
|
+
class TestRunner
|
529
|
+
def run
|
530
|
+
'something'.should_receive(:foo).any_number_of_times
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
it 'responds to #foo' do
|
535
|
+
TestRunner.new.run
|
536
|
+
end
|
537
|
+
end
|
538
|
+
END
|
539
|
+
end
|
540
|
+
|
541
|
+
context 'with runtime information' do
|
542
|
+
include_context 'dynamic analysis objects'
|
543
|
+
|
544
|
+
it 'raises InvalidContextError' do
|
545
|
+
-> { should_receive_object.allowize_useless_expectation! }
|
546
|
+
.should raise_error(InvalidContextError)
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
context 'without runtime information' do
|
551
|
+
it 'raises InvalidContextError' do
|
552
|
+
-> { should_receive_object.allowize_useless_expectation! }
|
553
|
+
.should raise_error(InvalidContextError)
|
554
|
+
end
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
context 'and the context is not determinable statically' do
|
559
|
+
let(:source) do
|
560
|
+
<<-END
|
561
|
+
def my_eval(&block)
|
562
|
+
Object.new.instance_eval(&block)
|
563
|
+
end
|
564
|
+
|
565
|
+
describe 'example' do
|
566
|
+
it 'responds to #foo' do
|
567
|
+
my_eval { 'something'.should_receive(:foo).any_number_of_times }
|
568
|
+
end
|
569
|
+
end
|
570
|
+
END
|
571
|
+
end
|
572
|
+
|
573
|
+
context 'with runtime information' do
|
574
|
+
include_context 'dynamic analysis objects'
|
575
|
+
|
576
|
+
it 'raises InvalidContextError' do
|
577
|
+
-> { should_receive_object.allowize_useless_expectation! }
|
578
|
+
.should raise_error(InvalidContextError)
|
579
|
+
end
|
580
|
+
end
|
581
|
+
|
582
|
+
context 'without runtime information' do
|
583
|
+
it 'does not raise InvalidContextError' do
|
584
|
+
-> { should_receive_object.allowize_useless_expectation! }
|
585
|
+
.should_not raise_error
|
586
|
+
end
|
587
|
+
end
|
588
|
+
end
|
589
|
+
end
|
411
590
|
end
|
412
591
|
|
413
592
|
context 'when it is `SomeClass.any_instance.should_receive(:method).any_number_of_times` form' do
|
414
593
|
let(:source) do
|
415
594
|
<<-END
|
416
|
-
|
417
|
-
|
595
|
+
describe 'example' do
|
596
|
+
it 'responds to #foo' do
|
597
|
+
SomeClass.any_instance.should_receive(:foo).any_number_of_times
|
598
|
+
end
|
418
599
|
end
|
419
600
|
END
|
420
601
|
end
|
421
602
|
|
422
603
|
let(:expected_source) do
|
423
604
|
<<-END
|
424
|
-
|
425
|
-
|
605
|
+
describe 'example' do
|
606
|
+
it 'responds to #foo' do
|
607
|
+
allow_any_instance_of(SomeClass).to receive(:foo)
|
608
|
+
end
|
426
609
|
end
|
427
610
|
END
|
428
611
|
end
|
429
612
|
|
430
613
|
it 'converts into `allow_any_instance_of(subject).to receive(:method)` form' do
|
614
|
+
should_receive_object.allowize_useless_expectation!
|
431
615
|
rewritten_source.should == expected_source
|
432
616
|
end
|
433
617
|
|
434
618
|
it 'adds record "`SomeClass.any_instance.should_receive(:message).any_number_of_times` ' +
|
435
619
|
'-> `allow_any_instance_of(SomeClass).to receive(:message)`"' do
|
620
|
+
should_receive_object.allowize_useless_expectation!
|
436
621
|
record.original_syntax.should == 'SomeClass.any_instance.should_receive(:message).any_number_of_times'
|
437
622
|
record.converted_syntax.should == 'allow_any_instance_of(SomeClass).to receive(:message)'
|
438
623
|
end
|
@@ -441,26 +626,32 @@ module Transpec
|
|
441
626
|
context 'when it is `subject.should_receive(:method).at_least(0)` form' do
|
442
627
|
let(:source) do
|
443
628
|
<<-END
|
444
|
-
|
445
|
-
|
629
|
+
describe 'example' do
|
630
|
+
it 'responds to #foo' do
|
631
|
+
subject.should_receive(:foo).at_least(0)
|
632
|
+
end
|
446
633
|
end
|
447
634
|
END
|
448
635
|
end
|
449
636
|
|
450
637
|
let(:expected_source) do
|
451
638
|
<<-END
|
452
|
-
|
453
|
-
|
639
|
+
describe 'example' do
|
640
|
+
it 'responds to #foo' do
|
641
|
+
allow(subject).to receive(:foo)
|
642
|
+
end
|
454
643
|
end
|
455
644
|
END
|
456
645
|
end
|
457
646
|
|
458
647
|
it 'converts into `allow(subject).to receive(:method)` form' do
|
648
|
+
should_receive_object.allowize_useless_expectation!
|
459
649
|
rewritten_source.should == expected_source
|
460
650
|
end
|
461
651
|
|
462
652
|
it 'adds record ' +
|
463
653
|
'"`obj.should_receive(:message).at_least(0)` -> `allow(obj).to receive(:message)`"' do
|
654
|
+
should_receive_object.allowize_useless_expectation!
|
464
655
|
record.original_syntax.should == 'obj.should_receive(:message).at_least(0)'
|
465
656
|
record.converted_syntax.should == 'allow(obj).to receive(:message)'
|
466
657
|
end
|
@@ -469,26 +660,32 @@ module Transpec
|
|
469
660
|
context 'when it is `SomeClass.any_instance.should_receive(:method).at_least(0)` form' do
|
470
661
|
let(:source) do
|
471
662
|
<<-END
|
472
|
-
|
473
|
-
|
663
|
+
describe 'example' do
|
664
|
+
it 'responds to #foo' do
|
665
|
+
SomeClass.any_instance.should_receive(:foo).at_least(0)
|
666
|
+
end
|
474
667
|
end
|
475
668
|
END
|
476
669
|
end
|
477
670
|
|
478
671
|
let(:expected_source) do
|
479
672
|
<<-END
|
480
|
-
|
481
|
-
|
673
|
+
describe 'example' do
|
674
|
+
it 'responds to #foo' do
|
675
|
+
allow_any_instance_of(SomeClass).to receive(:foo)
|
676
|
+
end
|
482
677
|
end
|
483
678
|
END
|
484
679
|
end
|
485
680
|
|
486
681
|
it 'converts into `allow_any_instance_of(subject).to receive(:method)` form' do
|
682
|
+
should_receive_object.allowize_useless_expectation!
|
487
683
|
rewritten_source.should == expected_source
|
488
684
|
end
|
489
685
|
|
490
686
|
it 'adds record "`SomeClass.any_instance.should_receive(:message).at_least(0)` ' +
|
491
687
|
'-> `allow_any_instance_of(SomeClass).to receive(:message)`"' do
|
688
|
+
should_receive_object.allowize_useless_expectation!
|
492
689
|
record.original_syntax.should == 'SomeClass.any_instance.should_receive(:message).at_least(0)'
|
493
690
|
record.converted_syntax.should == 'allow_any_instance_of(SomeClass).to receive(:message)'
|
494
691
|
end
|
@@ -497,13 +694,16 @@ module Transpec
|
|
497
694
|
context 'when it is `subject.should_receive(:method)` form' do
|
498
695
|
let(:source) do
|
499
696
|
<<-END
|
500
|
-
|
501
|
-
|
697
|
+
describe 'example' do
|
698
|
+
it 'receives to #foo' do
|
699
|
+
subject.should_receive(:foo)
|
700
|
+
end
|
502
701
|
end
|
503
702
|
END
|
504
703
|
end
|
505
704
|
|
506
705
|
it 'does nothing' do
|
706
|
+
should_receive_object.allowize_useless_expectation!
|
507
707
|
rewritten_source.should == source
|
508
708
|
end
|
509
709
|
end
|
@@ -517,16 +717,20 @@ module Transpec
|
|
517
717
|
context 'when it is `subject.should_receive(:method).any_number_of_times` form' do
|
518
718
|
let(:source) do
|
519
719
|
<<-END
|
520
|
-
|
521
|
-
|
720
|
+
describe 'example' do
|
721
|
+
it 'responds to #foo' do
|
722
|
+
subject.should_receive(:foo).any_number_of_times
|
723
|
+
end
|
522
724
|
end
|
523
725
|
END
|
524
726
|
end
|
525
727
|
|
526
728
|
let(:expected_source) do
|
527
729
|
<<-END
|
528
|
-
|
529
|
-
|
730
|
+
describe 'example' do
|
731
|
+
it 'responds to #foo' do
|
732
|
+
subject.stub(:foo)
|
733
|
+
end
|
530
734
|
end
|
531
735
|
END
|
532
736
|
end
|
@@ -545,8 +749,10 @@ module Transpec
|
|
545
749
|
context 'when it is `subject.should_receive(:method)` form' do
|
546
750
|
let(:source) do
|
547
751
|
<<-END
|
548
|
-
|
549
|
-
|
752
|
+
describe 'example' do
|
753
|
+
it 'receives to #foo' do
|
754
|
+
subject.should_receive(:foo)
|
755
|
+
end
|
550
756
|
end
|
551
757
|
END
|
552
758
|
end
|