transpec 1.8.0 → 1.9.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/.rubocop.yml +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG.md +6 -0
- data/README.md +106 -79
- data/README.md.erb +91 -73
- data/lib/transpec/cli.rb +1 -1
- data/lib/transpec/converter.rb +16 -5
- data/lib/transpec/syntax/allow.rb +4 -0
- data/lib/transpec/syntax/expect.rb +4 -0
- data/lib/transpec/syntax/have.rb +24 -13
- data/lib/transpec/syntax/method_stub.rb +42 -6
- data/lib/transpec/syntax/mixin/any_instance_block.rb +14 -5
- data/lib/transpec/syntax/mixin/expect_base.rb +6 -5
- data/lib/transpec/syntax/mixin/messaging_host.rb +17 -0
- data/lib/transpec/syntax/mixin/{allow_no_message.rb → no_message_allowance.rb} +5 -4
- data/lib/transpec/syntax/mixin/send.rb +0 -13
- data/lib/transpec/syntax/mixin/should_base.rb +7 -1
- data/lib/transpec/syntax/mixin/useless_and_return.rb +79 -0
- data/lib/transpec/syntax/operator_matcher.rb +20 -4
- data/lib/transpec/syntax/receive.rb +21 -6
- data/lib/transpec/syntax/should_receive.rb +14 -11
- data/lib/transpec/util.rb +46 -0
- data/lib/transpec/version.rb +1 -1
- data/spec/transpec/converter_spec.rb +60 -18
- data/spec/transpec/syntax/expect_spec.rb +41 -9
- data/spec/transpec/syntax/method_stub_spec.rb +99 -2
- data/spec/transpec/syntax/operator_matcher_spec.rb +19 -84
- data/spec/transpec/syntax/receive_spec.rb +231 -2
- data/spec/transpec/syntax/should_receive_spec.rb +38 -0
- data/spec/transpec/syntax/should_spec.rb +28 -39
- data/tasks/readme.rake +16 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa52c57bc733f1dfe6a1c635a6338bd54cc39c0d
|
4
|
+
data.tar.gz: 54c31463aff3d7f8a0f52588da49914a4cb597d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af49f12b94003b1b14f426044d349c03d76c53a8ca78470e75765e1e15f1a1b3c431d2a5c64a0fae7329a74053d80759a0ada4c9282b251eac112a85bd71cdf9
|
7
|
+
data.tar.gz: 9c160cd00df22d3a0f0f52c1318ca10ebafd3b1fe6b8ddf4d4215a71121fd6448edba07ba649945d0e0aad187b7addb35760d7f4a714320f5cb706cf1ff38429
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## Development
|
4
4
|
|
5
|
+
## v1.9.0
|
6
|
+
|
7
|
+
* Support conversion of `and_return { value }` and `and_return` without arguments
|
8
|
+
* Fix a bug where conversion of `.any_number_of_times` and `at_least(0)` with `obj.stub(:message)` weren't reported in the final summary
|
9
|
+
* Fix a bug where arguments of `any_instance` implementation blocks weren't converted when a `receive` matcher was chained by the fluent interface (e.g. `expect_any_instance_of(Klass).to receive(:message).once { |arg| }`)
|
10
|
+
|
5
11
|
## v1.8.0
|
6
12
|
|
7
13
|
* Conversion of `obj.stub(:message => value)` to `allow(obj).to receive(:message).and_return(value)` is now opt-in with `-t/--convert-stub-with-hash` option when `receive_messages` is unavailable
|
data/README.md
CHANGED
@@ -416,6 +416,7 @@ The one-liner (implicit receiver) `should`:
|
|
416
416
|
* [`have(n).items` matcher](#havenitems-matcher)
|
417
417
|
* [One-liner expectations with `have(n).items` matcher](#one-liner-expectations-with-havenitems-matcher)
|
418
418
|
* [Expectations on block](#expectations-on-block)
|
419
|
+
* [Expectations on attribute of subject with `its`](#expectations-on-attribute-of-subject-with-its)
|
419
420
|
* [Negative error expectations with specific error](#negative-error-expectations-with-specific-error)
|
420
421
|
* [Message expectations](#message-expectations)
|
421
422
|
* [Message expectations that are actually method stubs](#message-expectations-that-are-actually-method-stubs)
|
@@ -423,9 +424,9 @@ The one-liner (implicit receiver) `should`:
|
|
423
424
|
* [Method stubs with a hash argument](#method-stubs-with-a-hash-argument)
|
424
425
|
* [Deprecated method stub aliases](#deprecated-method-stub-aliases)
|
425
426
|
* [Method stubs with deprecated specification of number of times](#method-stubs-with-deprecated-specification-of-number-of-times)
|
427
|
+
* [Useless `and_return`](#useless-and_return)
|
426
428
|
* [`any_instance` implementation blocks](#any_instance-implementation-blocks)
|
427
429
|
* [Deprecated test double aliases](#deprecated-test-double-aliases)
|
428
|
-
* [Expectations on attribute of subject with `its`](#expectations-on-attribute-of-subject-with-its)
|
429
430
|
* [Current example object](#current-example-object)
|
430
431
|
* [Custom matcher DSL](#custom-matcher-dsl)
|
431
432
|
|
@@ -661,6 +662,59 @@ expect { do_something }.to raise_error
|
|
661
662
|
* Deprecation: deprecated since RSpec 3.0
|
662
663
|
* See also: [Unification of Block vs. Value Syntaxes - RSpec's New Expectation Syntax](http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax#unification_of_block_vs_value_syntaxes)
|
663
664
|
|
665
|
+
### Expectations on attribute of subject with `its`
|
666
|
+
|
667
|
+
**This conversion will be disabled automatically if `rspec-its` is loaded in your spec.**
|
668
|
+
|
669
|
+
Targets:
|
670
|
+
|
671
|
+
```ruby
|
672
|
+
describe 'example' do
|
673
|
+
subject { { foo: 1, bar: 2 } }
|
674
|
+
its(:size) { should == 2 }
|
675
|
+
its([:foo]) { should == 1 }
|
676
|
+
its('keys.first') { should == :foo }
|
677
|
+
end
|
678
|
+
```
|
679
|
+
|
680
|
+
Will be converted to:
|
681
|
+
|
682
|
+
```ruby
|
683
|
+
describe 'example' do
|
684
|
+
subject { { foo: 1, bar: 2 } }
|
685
|
+
|
686
|
+
describe '#size' do
|
687
|
+
subject { super().size }
|
688
|
+
it { should == 2 }
|
689
|
+
end
|
690
|
+
|
691
|
+
describe '[:foo]' do
|
692
|
+
subject { super()[:foo] }
|
693
|
+
it { should == 1 }
|
694
|
+
end
|
695
|
+
|
696
|
+
describe '#keys' do
|
697
|
+
subject { super().keys }
|
698
|
+
describe '#first' do
|
699
|
+
subject { super().first }
|
700
|
+
it { should == :foo }
|
701
|
+
end
|
702
|
+
end
|
703
|
+
end
|
704
|
+
```
|
705
|
+
|
706
|
+
There's an option to continue using `its` with [rspec-its](https://github.com/rspec/rspec-its) which is a gem extracted from `rspec-core`.
|
707
|
+
If you choose to do so, disable this conversion by either:
|
708
|
+
|
709
|
+
* Specify `--keep its` option manually.
|
710
|
+
* Require `rspec-its` in your spec so that Transpec automatically disables this conversion.
|
711
|
+
|
712
|
+
---
|
713
|
+
|
714
|
+
* This conversion can be disabled by: `--keep its`
|
715
|
+
* Deprecation: deprecated since RSpec 2.99, removed in RSpec 3.0
|
716
|
+
* See also: [Core: `its` will be moved into an external gem - The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#core__will_be_moved_into_an_external_gem)
|
717
|
+
|
664
718
|
### Negative error expectations with specific error
|
665
719
|
|
666
720
|
Targets:
|
@@ -688,15 +742,15 @@ lambda { do_something }.should_not raise_error # with `--keep should`
|
|
688
742
|
Targets:
|
689
743
|
|
690
744
|
```ruby
|
691
|
-
obj.should_receive(:
|
692
|
-
Klass.any_instance.should_receive(:
|
745
|
+
obj.should_receive(:message)
|
746
|
+
Klass.any_instance.should_receive(:message)
|
693
747
|
```
|
694
748
|
|
695
749
|
Will be converted to:
|
696
750
|
|
697
751
|
```ruby
|
698
|
-
expect(obj).to receive(:
|
699
|
-
expect_any_instance_of(Klass).to receive(:
|
752
|
+
expect(obj).to receive(:message)
|
753
|
+
expect_any_instance_of(Klass).to receive(:message)
|
700
754
|
```
|
701
755
|
|
702
756
|
* This conversion can be disabled by: `--keep should_receive`
|
@@ -708,21 +762,21 @@ expect_any_instance_of(Klass).to receive(:foo)
|
|
708
762
|
Targets:
|
709
763
|
|
710
764
|
```ruby
|
711
|
-
obj.should_receive(:
|
712
|
-
obj.should_receive(:
|
765
|
+
obj.should_receive(:message).any_number_of_times
|
766
|
+
obj.should_receive(:message).at_least(0)
|
713
767
|
|
714
|
-
Klass.any_instance.should_receive(:
|
715
|
-
Klass.any_instance.should_receive(:
|
768
|
+
Klass.any_instance.should_receive(:message).any_number_of_times
|
769
|
+
Klass.any_instance.should_receive(:message).at_least(0)
|
716
770
|
```
|
717
771
|
|
718
772
|
Will be converted to:
|
719
773
|
|
720
774
|
```ruby
|
721
|
-
allow(obj).to receive(:
|
722
|
-
obj.stub(:
|
775
|
+
allow(obj).to receive(:message)
|
776
|
+
obj.stub(:message) # with `--keep stub`
|
723
777
|
|
724
|
-
allow_any_instance_of(Klass).to receive(:
|
725
|
-
Klass.any_instance.stub(:
|
778
|
+
allow_any_instance_of(Klass).to receive(:message)
|
779
|
+
Klass.any_instance.stub(:message) # with `--keep stub`
|
726
780
|
```
|
727
781
|
|
728
782
|
* This conversion can be disabled by: `--keep deprecated`
|
@@ -734,24 +788,24 @@ Klass.any_instance.stub(:foo) # with `--keep stub`
|
|
734
788
|
Targets:
|
735
789
|
|
736
790
|
```ruby
|
737
|
-
obj.stub(:
|
738
|
-
obj.stub!(:
|
791
|
+
obj.stub(:message)
|
792
|
+
obj.stub!(:message)
|
739
793
|
|
740
794
|
obj.stub_chain(:foo, :bar, :baz)
|
741
795
|
|
742
|
-
Klass.any_instance.stub(:
|
796
|
+
Klass.any_instance.stub(:message)
|
743
797
|
```
|
744
798
|
|
745
799
|
Will be converted to:
|
746
800
|
|
747
801
|
```ruby
|
748
|
-
allow(obj).to receive(:
|
802
|
+
allow(obj).to receive(:message)
|
749
803
|
|
750
804
|
# Conversion from `stub_chain` to `receive_message_chain` is available
|
751
805
|
# only if the target project's RSpec is 3.0.0.beta2 (not yet released) or later
|
752
806
|
allow(obj).to receive_message_chain(:foo, :bar, :baz)
|
753
807
|
|
754
|
-
allow_any_instance_of(Klass).to receive(:
|
808
|
+
allow_any_instance_of(Klass).to receive(:message)
|
755
809
|
```
|
756
810
|
|
757
811
|
There's no replacement for `unstub` in the `expect` syntax. See [this discussion](https://github.com/rspec/rspec-mocks/issues/153#issuecomment-12208638) for more details.
|
@@ -805,15 +859,15 @@ Or if you're going to stay RSpec 2.14 for now but want to convert all `stub` to
|
|
805
859
|
Targets:
|
806
860
|
|
807
861
|
```ruby
|
808
|
-
obj.stub!(:
|
809
|
-
obj.unstub!(:
|
862
|
+
obj.stub!(:message)
|
863
|
+
obj.unstub!(:message)
|
810
864
|
```
|
811
865
|
|
812
866
|
Will be converted to:
|
813
867
|
|
814
868
|
```ruby
|
815
|
-
obj.stub(:
|
816
|
-
obj.unstub(:
|
869
|
+
obj.stub(:message) # with `--keep stub`
|
870
|
+
obj.unstub(:message)
|
817
871
|
```
|
818
872
|
|
819
873
|
* This conversion can be disabled by: `--keep deprecated`
|
@@ -825,21 +879,47 @@ obj.unstub(:foo)
|
|
825
879
|
Targets:
|
826
880
|
|
827
881
|
```ruby
|
828
|
-
obj.stub(:
|
829
|
-
obj.stub(:
|
882
|
+
obj.stub(:message).any_number_of_times
|
883
|
+
obj.stub(:message).at_least(0)
|
830
884
|
```
|
831
885
|
|
832
886
|
Will be converted to:
|
833
887
|
|
834
888
|
```ruby
|
835
|
-
allow(obj).to receive(:
|
836
|
-
obj.stub(:
|
889
|
+
allow(obj).to receive(:message)
|
890
|
+
obj.stub(:message) # with `--keep stub`
|
837
891
|
```
|
838
892
|
|
839
893
|
* This conversion can be disabled by: `--keep deprecated`
|
840
894
|
* Deprecation: deprecated since RSpec 2.14, removed in RSpec 3.0
|
841
895
|
* See also: [Don't allow at_least(0) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/133)
|
842
896
|
|
897
|
+
### Useless `and_return`
|
898
|
+
|
899
|
+
Targets:
|
900
|
+
|
901
|
+
```ruby
|
902
|
+
expect(obj).to receive(:message).and_return { 1 }
|
903
|
+
allow(obj).to receive(:message).and_return { 1 }
|
904
|
+
|
905
|
+
expect(obj).to receive(:message).and_return
|
906
|
+
allow(obj).to receive(:message).and_return
|
907
|
+
```
|
908
|
+
|
909
|
+
Will be converted to:
|
910
|
+
|
911
|
+
```ruby
|
912
|
+
expect(obj).to receive(:message) { 1 }
|
913
|
+
allow(obj).to receive(:message) { 1 }
|
914
|
+
|
915
|
+
expect(obj).to receive(:message)
|
916
|
+
allow(obj).to receive(:message)
|
917
|
+
```
|
918
|
+
|
919
|
+
* This conversion can be disabled by: `--keep deprecated`
|
920
|
+
* Deprecation: deprecated since RSpec 2.99, removed in RSpec 3.0
|
921
|
+
* See also: [Consider deprecating `and_return { value }` · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/558)
|
922
|
+
|
843
923
|
### `any_instance` implementation blocks
|
844
924
|
|
845
925
|
**This conversion is available only if your project's RSpec is `>= 2.99.0.beta1` and `< 3.0.0.beta1`.**
|
@@ -937,59 +1017,6 @@ double('something')
|
|
937
1017
|
* Deprecation: deprecated since RSpec 2.14, removed in RSpec 3.0
|
938
1018
|
* See also: [myronmarston / why_double.md - Gist](https://gist.github.com/myronmarston/6576665)
|
939
1019
|
|
940
|
-
### Expectations on attribute of subject with `its`
|
941
|
-
|
942
|
-
**This conversion will be disabled automatically if `rspec-its` is loaded in your spec.**
|
943
|
-
|
944
|
-
Targets:
|
945
|
-
|
946
|
-
```ruby
|
947
|
-
describe 'example' do
|
948
|
-
subject { { foo: 1, bar: 2 } }
|
949
|
-
its(:size) { should == 2 }
|
950
|
-
its([:foo]) { should == 1 }
|
951
|
-
its('keys.first') { should == :foo }
|
952
|
-
end
|
953
|
-
```
|
954
|
-
|
955
|
-
Will be converted to:
|
956
|
-
|
957
|
-
```ruby
|
958
|
-
describe 'example' do
|
959
|
-
subject { { foo: 1, bar: 2 } }
|
960
|
-
|
961
|
-
describe '#size' do
|
962
|
-
subject { super().size }
|
963
|
-
it { should == 2 }
|
964
|
-
end
|
965
|
-
|
966
|
-
describe '[:foo]' do
|
967
|
-
subject { super()[:foo] }
|
968
|
-
it { should == 1 }
|
969
|
-
end
|
970
|
-
|
971
|
-
describe '#keys' do
|
972
|
-
subject { super().keys }
|
973
|
-
describe '#first' do
|
974
|
-
subject { super().first }
|
975
|
-
it { should == :foo }
|
976
|
-
end
|
977
|
-
end
|
978
|
-
end
|
979
|
-
```
|
980
|
-
|
981
|
-
There's an option to continue using `its` with [rspec-its](https://github.com/rspec/rspec-its) which is a gem extracted from `rspec-core`.
|
982
|
-
If you choose to do so, disable this conversion by either:
|
983
|
-
|
984
|
-
* Specify `--keep its` option manually.
|
985
|
-
* Require `rspec-its` in your spec so that Transpec automatically disables this conversion.
|
986
|
-
|
987
|
-
---
|
988
|
-
|
989
|
-
* This conversion can be disabled by: `--keep its`
|
990
|
-
* Deprecation: deprecated since RSpec 2.99, removed in RSpec 3.0
|
991
|
-
* See also: [Core: `its` will be moved into an external gem - The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#core__will_be_moved_into_an_external_gem)
|
992
|
-
|
993
1020
|
### Current example object
|
994
1021
|
|
995
1022
|
**This conversion is available only if your project's RSpec is `2.99.0.beta1` or later.**
|
data/README.md.erb
CHANGED
@@ -407,21 +407,13 @@ The one-liner (implicit receiver) `should`:
|
|
407
407
|
|
408
408
|
<%=
|
409
409
|
|
410
|
-
sections =
|
410
|
+
sections = readme.each_line.slice_before(/^## /)
|
411
411
|
|
412
|
-
|
412
|
+
supported_conversions_section = sections.find do |section|
|
413
413
|
section.first.include?('Supported Conversions')
|
414
414
|
end
|
415
415
|
|
416
|
-
|
417
|
-
next unless line.start_with?('### ')
|
418
|
-
line.sub(/^[#\s]*/, '').chomp
|
419
|
-
end.compact
|
420
|
-
|
421
|
-
titles.map do |title|
|
422
|
-
anchor = '#' + title.gsub(/[^\w_\- ]/, '').downcase.gsub(' ', '-')
|
423
|
-
"* [#{title}](#{anchor})"
|
424
|
-
end.join("\n")
|
416
|
+
table_of_contents(supported_conversions_section, 3)
|
425
417
|
|
426
418
|
%>
|
427
419
|
|
@@ -657,6 +649,43 @@ expect { do_something }.to raise_error
|
|
657
649
|
* Deprecation: deprecated since RSpec 3.0
|
658
650
|
* See also: [Unification of Block vs. Value Syntaxes - RSpec's New Expectation Syntax](http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax#unification_of_block_vs_value_syntaxes)
|
659
651
|
|
652
|
+
### Expectations on attribute of subject with `its`
|
653
|
+
|
654
|
+
**This conversion will be disabled automatically if `rspec-its` is loaded in your spec.**
|
655
|
+
|
656
|
+
Targets:
|
657
|
+
|
658
|
+
```ruby
|
659
|
+
<%=
|
660
|
+
its_target = <<END
|
661
|
+
describe 'example' do
|
662
|
+
subject { { foo: 1, bar: 2 } }
|
663
|
+
its(:size) { should == 2 }
|
664
|
+
its([:foo]) { should == 1 }
|
665
|
+
its('keys.first') { should == :foo }
|
666
|
+
end
|
667
|
+
END
|
668
|
+
-%>
|
669
|
+
```
|
670
|
+
|
671
|
+
Will be converted to:
|
672
|
+
|
673
|
+
```ruby
|
674
|
+
<%= Transpec::Converter.new.convert(its_target) -%>
|
675
|
+
```
|
676
|
+
|
677
|
+
There's an option to continue using `its` with [rspec-its](https://github.com/rspec/rspec-its) which is a gem extracted from `rspec-core`.
|
678
|
+
If you choose to do so, disable this conversion by either:
|
679
|
+
|
680
|
+
* Specify `--keep its` option manually.
|
681
|
+
* Require `rspec-its` in your spec so that Transpec automatically disables this conversion.
|
682
|
+
|
683
|
+
---
|
684
|
+
|
685
|
+
* This conversion can be disabled by: `--keep its`
|
686
|
+
* Deprecation: deprecated since RSpec 2.99, removed in RSpec 3.0
|
687
|
+
* See also: [Core: `its` will be moved into an external gem - The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#core__will_be_moved_into_an_external_gem)
|
688
|
+
|
660
689
|
### Negative error expectations with specific error
|
661
690
|
|
662
691
|
Targets:
|
@@ -684,15 +713,15 @@ lambda { do_something }.should_not raise_error # with `--keep should`
|
|
684
713
|
Targets:
|
685
714
|
|
686
715
|
```ruby
|
687
|
-
obj.should_receive(:
|
688
|
-
Klass.any_instance.should_receive(:
|
716
|
+
obj.should_receive(:message)
|
717
|
+
Klass.any_instance.should_receive(:message)
|
689
718
|
```
|
690
719
|
|
691
720
|
Will be converted to:
|
692
721
|
|
693
722
|
```ruby
|
694
|
-
expect(obj).to receive(:
|
695
|
-
expect_any_instance_of(Klass).to receive(:
|
723
|
+
expect(obj).to receive(:message)
|
724
|
+
expect_any_instance_of(Klass).to receive(:message)
|
696
725
|
```
|
697
726
|
|
698
727
|
* This conversion can be disabled by: `--keep should_receive`
|
@@ -704,21 +733,21 @@ expect_any_instance_of(Klass).to receive(:foo)
|
|
704
733
|
Targets:
|
705
734
|
|
706
735
|
```ruby
|
707
|
-
obj.should_receive(:
|
708
|
-
obj.should_receive(:
|
736
|
+
obj.should_receive(:message).any_number_of_times
|
737
|
+
obj.should_receive(:message).at_least(0)
|
709
738
|
|
710
|
-
Klass.any_instance.should_receive(:
|
711
|
-
Klass.any_instance.should_receive(:
|
739
|
+
Klass.any_instance.should_receive(:message).any_number_of_times
|
740
|
+
Klass.any_instance.should_receive(:message).at_least(0)
|
712
741
|
```
|
713
742
|
|
714
743
|
Will be converted to:
|
715
744
|
|
716
745
|
```ruby
|
717
|
-
allow(obj).to receive(:
|
718
|
-
obj.stub(:
|
746
|
+
allow(obj).to receive(:message)
|
747
|
+
obj.stub(:message) # with `--keep stub`
|
719
748
|
|
720
|
-
allow_any_instance_of(Klass).to receive(:
|
721
|
-
Klass.any_instance.stub(:
|
749
|
+
allow_any_instance_of(Klass).to receive(:message)
|
750
|
+
Klass.any_instance.stub(:message) # with `--keep stub`
|
722
751
|
```
|
723
752
|
|
724
753
|
* This conversion can be disabled by: `--keep deprecated`
|
@@ -730,24 +759,24 @@ Klass.any_instance.stub(:foo) # with `--keep stub`
|
|
730
759
|
Targets:
|
731
760
|
|
732
761
|
```ruby
|
733
|
-
obj.stub(:
|
734
|
-
obj.stub!(:
|
762
|
+
obj.stub(:message)
|
763
|
+
obj.stub!(:message)
|
735
764
|
|
736
765
|
obj.stub_chain(:foo, :bar, :baz)
|
737
766
|
|
738
|
-
Klass.any_instance.stub(:
|
767
|
+
Klass.any_instance.stub(:message)
|
739
768
|
```
|
740
769
|
|
741
770
|
Will be converted to:
|
742
771
|
|
743
772
|
```ruby
|
744
|
-
allow(obj).to receive(:
|
773
|
+
allow(obj).to receive(:message)
|
745
774
|
|
746
775
|
# Conversion from `stub_chain` to `receive_message_chain` is available
|
747
776
|
# only if the target project's RSpec is <%= Transpec::RSpecVersion.receive_message_chain_available_version %> (not yet released) or later
|
748
777
|
allow(obj).to receive_message_chain(:foo, :bar, :baz)
|
749
778
|
|
750
|
-
allow_any_instance_of(Klass).to receive(:
|
779
|
+
allow_any_instance_of(Klass).to receive(:message)
|
751
780
|
```
|
752
781
|
|
753
782
|
There's no replacement for `unstub` in the `expect` syntax. See [this discussion](https://github.com/rspec/rspec-mocks/issues/153#issuecomment-12208638) for more details.
|
@@ -801,15 +830,15 @@ Or if you're going to stay RSpec 2.14 for now but want to convert all `stub` to
|
|
801
830
|
Targets:
|
802
831
|
|
803
832
|
```ruby
|
804
|
-
obj.stub!(:
|
805
|
-
obj.unstub!(:
|
833
|
+
obj.stub!(:message)
|
834
|
+
obj.unstub!(:message)
|
806
835
|
```
|
807
836
|
|
808
837
|
Will be converted to:
|
809
838
|
|
810
839
|
```ruby
|
811
|
-
obj.stub(:
|
812
|
-
obj.unstub(:
|
840
|
+
obj.stub(:message) # with `--keep stub`
|
841
|
+
obj.unstub(:message)
|
813
842
|
```
|
814
843
|
|
815
844
|
* This conversion can be disabled by: `--keep deprecated`
|
@@ -821,21 +850,47 @@ obj.unstub(:foo)
|
|
821
850
|
Targets:
|
822
851
|
|
823
852
|
```ruby
|
824
|
-
obj.stub(:
|
825
|
-
obj.stub(:
|
853
|
+
obj.stub(:message).any_number_of_times
|
854
|
+
obj.stub(:message).at_least(0)
|
826
855
|
```
|
827
856
|
|
828
857
|
Will be converted to:
|
829
858
|
|
830
859
|
```ruby
|
831
|
-
allow(obj).to receive(:
|
832
|
-
obj.stub(:
|
860
|
+
allow(obj).to receive(:message)
|
861
|
+
obj.stub(:message) # with `--keep stub`
|
833
862
|
```
|
834
863
|
|
835
864
|
* This conversion can be disabled by: `--keep deprecated`
|
836
865
|
* Deprecation: deprecated since RSpec 2.14, removed in RSpec 3.0
|
837
866
|
* See also: [Don't allow at_least(0) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/133)
|
838
867
|
|
868
|
+
### Useless `and_return`
|
869
|
+
|
870
|
+
Targets:
|
871
|
+
|
872
|
+
```ruby
|
873
|
+
<%=
|
874
|
+
useless_and_return_target = <<END
|
875
|
+
expect(obj).to receive(:message).and_return { 1 }
|
876
|
+
allow(obj).to receive(:message).and_return { 1 }
|
877
|
+
|
878
|
+
expect(obj).to receive(:message).and_return
|
879
|
+
allow(obj).to receive(:message).and_return
|
880
|
+
END
|
881
|
+
-%>
|
882
|
+
```
|
883
|
+
|
884
|
+
Will be converted to:
|
885
|
+
|
886
|
+
```ruby
|
887
|
+
<%= Transpec::Converter.new.convert(useless_and_return_target) -%>
|
888
|
+
```
|
889
|
+
|
890
|
+
* This conversion can be disabled by: `--keep deprecated`
|
891
|
+
* Deprecation: deprecated since RSpec 2.99, removed in RSpec 3.0
|
892
|
+
* See also: [Consider deprecating `and_return { value }` · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/558)
|
893
|
+
|
839
894
|
### `any_instance` implementation blocks
|
840
895
|
|
841
896
|
**This conversion is available only if your project's RSpec is `>= <%= Transpec::RSpecVersion::ANY_INSTANCE_IMPLEMENTATION_BLOCK_MIGRATION_BEGIN %>` and `< <%= Transpec::RSpecVersion::ANY_INSTANCE_IMPLEMENTATION_BLOCK_MIGRATION_EXCLUSIVE_END %>`.**
|
@@ -919,43 +974,6 @@ double('something')
|
|
919
974
|
* Deprecation: deprecated since RSpec 2.14, removed in RSpec 3.0
|
920
975
|
* See also: [myronmarston / why_double.md - Gist](https://gist.github.com/myronmarston/6576665)
|
921
976
|
|
922
|
-
### Expectations on attribute of subject with `its`
|
923
|
-
|
924
|
-
**This conversion will be disabled automatically if `rspec-its` is loaded in your spec.**
|
925
|
-
|
926
|
-
Targets:
|
927
|
-
|
928
|
-
```ruby
|
929
|
-
<%=
|
930
|
-
its_target = <<END
|
931
|
-
describe 'example' do
|
932
|
-
subject { { foo: 1, bar: 2 } }
|
933
|
-
its(:size) { should == 2 }
|
934
|
-
its([:foo]) { should == 1 }
|
935
|
-
its('keys.first') { should == :foo }
|
936
|
-
end
|
937
|
-
END
|
938
|
-
-%>
|
939
|
-
```
|
940
|
-
|
941
|
-
Will be converted to:
|
942
|
-
|
943
|
-
```ruby
|
944
|
-
<%= Transpec::Converter.new.convert(its_target) -%>
|
945
|
-
```
|
946
|
-
|
947
|
-
There's an option to continue using `its` with [rspec-its](https://github.com/rspec/rspec-its) which is a gem extracted from `rspec-core`.
|
948
|
-
If you choose to do so, disable this conversion by either:
|
949
|
-
|
950
|
-
* Specify `--keep its` option manually.
|
951
|
-
* Require `rspec-its` in your spec so that Transpec automatically disables this conversion.
|
952
|
-
|
953
|
-
---
|
954
|
-
|
955
|
-
* This conversion can be disabled by: `--keep its`
|
956
|
-
* Deprecation: deprecated since RSpec 2.99, removed in RSpec 3.0
|
957
|
-
* See also: [Core: `its` will be moved into an external gem - The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#core__will_be_moved_into_an_external_gem)
|
958
|
-
|
959
977
|
### Current example object
|
960
978
|
|
961
979
|
**This conversion is available only if your project's RSpec is `<%= Transpec::RSpecVersion.yielded_example_available_version %>` or later.**
|