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.
@@ -53,6 +53,43 @@ module Transpec
53
53
  record.converted_syntax.should == 'expect(obj).to receive(:message)'
54
54
  end
55
55
 
56
+ context 'when the statement continues over multi lines' do
57
+ let(:source) do
58
+ <<-END
59
+ describe 'example' do
60
+ it 'receives #foo and returns 1' do
61
+ subject.should_receive(
62
+ :foo
63
+ ).
64
+ and_return(
65
+ 1
66
+ )
67
+ end
68
+ end
69
+ END
70
+ end
71
+
72
+ let(:expected_source) do
73
+ <<-END
74
+ describe 'example' do
75
+ it 'receives #foo and returns 1' do
76
+ expect(subject).to receive(
77
+ :foo
78
+ ).
79
+ and_return(
80
+ 1
81
+ )
82
+ end
83
+ end
84
+ END
85
+ end
86
+
87
+ it 'keeps the style as far as possible' do
88
+ should_receive_object.expectize!
89
+ rewritten_source.should == expected_source
90
+ end
91
+ end
92
+
56
93
  context 'and #expect and #receive are not available in the context' do
57
94
  context 'and the context is determinable statically' do
58
95
  let(:source) do
@@ -372,12 +409,86 @@ module Transpec
372
409
  end
373
410
  end
374
411
 
375
- context 'when it is `SomeClass.any_instance.should_receive(:method)` form' do
412
+ context 'when it is `Klass.any_instance.should_receive(:method)` form' do
413
+ let(:source) do
414
+ <<-END
415
+ describe 'example' do
416
+ it 'receives #foo' do
417
+ Klass.any_instance.should_receive(:foo)
418
+ end
419
+ end
420
+ END
421
+ end
422
+
423
+ let(:expected_source) do
424
+ <<-END
425
+ describe 'example' do
426
+ it 'receives #foo' do
427
+ expect_any_instance_of(Klass).to receive(:foo)
428
+ end
429
+ end
430
+ END
431
+ end
432
+
433
+ it 'converts into `expect_any_instance_of(Klass).to receive(:method)` form' do
434
+ should_receive_object.expectize!
435
+ rewritten_source.should == expected_source
436
+ end
437
+
438
+ it 'adds record "`Klass.any_instance.should_receive(:message)` ' +
439
+ '-> `expect_any_instance_of(Klass).to receive(:message)`"' do
440
+ should_receive_object.expectize!
441
+ record.original_syntax.should == 'Klass.any_instance.should_receive(:message)'
442
+ record.converted_syntax.should == 'expect_any_instance_of(Klass).to receive(:message)'
443
+ end
444
+
445
+ context 'when the statement continues over multi lines' do
446
+ let(:source) do
447
+ <<-END
448
+ describe 'example' do
449
+ it 'receives #foo and returns 1' do
450
+ Klass
451
+ .any_instance
452
+ .should_receive(
453
+ :foo
454
+ ).
455
+ and_return(
456
+ 1
457
+ )
458
+ end
459
+ end
460
+ END
461
+ end
462
+
463
+ let(:expected_source) do
464
+ <<-END
465
+ describe 'example' do
466
+ it 'receives #foo and returns 1' do
467
+ expect_any_instance_of(Klass)
468
+ .to receive(
469
+ :foo
470
+ ).
471
+ and_return(
472
+ 1
473
+ )
474
+ end
475
+ end
476
+ END
477
+ end
478
+
479
+ it 'keeps the style as far as possible' do
480
+ should_receive_object.expectize!
481
+ rewritten_source.should == expected_source
482
+ end
483
+ end
484
+ end
485
+
486
+ context 'when it is `described_class.any_instance.should_receive(:method)` form' do
376
487
  let(:source) do
377
488
  <<-END
378
489
  describe 'example' do
379
490
  it 'receives #foo' do
380
- SomeClass.any_instance.should_receive(:foo)
491
+ described_class.any_instance.should_receive(:foo)
381
492
  end
382
493
  end
383
494
  END
@@ -387,22 +498,65 @@ module Transpec
387
498
  <<-END
388
499
  describe 'example' do
389
500
  it 'receives #foo' do
390
- expect_any_instance_of(SomeClass).to receive(:foo)
501
+ expect_any_instance_of(described_class).to receive(:foo)
391
502
  end
392
503
  end
393
504
  END
394
505
  end
395
506
 
396
- it 'converts into `expect_any_instance_of(SomeClass).to receive(:method)` form' do
507
+ it 'converts into `expect_any_instance_of(described_class).to receive(:method)` form' do
397
508
  should_receive_object.expectize!
398
509
  rewritten_source.should == expected_source
399
510
  end
400
511
 
401
- it 'adds record "`SomeClass.any_instance.should_receive(:message)` ' +
402
- '-> `expect_any_instance_of(SomeClass).to receive(:message)`"' do
512
+ it 'adds record "`Klass.any_instance.should_receive(:message)` ' +
513
+ '-> `expect_any_instance_of(Klass).to receive(:message)`"' do
403
514
  should_receive_object.expectize!
404
- record.original_syntax.should == 'SomeClass.any_instance.should_receive(:message)'
405
- record.converted_syntax.should == 'expect_any_instance_of(SomeClass).to receive(:message)'
515
+ record.original_syntax.should == 'Klass.any_instance.should_receive(:message)'
516
+ record.converted_syntax.should == 'expect_any_instance_of(Klass).to receive(:message)'
517
+ end
518
+ end
519
+
520
+ context 'when it is `variable.any_instance.should_receive(:method)` form ' +
521
+ 'and the variable is an AnyInstance::Recorder' do
522
+ context 'with runtime information' do
523
+ include_context 'dynamic analysis objects'
524
+
525
+ let(:source) do
526
+ <<-END
527
+ describe 'example' do
528
+ it 'receives #foo' do
529
+ variable = String.any_instance
530
+ variable.should_receive(:foo)
531
+ 'string'.foo
532
+ end
533
+ end
534
+ END
535
+ end
536
+
537
+ let(:expected_source) do
538
+ <<-END
539
+ describe 'example' do
540
+ it 'receives #foo' do
541
+ variable = String.any_instance
542
+ expect_any_instance_of(String).to receive(:foo)
543
+ 'string'.foo
544
+ end
545
+ end
546
+ END
547
+ end
548
+
549
+ it 'converts into `expect_any_instance_of(Klass).to receive(:method)` form' do
550
+ should_receive_object.expectize!
551
+ rewritten_source.should == expected_source
552
+ end
553
+
554
+ it 'adds record "`Klass.any_instance.should_receive(:message)` ' +
555
+ '-> `expect_any_instance_of(Klass).to receive(:message)`"' do
556
+ should_receive_object.expectize!
557
+ record.original_syntax.should == 'Klass.any_instance.should_receive(:message)'
558
+ record.converted_syntax.should == 'expect_any_instance_of(Klass).to receive(:message)'
559
+ end
406
560
  end
407
561
  end
408
562
  end
@@ -584,12 +738,46 @@ module Transpec
584
738
  end
585
739
  end
586
740
 
587
- context 'when it is `SomeClass.any_instance.should_receive(:method).any_number_of_times` form' do
741
+ context 'when it is `Klass.any_instance.should_receive(:method).any_number_of_times` form' do
742
+ let(:source) do
743
+ <<-END
744
+ describe 'example' do
745
+ it 'responds to #foo' do
746
+ Klass.any_instance.should_receive(:foo).any_number_of_times
747
+ end
748
+ end
749
+ END
750
+ end
751
+
752
+ let(:expected_source) do
753
+ <<-END
754
+ describe 'example' do
755
+ it 'responds to #foo' do
756
+ allow_any_instance_of(Klass).to receive(:foo)
757
+ end
758
+ end
759
+ END
760
+ end
761
+
762
+ it 'converts into `allow_any_instance_of(Klass).to receive(:method)` form' do
763
+ should_receive_object.allowize_useless_expectation!
764
+ rewritten_source.should == expected_source
765
+ end
766
+
767
+ it 'adds record "`Klass.any_instance.should_receive(:message).any_number_of_times` ' +
768
+ '-> `allow_any_instance_of(Klass).to receive(:message)`"' do
769
+ should_receive_object.allowize_useless_expectation!
770
+ record.original_syntax.should == 'Klass.any_instance.should_receive(:message).any_number_of_times'
771
+ record.converted_syntax.should == 'allow_any_instance_of(Klass).to receive(:message)'
772
+ end
773
+ end
774
+
775
+ context 'when it is `described_class.any_instance.should_receive(:method).any_number_of_times` form' do
588
776
  let(:source) do
589
777
  <<-END
590
778
  describe 'example' do
591
779
  it 'responds to #foo' do
592
- SomeClass.any_instance.should_receive(:foo).any_number_of_times
780
+ described_class.any_instance.should_receive(:foo).any_number_of_times
593
781
  end
594
782
  end
595
783
  END
@@ -599,22 +787,22 @@ module Transpec
599
787
  <<-END
600
788
  describe 'example' do
601
789
  it 'responds to #foo' do
602
- allow_any_instance_of(SomeClass).to receive(:foo)
790
+ allow_any_instance_of(described_class).to receive(:foo)
603
791
  end
604
792
  end
605
793
  END
606
794
  end
607
795
 
608
- it 'converts into `allow_any_instance_of(subject).to receive(:method)` form' do
796
+ it 'converts into `allow_any_instance_of(described_class).to receive(:method)` form' do
609
797
  should_receive_object.allowize_useless_expectation!
610
798
  rewritten_source.should == expected_source
611
799
  end
612
800
 
613
- it 'adds record "`SomeClass.any_instance.should_receive(:message).any_number_of_times` ' +
614
- '-> `allow_any_instance_of(SomeClass).to receive(:message)`"' do
801
+ it 'adds record "`Klass.any_instance.should_receive(:message).any_number_of_times` ' +
802
+ '-> `allow_any_instance_of(Klass).to receive(:message)`"' do
615
803
  should_receive_object.allowize_useless_expectation!
616
- record.original_syntax.should == 'SomeClass.any_instance.should_receive(:message).any_number_of_times'
617
- record.converted_syntax.should == 'allow_any_instance_of(SomeClass).to receive(:message)'
804
+ record.original_syntax.should == 'Klass.any_instance.should_receive(:message).any_number_of_times'
805
+ record.converted_syntax.should == 'allow_any_instance_of(Klass).to receive(:message)'
618
806
  end
619
807
  end
620
808
 
@@ -652,12 +840,12 @@ module Transpec
652
840
  end
653
841
  end
654
842
 
655
- context 'when it is `SomeClass.any_instance.should_receive(:method).at_least(0)` form' do
843
+ context 'when it is `Klass.any_instance.should_receive(:method).at_least(0)` form' do
656
844
  let(:source) do
657
845
  <<-END
658
846
  describe 'example' do
659
847
  it 'responds to #foo' do
660
- SomeClass.any_instance.should_receive(:foo).at_least(0)
848
+ Klass.any_instance.should_receive(:foo).at_least(0)
661
849
  end
662
850
  end
663
851
  END
@@ -667,22 +855,22 @@ module Transpec
667
855
  <<-END
668
856
  describe 'example' do
669
857
  it 'responds to #foo' do
670
- allow_any_instance_of(SomeClass).to receive(:foo)
858
+ allow_any_instance_of(Klass).to receive(:foo)
671
859
  end
672
860
  end
673
861
  END
674
862
  end
675
863
 
676
- it 'converts into `allow_any_instance_of(subject).to receive(:method)` form' do
864
+ it 'converts into `allow_any_instance_of(Klass).to receive(:method)` form' do
677
865
  should_receive_object.allowize_useless_expectation!
678
866
  rewritten_source.should == expected_source
679
867
  end
680
868
 
681
- it 'adds record "`SomeClass.any_instance.should_receive(:message).at_least(0)` ' +
682
- '-> `allow_any_instance_of(SomeClass).to receive(:message)`"' do
869
+ it 'adds record "`Klass.any_instance.should_receive(:message).at_least(0)` ' +
870
+ '-> `allow_any_instance_of(Klass).to receive(:message)`"' do
683
871
  should_receive_object.allowize_useless_expectation!
684
- record.original_syntax.should == 'SomeClass.any_instance.should_receive(:message).at_least(0)'
685
- record.converted_syntax.should == 'allow_any_instance_of(SomeClass).to receive(:message)'
872
+ record.original_syntax.should == 'Klass.any_instance.should_receive(:message).at_least(0)'
873
+ record.converted_syntax.should == 'allow_any_instance_of(Klass).to receive(:message)'
686
874
  end
687
875
  end
688
876
 
data/transpec.gemspec CHANGED
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'guard-rubocop', '~> 1.0'
33
33
  spec.add_development_dependency 'guard-shell', '~> 0.5'
34
34
  spec.add_development_dependency 'ruby_gntp', '~> 0.3'
35
+ spec.add_development_dependency 'activesupport', '~> 4.0'
35
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transpec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Nakayama
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ~>
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0.3'
167
+ - !ruby/object:Gem::Dependency
168
+ name: activesupport
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: '4.0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ~>
179
+ - !ruby/object:Gem::Version
180
+ version: '4.0'
167
181
  description: Transpec converts your specs into the latest RSpec syntax with static
168
182
  and dynamic code analysis.
169
183
  email: